BEST RM COMMAND IN LINUX WITH EXAMPLES

BEST RM COMMAND IN LINUX WITH EXAMPLES

Introduction
In this article we are going to discuss on rm command in Linux. rm is a Linux terminal command used to delete/remove files & directories. It’s completely free application comes as in build application with Linux OS Installation. The main author of this application is Paul Rubin, Richard M. Stallman, Jim Meyering and David MacKenzie and released under GNU GPLv3 license.

Now let’s have a look at some most important rm command in Linux with examples
Delete a File
Delete a file using rm command in Linux.
elinuxbook@ubuntu:~$ rm file.txt # Delete a File

Delete a File with output
If you wish to get output after delete a file then use rm command with argument -v. Refer the command below.

elinuxbook@ubuntu:~$ rm -v file.txt # Delete a file with Output
removed ‘file.txt’

Prompt before Delete a File/Directory
rm command with argument -i will prompt you a warning message before delete a file. You will get the warning message before deleting each file if you are deleting multiple files.

elinuxbook@ubuntu:~$ rm -i file.txt # Prompt a Warning Message before delete the file
rm: remove regular empty file ‘file.txt’? y

Delete a Empty Directory
To delete a empty directory use rm command in Linux with argument -d. Refer the command below.

elinuxbook@ubuntu:~$ rm -d data/ # Delete Empty Directory

Delete a Directory with it’s Content



To delete a directory with all it’s content recursively use rm command with argument -R. Use the argument -f with the argument -R to delete the directory forcefully.

elinuxbook@ubuntu:~$ rm -Rf data/ # Delete a Directory with content

You can also use the below command to delete a directory with it’s content recursively.
elinuxbook@ubuntu:~$ rm -rf data/

Also Read :

Delete a file Forcefully
To delete a file forcefully use rm command in Linux with argument -f. Refer the command below.

elinuxbook@ubuntu:~$ rm -f file.txt # Delete a File Forcefully

Prompt before delete more then 3 files
rm command with argument -I will Prompt a warning message once before delete more the three files.
elinuxbook@ubuntu:~/data$ rm -I file* # Prompt a warning message before delete 3 files
rm: remove 5 arguments? y

Delete Multiple Files using Wildcard
Delete multiple files at once using rm command in Linux using Wildcard. Here I have five text files. So to delete all files use the below command.
elinuxbook@ubuntu:~/data$ ls
file1.txt file2.txt file3.txt file4.txt file5.txt
elinuxbook@ubuntu:~/data$ rm file* # Delete Multiple Files using Wildcard

You can also delete multiple files at once with the help of file extension using rm command in Linux. Refer the command below.

elinuxbook@ubuntu:~/data$ ls
file1.txt file2.txt file3.txt file4.txt file5.txt
elinuxbook@ubuntu:~/data$ rm *.txt

We tries to include all possible rm command in Linux with examples. If some thing missed out you can comment on comment box below.
If you found this article useful then Like us, Share this post on your preferred Social media, Subscribe our Newsletter OR if you have something to say then feel free to comment on the comment box below.

Latest articles

Related articles