How to delete a folder?

QuestionsQuestions8 SkillsProBasic Files OperationsDec, 02 2025
066

To delete a folder in Linux, you can use the rmdir or rm command, depending on whether the folder is empty or contains files. Here’s how to use both commands:

1. Deleting an Empty Folder

If the folder is empty, you can use the rmdir command:

rmdir folder_name

Example:

To delete an empty folder named old_folder, you would run:

rmdir old_folder

2. Deleting a Non-Empty Folder

If the folder contains files or other directories, you need to use the rm command with the -r (recursive) option:

rm -r folder_name

Example:

To delete a folder named my_files that contains files, you would run:

rm -r my_files

Important Note:

  • Be Cautious: The rm -r command will permanently delete the folder and all its contents without any confirmation. Make sure you really want to delete it before running the command.

Verify Deletion:

You can check if the folder has been deleted by listing the contents of the directory:

ls

If you have any further questions or need assistance, feel free to ask!

0 Comments

no data
Be the first to share your comment!