Mastering File Deletion in Linux: Command-Line and GUI Methods Explained

How-to-delete-file-in-linux

Are you new for Linux and even don’t know “how to delete file in Linux Ubuntu 20.04″? Or Do you want to learn more options to delete files? Don’t worry.

As you know the graphical environment is growing day by day, And now you can use a graphical interface to delete the file.

Trust me Command line interface is more interesting then GUI. Once you will be habitual of commands you never like press right/left click on objects through mouse of your computer.

Using the keyboard will give you an amazing experience. This is a royal experience for a Linux user.

This article is not about how to remove directory in Linux.

This article will only cover how to delete files using different methods.

Article Contents:

How to delete file in Linux

Be extra careful, When you delete a file in Linux using the rm command because you can’t recover file once deleted by rm command.

To delete a single file use the rm command followed by the file path with the name.

$rm /path/to/file

If you are removing the file from current directory use rm command followed by filename only:

$rm filename

How to delete multiple files in Linux

To delete multiple files in single time use rm command followed by the file paths and names separated by space.

$rm /Path_to_file1 /Path_to_file2 /Path_to_file3

If you want to delete multiple files from current directory use rm command followed by file names separated by space.

$rm filename1 filename2 filename3

How to delete a file with wildcards

If you want to delete all files with a specific prefix name, then you can use a wildcard (*). For example, remove all the files start with java from the current directory, use the following command

$rm java*

If you want to delete all .pdf files then syntax will be:

$rm *.pdf

It is recommended to list all files using ls command before using a wildcard, and use -i option with the rm command.

i expansion is used to prompting to ask confirmation before deleting each file. Syntax Use:

$rm -i filename

If you are facing any problem or error before deleting the file. use -f option to remove file forcefully.

-f command is so powerful, can remove write the protected file without prompt.

$rm -f filename

Delete File in Linux by using GUI

GUI is very lovely for new users, but not good for Linux experts. You can delete any file from the graphical interface as well.

Right-click on file > Move to Trash

20-delete-file-in-linux-Gui

Delete the file by GUI can be recovered because the deleted file is saved in Trash. After deleting from trash it goes out of the system.

21-go-to-trash

Conclusion:

By Now, You know lots of about deleting the file, you can use cautions to delete a file in Linux by the command-line interface. if you are using GUI no problem you can get back after deleting the file.

How do you like this article tell me in the comment box? If you have any question, you can put in the comment box.

If you want to contact me a mail at [email protected]

If you like our content, please consider buying us a coffee.
Thank you for your support!

Leave a Reply

Your email address will not be published. Required fields are marked *