Migrate to RunxBuild and earn up to $50 in hosting credit on your first deposit.

Calculate your savings
unxBuild

Remove Directory Linux: rmdir for Empty, rm -rf for Recursive

Sean

Platform Writer

Jul 05, 2026
4 min read

Remove directory Linux: rmdir dir for empty (safe), rm -rf dir for non-empty (careful!). rm -rf / will destroy a system. The team that uses rmdir for safe empty removal and rm -rf only with explicit verification has correct practice.

Remove Directory Linux: rmdir for Empty, rm -rf for Recursive

Table of contents

rmdir (empty only)

rmdir /tmp/empty_dir
# Or multiple
rmdir dir1 dir2 dir3

Errors if directory is not empty. The team that uses rmdir has safe empty-directory removal.

rm -rf (recursive force)

rm -rf /tmp/some_dir
  • -r: recursive (delete contents too).
  • -f: force (no prompts, ignore nonexistent files).

The team that uses rm -rf has the dangerous tool. Use carefully.

Safety practices

  1. rm -i for interactive (prompts before each delete).
  2. Use absolute paths to avoid ambiguity.
  3. Check pwd before rm -rf.
  4. rm -rf / will destroy a Linux system - many distros have a safety check (--preserve-root).
  5. Use trash-cli or similar for soft delete with recovery.

The dangerous rm -rf /

# DO NOT RUN THIS
sudo rm -rf /

This recursively deletes everything from /. Modern systems have --preserve-root as default (refuses to delete /), but sudo can override.

Find before delete

Before rm -rf, verify the contents:

ls -la /path/to/dir
find /path/to/dir -type f | head

The team that previews has confidence in the deletion scope.

Recover from rm -rf

Recovery options (none guaranteed):

  • Backups: restore from backup (the right answer).
  • extundelete: undelete tool for ext3/ext4. Works only if filesystem space isn’t reused.
  • testdisk/photorec: file carving tools. May recover some files.
  • Filesystem journaling: ext4 has journaling, may help partial recovery.

The team that has backups has recovery. The team that has rm -rf without backup has data loss.

FAQ

What’s the difference between rmdir and rm -rf?

rmdir: empty only, safe. rm -rf: non-empty, dangerous. The team that picks based on the situation has correct usage.

Can I recover files after rm -rf?

Only with backups or specialized recovery tools (rarely successful). The team that has backups has the right answer.

Is rm -rf / safe?

No - never. Modern systems have safety but you can override. The team that never types this is safe.

How do I delete a directory with millions of files?

rm -rf is slow. The team that has many files uses find dir -delete or rsync --delete for faster.

Can I undo rm -rf?

No. The team that has backups restores. The team that uses trash-cli has soft delete with recovery.

If you are sizing the infrastructure for the kind of project this post covers, the RunxBuild hosting calculator is the right place to model the line items. The compute, the memory, the storage, the bandwidth, the database - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers. The RunxBuild dashboard is where the team sees the actual usage in one place.

Useful related references:

#linux#rm#rmdir#command#dev-infra