How To Delete Files And Folders Using Linux

Use the 'rm' command or your desktop environment's graphical tools

With Linux, use either your desktop environment's graphical tools or the rm command from a shell prompt to delete files and folders. The benefit of the GUI relates to ease-of-use, but each DE's file manager functions slightly differently. The rm command functions similarly across all distributions, but it works from the shell prompt.

Deleting Files and Folders Graphically

Delete file in ubuntu

Although each desktop environment uses slightly different metaphors for file access, in general, you're generally free to delete files and folders by either:

  • Clicking the object then pressing Del.
  • Right-clicking the object then selecting the Delete or Move to Trash option, or its equivalent.

In the GUI, by default, deleted files and folders move to the Trash folder, from which they may later be recovered if you deleted them accidentally.

Removing Files from the Shell

rm command in linux

The rm command works from the shell prompt; its usage is the same regardless of your distribution or your desktop environment.

By default, the command looks like this:

rm file-to-delete

Command Options for 'rm'

The rm command accepts several options that influence how it executes:

  • -f: Ignores (force) non-existent files and arguments without prompting for confirmation.
  • -i: Prompt before each object deletes.
  • -r: Remove directories and their contents recursively.
  • -d: Remove empty directories.
  • -v: Display progress with verbose notifications.
  • --help: Displays a summary of the command's syntax and usage.

Tips

The rm command's delete capability does allow for file recovery with sufficient time and skill. To remove files permanently, use the shred utility.

From the shell prompt, rm supports wildcard patterns. Thus, to delete all files with a PDF extension, type:

rm *.pdf

In addition, rm unlinks hard and soft links.