Delete Files Using rm Command on Windows, Linux, and Mac

Brithny updated on Feb 19, 2024 | Home > Knowledge Center

What Is rm Command

The rm command is a basic command on Unix/Unix-like OS to remove files, directors, and symbolic links. The rm command, short for remove, is similar to the del command in Windows, which is used to remove files you no longer need.

the rm command

The rm command is generally enclosed in some wrapper in case of accidental deletion because files deleted by the rm command can't be easily restored from recycle bin or Trash.

So, after intentionally or unintentionally deleting files by the rm command, you should use data recovery software to get the deleted files back, or you can restore them from your precious backups.

The rm command Linux removes the specified file parameter from a directory. And the deletion of files by the command doesn't require permission to read or write. Instead, you must be permitted to write for the file's directory.

Delete Files Using rm Command on Linux, Windows, and Mac

Suppose you want to use the rm command to delete files on Linux, Windows, or Mac. In that case, the first thing is to make sure you have the write permission for the directory contents, so you can use the rm command to remove the entire files or select files from a list within a directory. Like this:

rm [Option]...FILE...

Here are some options to specify how the rm command will behave:

  • The -d flag empty directories and only works when the specified directory is empty.
  • The -e flag displays a message after each file is deleted.
  • The -f flag ignores non-existent files and overrides any confirmation prompts.
  • The -i flag asks for every deletion to be confirmed.
  • The -r flag removes directories. This flag is equivalent to the -R flag.
  • The -v flag prints what the rm command is doing onto the Terminal.

Suppose you want to delete a large number of files without confirmation. In that case, you can manually cancel out the "-i" argument by adding the "-f" option, as the option specified later on in the expanded command line "rm -i -f" takes precedence.

Share this article on social media to help others learn more about the rm command on Linux, Windows, and Mac.

 

🐧rm Command: Examples on Linux

Suppose the file name is "testfile1". Type the following to delete the "testfile1":

rm testfile1

To delete all the files in the target directory one by one, type the following:

rm -i tragetdir/*

And to remove a file that is not in the current directory, you should mention the path and type rm followed by the path:

rm ~/Documents/testfile3.txt

This command will remove the file named "testfile3" located in the Documents directory.

🪟rm Command: Examples on Windows

To delete a non-empty folder on Windows PC using CMD, you may probably get the error "The directory is not empty". And you could force the rmdir command to delete this non-empty folder and execute the deletion as follows:

C:\> rmdir /s /q

The /s option means deleting the folder with its sub-folders and files.

The /q option means no prompt for confirmation.

🍏rm Command: Examples on Mac

Suppose your computer runs macOS; In the Terminal window, type rm and drag the file you want to delete into the Terminal window, then press "Enter". For example, the rmdir Pictures would delete the directory "Pictures" from the directory you are currently in.

 
recover rm deleted files on Mac

How to Recover Files Deleted by RM on Mac

RM or RM - R command is used in Mac Terminal to delete files permanently, and this article will tell you effective ways to recover your deleted files. Read more >>

Can I Recovery Files Deleted by rm Command

It is typically impossible to undo the rm command after it is executed. The rm command deletes files permanently, and the deleted files will not be found in the Recycle Bin on your Windows PC or Trash on your Mac.

🧑‍🔧Recover Files Deleted by rm Command Using Data Recovery Software on Windows

However, some command line tools and data recovery software can help recover files deleted by the rm command, such as a powerful data recovery software EaseUS Data Recovery Wizard, which can recover various file types under numerous situations effectively and easily.

 Download for Win Recovery Rate 99.7%
 Download for Mac Trustpilot Rating 4.7

To easily understand the operation of the EaseUS data recovery software, you can refer to the steps below:

Step 1. Install and open the EaseUS data recovery software on your computer, and choose the partition where your deleted files are stored on.

Step 2. Click "Scan" to view all the deleted files, including files deleted by the rm command.

Step 3. Select files you want to restore, click "Preview" to view their content, and click "Recover" to get them back.

⏱️Recover Files Deleted by rm Command from Time Machine on Mac

In addition, you can recover files deleted by the rm command on Mac from the previous backups, such as the Time Machine Backup Schedule on Mac. Follow the steps below:

Step 1. Open "System Preferences" and find "Time Machine".

Step 2. Turn on the "Show Time Machine in the menu bar" option in the Time Machine window.

Step 3. Click "Enter Time Machine" on the Apple menu bar, and use the arrow buttons to locate the snapshot which contains the deleted files.

Step 4. Select the files and folders you want to undelete and click "Restore" to return them to their original locations.

⚠️Recover Files Deleted by rm Command Using CMD

Note that using the attrib command in CMD only allows you to unhide files instead of recovering deleted files. If the rm command permanently deletes your files, the CMD won't be helpful, and you need to use EaseUS Data Recovery Wizard as a CMD alternative.

Follow the steps below to unhide your files using CMD:

Step 1. Press "Windows + X" and hit on the "Command Prompt (Admin)" option in the menu.

Note: For Windows 8 and Windows 7, you should press "Windows + R" to find "Command Prompt Admin".

Step 2. Type chkdsk 'drive letter:'/f, press "Enter", and press "Y", and wait for the command lines to start again.

Step 3. Type drive letter again, hit "Enter", and type [drive letter: \ >attrib -h -r -s/s /d *.*].

Conclusion

The rm command is a basic Linux command that can remove files, directors, and symbolic links. The rm command is enclosed in default in case of accidental deletion.

Suppose the rm command deletes your files. In this case, if you want to restore the deleted files, three methods are suggested: recovering the deleted files using CMD, using data recovery software, such as EaseUS Data Recovery Wizard, and recovering from previous backups.

rm Command FAQs

Here are some questions people also ask when they search for the rm command, and you can read the questions below to learn more about the rm command:

1. How to delete files using cmd?

Follow the steps below to delete files using CMD:

Step 1. Type in del with a space after it.

Step 2. Then type the path for each file you want to delete, and remember to add spaces to separate each file name.

Step 3. Make sure you type in the right path and press the Enter key.

2. What is the rm rf command?

The rm -rf command allows removing root-owned files and directories. The rm command is a Linux command for removing files/directories. The -r option indicates recursive removal and removes non-empty directories. The -f option allows removal without confirmation.

3. How do I recover files after the rm command?

You can recover files deleted by the rm command using data recovery software like EaseUS Data Recovery Wizard, using CMD, and using your previous backups.

4. Does the rm command delete a directory?

The rm command can be used to delete a directory entirely, which means, this command deletes a directory and all files or subdirectories within this directory.

Was This Page Helpful?

 

Updated by Brithny

Brithny is a technology enthusiast, aiming to make readers' tech lives easy and enjoyable. She loves exploring new technologies and writing technical how-to tips. In her spare time, she loves sharing things about her game experience on Facebook or Twitter.

Read full bio

Totalav antivirus software