How VPS - How to use/setup VPS
  • 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
35
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
How VPS

How VPS

Related Posts

Failed to download metadata for repo 'appstream' on Centos 8
CentOS

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

February 25, 2022
How to Install Apache Tomcat 8 on CentOS 7
Linux

How to Install Apache Tomcat 8 on CentOS 7?

February 11, 2020
Install Arch Linux With Btrfs Snapshotting
Uncategorized

Install Arch Linux With Btrfs Snapshotting

February 13, 2020
Next Post

How to Remove Packages with Dependencies Using Yum

27 ‘DNF’ (Fork of Yum) Commands for RPM Package Management in Linux

Securely Accessing Your VPS

Securely Accessing Your VPS

Leave a Reply Cancel reply

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

Follow Us

  • 121 Followers
  • 87.2k Followers

Recommended

WebHostingHub Review

4 years ago

How to Install and Configure TaskBoard on Ubuntu 16.04

3 years ago

InternetVikings Review

4 years ago
Backing Up Your Data

Backing Up Your Data

4 years ago

Instagram

    Please install/update and activate JNews Instagram plugin.

Categories

  • 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

Topics

Apache Web Server Bluehost Review 2019 Bluehost Review 2020 Bluehost Review 2021 Centmin Mod CentminMod centos install htop fsck htop install HTTP DoS attack Install Snort on an Ubuntu install Zabbix on CentOS install Zabbix on CentOS 7 Linux Commands linux guide linux install htop linux vps setup guide MariaDB MariaDB Error Mysql mysqld error optimize MariaDB optimize Mysql snort Ubuntu
No Result
View All Result

Highlights

Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

Webmin Reviews

Virtualmin Reviews

CentOS Web Panel Reviews

Ajenti Reviews

ISPConfig Reviews

Trending

Failed to download metadata for repo 'appstream' on Centos 8
CentOS

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

by How VPS
February 25, 2022
0

I tried to update some extensions by use yum on centOs which I specified in Dockerfile. After...

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
Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

February 17, 2020
Webmin Reviews

Webmin Reviews

February 17, 2020
How VPS – How to use/setup VPS

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc. Visit our landing page to see all features & demos.
LEARN MORE »

Recent News

  • 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”? November 17, 2020
  • How to optimize Mysql or MariaDB November 3, 2020

Categories

  • 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

[mc4wp_form]

© 2018 JNews - City News Magazine WordPress theme. All rights belong to their respective owners.
JNews is a top selling 2018 WordPress News, Blog, Newspaper & Magazine Theme.

No Result
View All Result
  • Home

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