To delete multiple files at once, you use the rm (remove) command. Just like with touch, you can specify multiple files or use patterns.
Here are the most common ways to do it:
1. List the files individually
Separate each filename with a space:
rm file1.txt file2.txt
2. Use "Brace Expansion"
If the files follow a naming pattern, you can delete them all at once:
rm testdir/file{1,2,3}.txt
3. Use Wildcards (*)
The asterisk * acts as a wildcard meaning "anything." This is very powerful, so be careful when using it!
- Delete all files starting with "file":
rm file* - Delete all
.txtfiles in a directory:rm testdir/*.txt - Delete everything inside a specific directory:
rm testdir/*
4. Delete a directory and everything inside it
To delete a folder and all the files/folders inside it, you need the -r (recursive) flag:
rm -r testdir
💡 A Friendly Tip from Labby:
The rm command is permanent! There is no "Recycle Bin" in the Linux command line. Once a file is deleted with rm, it is gone.
If you want to be safe, you can add the -i (interactive) flag, which will ask for your permission before deleting each file:
rm -i file1.txt file2.txt
Give it a try with the files you created