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 chapter1.md
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
clear
rm files/backups/chapter1.md
ls files/backups
Run the above code on the terminal below for practice.
Get hands-on with 1200+ tech skills courses.