How to Remove Files Using Linux Commands
If you are new to Linux, you must know Linux commands. We can do everything in Linux using the command line including the deletion of files or folder. In this tutorial, I will show you to remove files in Linux using the command line.
How to Remove Files
In Linux, we use either the
Here is the syntax
$ unlink filename
$ rm filename
While using these commands, be careful. It is because it will not ask for your confirmation when deleting files. Files once deleted using
rm command are gone. So, be careful.
If you try to remove a file that is write-protected, it will ask you to confirm. In such cases, type Y and hit Enter to confirm the deletion. Otherwise, it will delete the file with our prompting.
If you are using unlink command you can only remove one file at a time, but the rm command lets you remove multiple files at the same time.
To delete multiple files using the
rm command, here is the syntax you need to follow.
$ rm filename1 filename2 filename3
rm command also supports wildcard (*) and regular expansions. So, you can use these to delete multiple files. For example, if you want to remove all .jpg images in the current directory, use the following command.
$ rm *.jpg
If you want the system to confirm each file before deleting, use
$ rm -i filename(s)
If you do not want the prompt and force delete all files including write-protected. Use
-f option to the
$ rm -f filename(s)
If you want to see the report of each file removed, use
$ rm -v filename(s)
You can also combine these options. Like if you want the system to prompt before each deletion and show the details. Combine
$ rm -iv filename(s)
Now you know how to use
rm command to delete files one by one of in bulk. I have also listed options you can use with
rm commands. So, you can now start using the