• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Friday, May 9, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

What Actually “rm -rf” Command Do in Linux?

How VPS by How VPS
November 2, 2018
in Linux, Operating System
0
0
SHARES
41
VIEWS
Share on FacebookShare on Twitter

Contents

  1. How to Remove a File in Linux
  2. How to Remove Multiple Files in Linux
  3. How to Remove a Directory in Linux
  4. How to Remove Files with Confirmation Prompt
  5. How to Remove Directories with Confirmation Prompt
  6. How to Remove File or Directory Forcefully
  7. How to Show Information While Deletion
  8. Learn rm -Rf / Command
  9. Create Alias for rm Command in Linux
  10. Does rm Delete a File?

The rm command is a UNIX and Linux command line utility for removing files or directories on a Linux system. In this article, we will clearly explain what actually “rm -rf” command can do in Linux.

In addition, we will share a few useful examples of removing a file, removing a directory, removing multiple files or directories, prompting for confirmation, removing files recursively and forcing removal of files.

The rm command is also one of the frequently used commands on a Linux system, but also a dangerous command that you will discover later on in this article.

How to Remove a File in Linux

By default, the rm command only removes file or files specified on the command line immediately and it doesn’t remove directories.

$ mkdir -p tecmint_files
$ touch tecmint.txt
$ rm tecmint.txt
$ rm tecmint_files
What Actually “rm -rf” Command Do in Linux?

rm Command Example

How to Remove Multiple Files in Linux

To remove multiple files at onces, specify the file names one by one (for example: file1 file2) or use a pattern to remove multiple files (for example: pattern ending with .txt) at one go.

$ rm tecmint.txt fossmint.txt  [Using Filenames]
$ rm *.txt                     [Using Pattern] 
What Actually “rm -rf” Command Do in Linux?

Remove Multiple Files in Linux

How to Remove a Directory in Linux

To remove a directory, you can use the -r or -R switch, which tells rm to delete a directory recursively including its content (sub-directories and files).

$ rm tecmint_files/
$ rm -R tecmint_files/
What Actually “rm -rf” Command Do in Linux?

Remove Directory in Linux

How to Remove Files with Confirmation Prompt

To prompt for confirmation while deleting a file, use the -i option as shown.

$ rm -i tecmint.txt
What Actually “rm -rf” Command Do in Linux?

Remove Files with Confirmation

How to Remove Directories with Confirmation Prompt

To prompt for confirmation while deleting a directory and its sub-directories, use the -R and -i option as shown.

$ rm -Ri tecmint_files/ 
What Actually “rm -rf” Command Do in Linux?

Remove Directory with Confirmation

How to Remove File or Directory Forcefully

To remove file or directory forcefully, you can use the option -f force a deletion operation without rm prompting you for confirmation. For example if a file is unwritable, rm will prompt you whether to remove that file or not, to avoid this and simply execute the operation.

$ rm -f tecmint.txt

When you combine the -r and -f flags, it means that recursively and forcibly remove a directory (and its contents) without prompting for confirmation.

$ rm -rf fossmint_files
What Actually “rm -rf” Command Do in Linux?

Force Deletion of File and Directory

How to Show Information While Deletion

To show more information when deleting a file or directory, use the -v option, this will enable rm command to show what is being done on the standard output.

$ rm -rv fossmint_files
What Actually “rm -rf” Command Do in Linux?

Show Information of Deletion

Learn rm -Rf / Command

You should always keep in mind that “rm -rf” is one of the most dangerous commands, that you can never run on a Linux system, especially as root. The following command will clear everything on your root(/) partition.

# rm -rf  /

Create Alias for rm Command in Linux

As a safety measure, you can make rm to always prompt you to confirm a deletion operation, every time you want to delete a file or directory, using the -i option. To configure this permanently, add an alias in your $HOME/.bashrc file.

alias rm="rm -i"

Save the changes and exit the file. Then source your .bashrc file as shown or open a new terminal for the changes to take effect.

$ source $HOME/.bashrc 

This simply implies that when ever you execute rm, it will be invoked with the -i option by default (but using the -f flag will override this setting).

$ rm fossmint.txt
$ rm tecmint.txt
What Actually “rm -rf” Command Do in Linux?

Alias rm Command Confirmation

Does rm Delete a File?

Actually, the rm command never delete a file, instead it unlinks from the disk, but the data is still on th disk and can be recovered using tools such as PhotoRec, Scalpel or Foremost.

If you really want to permanently delete file or directory, you can use shred command-line tool to overwrite a file to hide its contents.

That’s it! In this article, we have explained some really useful rm command examples and also elaborated on what the “rm -rf” command can do in Linux. If you have any questions, or additions to share, use the comment form below to reach us.

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
Previous Post

How to Rename File While Downloading with Wget in Linux

Next Post

How to Remove Packages with Dependencies Using Yum

Next Post

How to Remove Packages with Dependencies Using Yum

Leave a Reply Cancel reply

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

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet