How to delete a directory safely?

QuestionsQuestions8 SkillsProBasic Files OperationsDec, 08 2025
061

To delete a directory safely, you can use the rm command with the -ri options. This will prompt you for confirmation before deleting each file or subdirectory within the specified directory. Here’s the command:

rm -ri directory-name

This way, you can review each item before it is deleted, reducing the risk of accidentally removing important files.

Alternatively, if you want to ensure that the directory is empty before deletion, you can first check its contents using:

ls directory-name

If it is empty, you can then use:

rmdir directory-name

This method ensures that you only delete directories that do not contain any files or subdirectories.

0 Comments

no data
Be the first to share your comment!