Ubuntu

How to Delete a File in Ubuntu

How_to_Delete_a_File_in_Ubuntu

From time to time, our system accumulates plenty of unnecessary files that we do not need. These files consume a lot of space in your system. To free up the storage space, you must find and delete those unnecessary files from your system.

In today’s post, we will explain how to delete a file in Ubuntu. The method explained here can be followed in any Linux distribution.

Delete File in Ubuntu

In Ubuntu, you can delete a file either through the command line using the rm command or through the File Manager. However, note that the rm command does not move the deleted files to Trash. Instead, it permanently deletes the files. If you have mistakenly deleted the file, you can only recover it from the backup. On the other hand, if you delete a file through File Manager, it will first go to Trash. From the Trash, you can decide to either restore the file or remove it permanently.

Delete a Single File

To delete a file in Ubuntu, use the below syntax:

$ rm <filename>

If a file is not present in the current Terminal directory, provide the location of the file. For instance, to delete a file test.txt located in the Documents directory, we can use the below command:

$ rm ~/Documents/test.txt

Delete Multiple Files

To delete multiple files, use the below syntax:

$ rm <filename1> <filename2> <filename3>

For instance, to delete three text files file1.txt file2.txt, and file3.txt placed in our current Terminal directory, the command would be:

$ rm file1.txt file2.txt file3.txt

You can also delete multiple files using the wildcard character (*). For instance, to delete all the files ending with the .tar extension, the command would be:

$ rm *.tar

This command will remove all the archive files ending with the .tar extension.

Prompt before deleting a file

The rm command with the -i option prompts for approval before deleting a file.

$ rm -i <filename>

When it prompts for approval, hit y to delete the file.

Delete write-protected file

The rm command by default prompts for confirmation before deleting a write-protected file.

$ rm <filename>

If you want to forcefully delete the file without prompting, use the rm command with the -f option.

$ rm -f <filename>

This command will not ask for your approval before deleting the write-protected file.

Delete file graphically

Those who do not like the command line can use a graphical method for deleting a file. To delete a file graphically, launch the file manager. Right-click the file and select Move to Trash.

Another way to delete a file is to first select it and then hit the Delete key.

To delete multiple files simultaneously, select all of them and follow the above procedure.

By doing so, the file will be deleted from your system. As explained earlier, this method does not permanently delete the file. If you later want your file back, you can get it back from Trash. To delete the file from your system permanently, remove it from the Trash too.

In this post, we covered how to delete a file in Ubuntu using the command line and graphical methods. Using either of the methods described here, you can easily delete unwanted files from your system and free up storage space.

Similar Posts