Menu
Coddy logo textTech

Delete A Directory

Part of the Fundamentals section of Coddy's Terminal journey — lesson 19 of 82.

To delete a directory in the terminal, you have two options depending on whether the directory is empty or not.

Deleting an empty directory:

The rmdir command stands for remove directory. It can only delete a directory that is completely empty:

rmdir empty_folder

If the folder contains any files or subdirectories, rmdir will fail with an error.

Deleting a directory and all its contents:

To delete a directory along with everything inside it, use rm with the -r flag (recursive):

rm -r documents

This removes the documents folder and every file and subfolder inside it.

You can also combine it with -f to force delete without any confirmation prompts:

rm -rf documents

Warning: rm -rf is one of the most powerful and dangerous commands in the terminal. It permanently deletes everything without asking. Always double-check your path before running it — there is no undo.

challenge icon

Challenge

Beginner

Delete the documents directory and all its contents using rm -r, then use ls to confirm it has been removed.

Warning: This will permanently delete the directory and everything inside it. There is no way to recover deleted directories in the terminal!

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals