How to use SSH rm command

The SSH rm (remove) command lets you delete files and directories from your Linux hosting via SSH. In particular, it’s useful for cleaning up old backups, removing unused plugins or themes, or clearing temporary files. Furthermore, you can delete single files, entire directories, or everything in a folder – but use it carefully, as deletions are permanent and cannot be undone.

Deleting a single file

To remove one file, use rm followed by the filename:

rm filename.txt

Without options, rm may ask for confirmation before deleting. If the file doesn’t exist, you’ll get an error.

Deleting directories recursively

To delete a directory and everything inside it, use the -r (recursive) flag. The -f (force) flag skips confirmation prompts, which is helpful when removing folders with many files:

rm -rf /path/to/folder/

For example, to remove an unused WordPress plugin directory:

rm -rf ~/public_html/wp-content/plugins/old-plugin-name/

Deleting all files in the current directory

To remove all files and subdirectories in your current directory:

rm -rf *

This deletes everything in the current folder. Use with extreme caution—double-check your location with pwd before running it.

Safety tips

The rm command does not move files to a trash bin. Deleted files are gone permanently. Before using rm -rf:

  • Verify the path: Use pwd to confirm your current directory and ls to list contents
  • Create a backup: For important data, create a backup first
  • Test with a single file: Try deleting one file before removing entire directories
  • Avoid wildcards in root: Never run rm -rf /* or rm -rf / – this can destroy your system

Common use cases

Typical scenarios for SSH rm command on a web hosting account:

  • Removing an unused WordPress plugin or theme folder
  • Deleting old backup files or logs
  • Cleaning up temporary or cache files
  • Removing a subdirectory you no longer need

For moving or renaming files instead of deleting them, see our guide on the SSH mv command.

Need more help?

Explore more SSH and hosting guides in our knowledgebase. JetHost web hosting includes SSH access for managing your server files directly.