Deleting Files and Directories

Learn how to delete files and directories.

We'll cover the following

In the GUI, we delete files by dragging them to the Trash, the Recycle Bin, or some other metaphor for reclaiming disk space. On the command line, we typically skip that intermediate step and directly remove the files or directory.

The rm command

To delete a file, we use the rm command. Let’s delete the file in the files/backups/ directory:

mkdir -p files/{movies,music,photos,docs/{diagrams,markdown},code/{go,js,elm}}
touch files/docs/markdown/chapter{1..3}.md
mkdir files/backups
cp files/docs/markdown/*.md files/backups
rm files/backups/
ls files/backups

Run the above code on the terminal below for practice.

Get hands-on with 1200+ tech skills courses.