What is the terminal?
The terminal is a window where you type commands to a computer. A directory is another word for a folder. You connect to a hosting server with SSH, which is a safe way to open a terminal on a remote computer.
Check where you are
- Type this to see your current folder:
pwd
This prints the path of the folder you are in.
- List the files:
ls -l
This shows the files with details.
Remove one file
rm notes.txt
This deletes the file named notes.txt.
To be asked before each deletion, add -i:
rm -i notes.txt
This asks "remove?" and waits for you to type y or n.
Remove many files
rm *.log
This deletes every file in the folder that ends in .log. The star means "anything".
Remove an empty folder
rmdir oldfolder
This removes the folder only if it has nothing inside.
Remove a folder with files in it
rm -r oldfolder
The -r means recursive. It deletes the folder and everything inside it.
To skip questions, add -f, which means force:
rm -rf oldfolder
This deletes the folder and all its contents without asking.
Safety habits
- Run
lson the folder first to see what is inside. - Never run
rm -rf /orrm -rf *unless you are fully sure of your location. These can wipe a whole system or site. - Use the full path if in doubt, for example
rm -r /home/user/old-backup. - Use
rm -iwhile you are learning.
Common errors
- No such file or directory: the name is wrong. Check spelling and case.
- Permission denied: you do not own the file. On a VPS with root access, you can use
sudo rm, but be extra careful. - Is a directory: use
-rfor folders.
Quick recap
rm filedeletes a file.rmdirdeletes an empty folder.rm -r folderdeletes a folder and its contents.- There is no undo, so back up and double-check.