How to remove non-empty directories?

QuestionsQuestions8 SkillsProBasic Files OperationsSep, 27 2025
0218

To remove a non-empty directory, you can use the rm command with the -r (recursive) option. The syntax is as follows:

rm -r directory_name

Example:

If you have a directory named non_empty_dir that you want to remove, you would run:

rm -r non_empty_dir

Important Note:

  • Be cautious when using this command, as it will delete the directory and all of its contents permanently. If you want to be prompted before each deletion, you can add the -i option:
rm -ri non_empty_dir

This will ask for confirmation before deleting each file and subdirectory.

0 Comments

no data
Be the first to share your comment!