Opening a terminal for the first time is often unsettling. Yet a dozen commands are enough to move between files and folders at a speed the graphical interface rarely allows. This article collects the ones I use every day and the habits that prevent the typical beginner mistakes.
Terminal, shell and prompt
The terminal is the window you type into. The shell is the program that interprets what you type: on most distributions it is Bash, on macOS since Catalina it is Zsh. The prompt is the line before the cursor and usually shows the user, the machine name and the current folder, for example:
anna@laptop:~/Documents$
The ~ symbol stands for your home folder, while $ marks a normal user. If you see #, you are working as administrator and should be more careful.
Where am I and what is here
pwd(print working directory) prints the full path of the current folder.lslists the folder's contents.ls -lshows details: permissions, owner, size, modification date.ls -aincludes hidden files, those whose name starts with a dot, such as.bashrc.ls -lhmakes sizes human-readable (K, M, G instead of bytes).
Options can be combined: ls -lah is probably the most used variant of all.
Moving around: cd and paths
The cd command changes folder. The tricky part is understanding the difference between two kinds of path.
Absolute paths
They start with /, the root of the filesystem, and always point to the same place regardless of where you are: cd /var/log takes you there from anywhere.
Relative paths
They start from the current folder. If you are in /home/anna and type cd Documents, you land in /home/anna/Documents. Two shortcuts are essential:
.means the current folder;..means the parent folder, socd ..goes up one level.
Other useful shortcuts: cd on its own or cd ~ takes you back home, cd - returns to the folder you were in before.
Creating, copying, moving
| Command | What it does | Example |
|---|---|---|
mkdir |
creates a folder | mkdir projects |
mkdir -p |
also creates intermediate folders | mkdir -p photos/2025/summer |
touch |
creates an empty file or updates its date | touch notes.txt |
cp |
copies a file | cp notes.txt notes-backup.txt |
cp -r |
copies a folder with its contents | cp -r projects projects-copy |
mv |
moves or renames | mv notes.txt archive/ |
The mv command does not distinguish between moving and renaming: mv old.txt new.txt changes the name, mv file.txt folder/ moves it. Be careful: if the destination file already exists, cp and mv overwrite it without asking. The -i (interactive) option makes them ask for confirmation.
Deleting: rm has no trash
rm file.txt deletes a file, rm -r folder deletes a folder and everything in it. There is no trash: what rm deletes cannot be restored with a click. A few habits reduce the risk:
- Before deleting with a wildcard, check what matches:
ls *.logand only thenrm *.log. - Use
rm -iwhen deleting several files in a folder you do not know well. - Be wary of commands copied from the internet that contain
rm -rf: the-foption suppresses every confirmation. - To remove an empty folder there is
rmdir, which fails if the folder contains anything: a small safety net.
Reading files without opening an editor
cat file.txtprints the whole content, fine for short files.less file.txtlets you scroll through a long file; quit withqand search with/word.head -n 20 file.txtshows the first 20 lines,tail -n 20the last ones.tail -f logfile.logkeeps listening and shows new lines as they are written: very handy for following a log in real time.
Shortcuts that save time
The Tab key completes file and command names: type cd Doc and press Tab, and the shell completes it to Documents/. If there are several possibilities, a double Tab lists them. Besides saving time, completion prevents typos in names.
The up and down arrows scroll through commands you have already run. Ctrl+R starts a reverse search through the history: type part of a command used days ago and the shell finds it. Ctrl+C interrupts the running command, Ctrl+L clears the screen.
Names with spaces and special characters
The shell uses spaces to separate arguments, so cd Holiday photos is read as two arguments. The fixes are quotes, cd "Holiday photos", or a backslash, cd Holiday\ photos. Tab completion inserts the correct escaping automatically. For files you create yourself, names without spaces or accented letters, using hyphens or underscores, make life easier in the long run.
When you cannot remember an option
Every command has a manual: man ls opens the full documentation. Many commands also accept --help for a shorter summary. Reading the first lines of a man page before using an unfamiliar option is a habit that prevents a lot of trouble.
In short
pwd,lsandcdare enough to find your way; learn the difference between absolute and relative paths.cp,mvandrmoverwrite and delete without asking: use-iwhen needed.rmhas no trash: check withlswhat matches before deleting.- Tab, the arrow keys and
Ctrl+Rmake the terminal faster and less error-prone. manand--helpare the first place to look for any command.