• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Linux “rm” Command Examples

by admin

Unix includes two commands that you can use to delete files and directories: rm (remove) and rmdir (remove directory). You can also use “rm” command to remove a directory as well. In this post, 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.

Delete a File

Delete a file using rm command in Linux.

$ 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.

$ 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.

$ 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.

$ 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.

$ rm -Rf data/   # Delete a Directory with content

You can also use the below command to delete a directory with it’s content recursively.

$ rm -rf data/

Delete a file Forcefully

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

$ rm -f file.txt   # Delete a File Forcefully

Prompt before deleting more then 3 files

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

$ rm -I file*   # Prompt a warning message before deleting more than 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.

$ ls
file1.txt  file2.txt  file3.txt  file4.txt  file5.txt
$ 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.

$ ls
file1.txt  file2.txt  file3.txt  file4.txt  file5.txt
$ rm *.txt

Filed Under: Linux

Some more articles you might also be interested in …

  1. ascii: command not found
  2. pulseaudio: command not found
  3. alias: command not found
  4. How To Create a Local Yum Repository for MySQL Enterprise Packages
  5. iw Command Examples in Linux
  6. Kernel Logs Warning Messages “kernel: Possible SYN flooding on port X. Sending cookies” is logged”
  7. debugfs: command not found
  8. How to Start NTP Service With Slewing Enabled in Linux
  9. Linux OS Service ‘ntpd’
  10. How to Install NTP Service and Client in CentOS/RHEL 8

You May Also Like

Primary Sidebar

Recent Posts

  • raw: command not found
  • raw Command Examples in Linux
  • rankmirrors Command Examples in Linux
  • radeontop: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright