fbpx rm Command in Linux: Remove Files and Folders (rm -rf, -i) | Certificação Linux

rm Command in Linux: Safely Remove Files and Directories

📅 01/01/2019 ⏱ 2 min ✍️ Uira Ribeiro
Linuxcommands
rm Command in Linux: Safely Remove Files and Directories
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

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

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp