Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

BEST RM COMMAND IN LINUX WITH EXAMPLES

BEST RM Command IN LINUX WITH EXAMPLES

Introduction

I

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 :

  • BEST LINUX CHMOD COMMAND WITH EXAMPLES
  • BEST UNAME LINUX COMMANDS WITH EXAMPLES – EASY WAY TO CHECK LINUX VERSION
  • MOST USEFUL LINUX FREE COMMAND WITH EXAMPLES – A MEMORY USAGE MONITOR TOOL

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.

The post BEST RM COMMAND IN LINUX WITH EXAMPLES appeared first on Elinuxbook: Linux Tutorials, Guides, Howtos, Tips and Tricks.



This post first appeared on Elinuxbook: Linux Tutorials, Guides, Howtos, Tips And Tricks, please read the originial post: here

Share the post

BEST RM COMMAND IN LINUX WITH EXAMPLES

×

Subscribe to Elinuxbook: Linux Tutorials, Guides, Howtos, Tips And Tricks

Get updates delivered right to your inbox!

Thank you for your subscription

×