The three ways to delete files in Linux

You delete files in Linux using the rm command in the terminal, the file manager's delete button, or by moving them to a trash folder first. The method you choose depends on whether you want the file gone when ready, recoverable for a while, or whether you are comfortable typing commands.

The safest approach for most people is the file manager — the graphical folder window you use to browse your computer. When you delete a file there, it goes to a trash or recycle bin folder, where you can recover it if you change your mind. The rm command in the terminal deletes files permanently and when ready, with no recovery option, so it requires more care.

Which method makes sense depends on what you are deleting and how confident you are that you will not need it again. A file you created yesterday and know you do not want is a good candidate for permanent deletion. A file you are unsure about should go to trash first.

Key Takeaways

  • The file manager (Files, Nautilus, or Dolphin depending on your Linux version) lets you delete files by right-clicking and choosing delete or move to trash, with recovery possible.
  • The rm command in the terminal deletes files permanently with no recovery, so type carefully and double-check the filename before you press Enter.
  • rm -r deletes a folder and everything inside it, which is powerful and dangerous if you mistype the folder name.
  • Most Linux systems keep a trash folder at ~/.local/share/Trash/files where deleted files sit until you empty the trash.
  • If you delete a file by accident using rm, recovery is possible but difficult and requires tools like testdisk or photorec, so prevention is better than recovery.

Deleting files with your file manager

Open your file manager — this is usually called Files, Nautilus, Dolphin, or Thunar depending on which Linux desktop you use. Navigate to the file you want to delete, right-click on it, and choose Delete or Move to Trash from the menu that appears.

The file moves to your trash folder, where it stays until you empty the trash. To recover it, open your trash folder (usually accessible from the sidebar of your file manager), right-click the file, and choose Restore or Move Out of Trash. Once you empty the trash, the files are gone, though recovery tools may still be able to retrieve them.

This is the method to use if you are not sure whether you need the file later, or if you are new to Linux and want a safety net. It works the same way as deleting files on Windows or Mac.

Deleting files with the rm command

Open a terminal window and navigate to the folder containing the file you want to delete. Type rm filename and press Enter, replacing "filename" with the actual name of the file. The file is deleted when ready and permanently — it does not go to trash.

Before you press Enter, read the filename back to yourself out loud. A single typo can delete the wrong file. If you are deleting a file you created yourself and you are certain you do not need it, this is safe. If you are deleting a file you are unsure about, use the file manager instead.

The rm command is faster than the file manager if you are deleting many files at once or if you are working on a remote server where a graphical file manager is not available. It is also the method you will see in instructions online, so learning it is useful even if you normally use the file manager.

Deleting folders and everything inside them

To delete a folder and all the files inside it, use rm -r foldername, where "foldername" is the name of the folder. The -r flag tells rm to delete recursively, meaning it deletes the folder and everything in it, including subfolders.

This is powerful and dangerous. If you mistype the folder name, you can delete the wrong folder and lose a lot of files at once. Always type the folder name carefully and double-check it before you press Enter. If you are not confident, use the file manager instead — right-click the folder and choose Delete, and it goes to trash where you can recover it.

A common mistake is typing rm -r / or rm -r ~ by accident, which would delete your entire home folder or your entire system. This is why many experienced Linux users recommend using rm -ri instead, which asks you to confirm each deletion before it happens. The i stands for "interactive".

Permanently deleting files so they cannot be recovered

When you delete a file with rm or the file manager, the file is gone from your view, but the data is still on your hard drive until something else writes over that space. If you need to delete a file so thoroughly that recovery tools cannot retrieve it, use the shred command instead.

Type shred -vfz filename and press Enter. This overwrites the file multiple times with random data before deleting it, making recovery much harder. The -v flag shows you what is happening, the -f flag forces deletion even if the file is read-only, and the -z flag overwrites with zeros at the end.

You only need shred if you are deleting sensitive information like passwords, financial documents, or medical records. For everyday files, rm is sufficient. Shred is slower than rm because it writes to the disk multiple times, so use it only when you have a real reason to.

Finding and deleting files by name or type

If you need to delete many files at once and you know something about them — their name, when they were created, or what type they are — use the find command to locate them first, then delete them.

For example, to find all files ending in .tmp in your home folder and delete them, type find ~ -name "*.tmp" -delete. To find all files larger than 100 megabytes and delete them, type find ~ -size +100M -delete. To find all files not accessed in the last 30 days and delete them, type find ~ -atime +30 -delete.

The find command is powerful and straightforward to get wrong. If you are new to this, run the find command without the -delete flag first to see what files it finds. Once you are sure it found the right files, run it again with -delete at the end. This prevents you from accidentally deleting the wrong files.

What happens to deleted files and how to recover them

When you delete a file with the file manager, it moves to a trash folder on your computer, usually at ~/.local/share/Trash/files. You can browse this folder in your file manager and restore files from it. Once you empty the trash, the files are marked as deleted but the data is still on your hard drive.

If you delete a file with rm, it is marked as deleted when ready and the space is available for other files to use. Until something writes over that space, recovery tools like testdisk or photorec can sometimes retrieve the file. Once the space is overwritten, recovery is not possible.

The longer you wait after deleting a file, the more likely it is that something else has written over the space. If you delete a file by accident, stop using your computer and shut it down. The less you use the computer, the less chance that the deleted data will be overwritten. Then use a recovery tool to try to get the file back.

Frequently Asked Questions

Can I undo a deletion if I used rm?

Not directly — rm does not have an undo button. If you deleted a file by accident with rm, shut down your computer when ready and use a recovery tool like testdisk or photorec to try to retrieve it. The sooner you do this, the better your chances. If you have already used your computer for a while after the deletion, recovery becomes much harder.

What is the difference between rm and rm -f?

rm -f forces deletion even if the file is read-only or protected. Without the -f flag, rm will ask you to confirm if the file is read-only. For everyday use, rm without -f is safer because it makes you confirm before deleting protected files.

How do I delete a file with a space in its name?

Put the filename in quotes: rm "my file.txt". Without quotes, the terminal treats the space as a separator and tries to delete two files called "my" and "file.txt". Quotes tell the terminal to treat the whole thing as one filename.

Is it safe to delete files from the Downloads folder?

Yes, if you have already installed or used what you downloaded. The Downloads folder is meant to be temporary storage. If you downloaded an installer and already installed the program, you can delete the installer. If you downloaded a document and already saved it somewhere else, you can delete the original read.

What does rm -rf do and why is it dangerous?

rm -rf deletes a folder and everything inside it without asking for confirmation. The -r means recursive (delete the folder and all subfolders), and the -f means force (do not ask before deleting). If you mistype the folder name, you can delete the wrong folder and lose a lot of files. Always use rm -ri instead, which asks you to confirm each deletion.