If you are a new Ubuntu user and don’t know how to delete a file or multiple files in Ubuntu using the command line or through the GUI, we will cover in this article all the details on how to delete or delete a file in Ubuntu. It is important to note that you need certain write permissions to delete a file on Ubuntu Linux system.
Delete or Delete Files in Ubuntu
Using the following two different methods, you can
delete or delete a file on Ubuntu Linux system: Delete or delete a file
- in Ubuntu using Terminal Delete
- using the graphical user interface
Important Note : You need to be very careful before deleting a file from your Ubuntu system. Once the file is deleted from the system, it would be difficult to recover its contents.
Method 1: Delete or delete a file in Ubuntu using
With this method, you can delete a file using the ‘Terminal’ command line application. Two Linux commands are available to delete or delete a file in the Ubuntu distribution. First there is the ‘Unlink’ command, but you can only delete a file with this command.
The other most popular is the ‘rm’ command used shortly to ‘delete’, which is used to delete a file on the Ubuntu Linux system. Using the ‘rm’ command, you can delete multiple files at once from your Ubuntu system.
How to use
unlink command to delete a file? To delete or delete a file using the unlink command
, type the unlink command followed by the name of the file you want to delete. The syntax of the unlink command is mentioned below:
For example, we want to delete a text file with the name ‘demo.txt’ from the Ubuntu system. Using the ‘unlink’ command above, you can easily delete this file from your system as follows:
Delete or delete
a file using
the rm command
Using the rm command, you can delete one or multiple files on the Ubuntu system. To delete a file using the ‘rm’ command, use the following syntax:
For example, we want to delete a text file from the ‘Downloads’ system. To perform this task, use the rm command followed by the file path as follows:
If you delete a write-protected file from the Ubuntu system, the message will appear on the terminal screen for confirmation, enter ‘y’ and then press the ‘Enter’ key. Otherwise, the file will be deleted from your system without displaying any confirmation message.
multiple files using rm command
You can also delete multiple files from Ubuntu system using ‘rm’ command. To remove multiple files, you must have certain write permissions on the files. To delete or delete multiple files from your system, use the ‘rm’ command and specify the file names that will be separated by a space as follows:
Delete multiple similar files with
the wildcard (*)
You can also delete the multimatch file in the current directory using the normal or wildcard(*) expansions.
For example, to delete all ‘.txt’ files from the current working directory. Run the rm command using the wildcard with the extension .txt as follows
with the rm command
The following options can be used in conjunction with the
How to use
rm command options?
We discuss some examples here related to
the ‘rm’ command options, given below:
the ‘rm’ command followed by the ‘-i’ option that each time confirms before deleting a file:
If you delete a file without displaying a user confirmation message, even if the files are write-protected, use the ‘rm’ command followed by the ‘-f’ option.
You can also combine the rm command options to delete a file. For example, to delete all matching files from the current directory without prompting for a verbose. Use the ‘rm’ command and also mention
the ‘-fv’ option as follows:
Important Note: Never run the ‘sudo rm -R/’ or ‘sudo rm -r/’ commands as root or normal user on your system. These commands are harmful to data because these commands delete or delete all files in the root directory and will also delete all mounted volumes. Don’t even try to run the command ‘sudo rm -rf /*’ on your system. It makes mistakes with your system.
Method 2: Delete
a file by using the
GUI To delete a file using the GUI, you must have write permissions on the file and you must log in as root user on your Ubuntu system. By following a few simple steps, you can easily delete a file or multiple files
from the Ubuntu system:
Go to the Ubuntu file system and right-click on a file that you want to remove from your system
. To delete the selected file, choose ‘move to trash’ from the
drop-down list that is displayed
To permanently delete from the ‘Trash’ folder, right-click on the Trash and then choose the ’empty trash’.
We learned how to delete files on Ubuntu Linux system. In addition, we have also seen some files that we cannot delete using GUI, but these types of files can be deleted through the command line by executing commands as root user.