Best Linux RM Command With Examples

In this article, we are going to learn ‘Best Linux RM Command With Examples’. rm is a Linux terminal command used to delete/remove files and directories. This is a completely free application in build application with Linux OS installation. Paul Rubin, Richard M. Stallman, Jim Meyering, and David McKenzie are the main authors of this application and have been published under the GNU GPLv3 license.

Features of rm Command:

  • Removes each specified File.
  • Removes empty Directories.
  • Removes Directories and their contents recursively.
  • Prompt before every Removal.
  • Removes each specified File/Directory Forcefully. In this case, the command will never prompt before removal.
  • Displays Verbose output.

You must follow the syntax given below to use the rm command.

rm [OPTION]... [FILE]...
Best Linux RM Command With Examples

Best Linux RM Command With Examples

Follow the below Article For Best Linux RM Command With Examples :

Delete a File:

Delete a file using the rm command in Linux.

itsmarttricks@mangesh:~$ rm file.txt

Delete a File with output:

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

itsmarttricks@mangesh:~$ rm -v file.txt
removed 'file.txt'

Prompt before Delete a File/Directory:

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

itsmarttricks@mangesh:~$ rm -i file.txt
rm: remove regular empty file 'file.txt'? y

Also Read– Useful RPM Command With Examples In Linux

Delete an Empty Directory:

To delete an empty directory use the rm command in Linux with the argument -d. Refer to the command below.

itsmarttricks@mangesh:~$ rm -d data/

Delete a Directory with its Content:

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

itsmarttricks@mangesh:~$ rm -Rf data/

You can also use the below command to delete a directory with its content recursively.

itsmarttricks@mangesh:~$ rm -rf data/

Delete a file Forcefully:

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

itsmarttricks@mangesh:~$ rm -f file.txt

Prompt before delete more than 3 files:

rm command with argument -I will Prompt a warning message once before delete more the three files.

itsmarttricks@mangesh:~/data$ rm -I file*   
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.

itsmarttricks@mangesh:~/data$ ls
file1.txt  file2.txt  file3.txt  file4.txt  file5.txt
itsmarttricks@mangesh:~/data$ rm file*

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

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

Also Read – A Guide to Kill, Pkill and Killall Commands to Stop the Process in Linux(Kill Process Linux)

That’s all, In this article, we have explained the Best Linux RM Command With Examples. I hope you enjoy this article. If you like this article, then just share it. If you have any questions about this article, please comment.

Share this:

Mangesh Dhulap

This is Mangesh Dhulap the Founder and Editor of IT SMART TRICKS have 6+ years of Industrial Experience. We expect from our visitors to like, share, and comment on our posts.

You may also like...

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.