How to Delete Files and Directories in Linux (rm command)

Learn how to quickly and safely remove files and directories from your Linux system. Discover the many commands at your disposal and how to use them appropriately. Begin learning how to delete on Linux right now.

Table for Delete files and directories in Linux

Command and OptionDescription
rm -dUse the rm command to delete an empty directory.
rm -rRemove the contents of a non-empty directory.
rm -fIgnore any prompt when deleting a write-protected file.
rm -rfWhen removing a non-empty write-protected folder, ignore any prompts.
rm -iOutput a prompt before deleting every file.
rm -IOutput a prompt only once before deleting more than three files.
rm *Multiple characters are denoted by the wildcard.
rm ?Wildcard that represents a single character.
rmdir -pRemove the parent directory and any empty subdirectories.
rmdir -vThe deletion of the given directory will be printed.
rm command table for linux

Deleting Files

rm filename_or_path

Removing Folder in Linux (rmdir)

  • Use the rmdir or rm -d command to remove empty directories.
  • Use the rm -r command to remove non-empty directories.
rmdir folder_name

Note: If the directory still contains files or subdirectories, the rmdir command does not remove the directory.

rm -d directory_name

rm /path/to/dir/directory_name

rm /path/to/directory/*

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r.

rm -r folder_name

Use rm with the -r (recursive) and -f arguments to delete non-empty folders and all files without prompting:

rm -rf folder_name

How to Delete Files in Linux

  • unlink
  • rm

The unlink command can only delete a single file, whereas rm may remove many files at once.

unlink filename
rm filename

Delete multiple files at once

rm filename_1 filename_2 filename_3 filename_4
rm *.png


You should now be able to securely remove files and directories from the command line, having a thorough grasp of how to use the Linux rm, rmdir, and unlink functions.

58 / 100

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *