rm Command in Linux: Safely Remove Files and Directories
Linuxcommands
The rm command in Linux is used to remove files or directories.
You need write permission in the directory where the file is located to remove it. Using the -R and -f options, the rm command removes directories.
In some distributions, the "rm -i" command is used as an alias for the rm command, always prompting for confirmation before removing.
The options are:
- -f Forces removal of files without prompting the user.
- -r, -R Removes a directory and all of its contents.
- -i Prompts before removing
- -d, --dir Removes empty directories
Examples:
Removes file1:
$ rm arquivo1
Removes the documentos directory and all of its contents:
$ rm –Rf documentos
![]() | Even if a file is deleted by the rm command, it can be recovered with some advanced techniques and time, since rm deletes the file metadata in the file system table, so the inodes may still exist on the disk, allowing recovery. To delete files in a virtually unrecoverable way, the shred command should be used. |
Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.
Did you like it? Share
That was just one piece. The course teaches the whole path — from your first command to exam day.
