How to remove directories safely?

QuestionsQuestions8 SkillsProBasic Files OperationsNov, 18 2025
074

To remove directories safely, you can use the rm command with the -i option, which prompts you for confirmation before each deletion. Here’s how to do it:

  1. For an empty directory:
    Use rmdir for empty directories:

    rmdir -i directory-name
  2. For non-empty directories:
    Use rm with the -r (recursive) and -i (interactive) options:

    rm -ri directory-name

This way, you will be asked to confirm each file and directory deletion, helping to prevent accidental loss of important data. Always double-check the directory name before confirming the deletion.

0 Comments

no data
Be the first to share your comment!