Ubuntu

How to remove files on Ubuntu

Ubuntu is a Linux Operating System in which we can store different types of files. To free up storage in the system we need to delete or remove some unwanted or corrupted files. In Ubuntu we can remove unnecessary files from the system through “rm” or unlink commands using the command line interface.

There are two types of files; Program files and Data files. Program files contain software instructions which can be executable, Data files contain simple information. Files can be distinguished by file extensions like pdf files will have “.pdf” and text files “.txt” extensions. We can save, move, update or delete files in the system.

In this Article we will discuss how to remove/delete unnecessary files or files from the system to free up storage using Ubuntu Linux commands. Follow the steps to successfully remove the file from the system.

Removing files on Ubuntu using rm command

The rm command is used to delete files from the system at a time.

Syntax:

$ rm [options] filename/filenames

Removing a file using rm command: Run the below mentioned command to remove “linux.txt” file from current directory:

$ rm linux.txt

The “ls” command is used to list all files of current directory to check whether the file to be removed exist or not:

Now run the below mentioned command to check that whether file is removed by displaying all files of current directory:

$ ls

Now from the above image we can see “linux.txt” no longer exists in the current directory.

Removing multiple files at a time: Run the below mentioned command to delete “linux1.txt” and “linux2.txt” from current directory:

$ rm linux1.txt linux2.txt

Change filenames ”linux1.txt, linux2.txt” according to your requirement. The “ls” command is used to list all files of current directory to check whether the files to be removed exist or not

Now run the below mentioned command to check that whether file is removed or not by displaying all files of current directory:

$ ls

We can see “linux1.txt, linux2.txt” no longer exist in the current directory.

Removing all files of same type : To remove all similar type use a wildcard (*) and standard expansions. Run the below mentioned command to remove all “.txt” files from current directory:

$ rm *.txt

The “ls” command is used to list all files of the current directory to check whether the files to be removed exist or not.

Now run the below mentioned command to check that whether file is removed by displaying all files of current directory:

$ ls

No more .txt files left in the directory as shown above.

Removing files with confirmation: Before removing a file, use the rm command with the -i option to confirm it, run the below mentioned command to delete “linuxhint.txt” from desktop directory after confirming deletion:

$ rm –i /home/alishba/Desktop/linuxhint.txt

Provide the path of the file to remove the file which is not in the current directory. The “ls” command is used to list all files of the desktop directory to check whether the files to be removed exist or not. You have to enter “yes” to confirm deletion of the file.

Now run the below mentioned command to check that whether file is removed by displaying all files of current directory:

$ ls

Removing files on Ubuntu using unlink command

The unlink command is also used to delete one file at a time.

Removing file from current directory : Run the below mentioned command to remove “linux.txt” file from current directory:

$ unlink linux.txt

The “ls” command is used to list all files of the desktop directory to check whether the files to be removed exist or not.

Now run the below mentioned command to check that whether file is removed by displaying all files of current directory:

$ ls

Removing files on Ubuntu through GUI

If you are beginner and don’t know to use Command Line properly then you can also delete files using GUI method as shown below:

Step 1: Open File location
First open the directory or folder in which your file (which you want to delete) is present, as my file is in “Documents” folder so I will open “Documents” folder:

Step 2: Delete the file
Now to delete the specific file, right click on that file and a drop down list will appear, choose “Move to trash” option from list and your file will be deleted, I am deleting “intro-linux.pdf” file from my Documents folder:

And file will no longer present in folder as shown below:

Conclusion

Computer files are digital storage mediums in systems just like the paper files and folders. There are several types of files with different extensions like .txt, .pdf, .doc and many others. You can save, delete, modify, copy and move files through Linux commands. In this article we explained how to delete files from the Ubuntu (Linux OS) using the rm and unlink command. To get extra storage space on your system read the article thoroughly to remove unnecessary files successfully by any of the above discussed commands.

About the author

Alishba Iftikhar

I am currently an undergraduate student in my 1st year. I am an internee author with Linuxhint and loved learning the art of technical content writing from senior authors. I am looking forward to opting my career as a full time Linux writer after I graduate.