Start by looking, not changing
pwd shows where you are. ls shows what is there. cd moves between folders. These three commands are the terminal equivalent of opening folders in a file manager.
pwd
# /home/ubuntu
ls -la
# drwxr-xr-x 4 ubuntu ubuntu 4096 Jul 16 11:00 Documents
# drwxr-xr-x 2 ubuntu ubuntu 4096 Jul 14 09:00 Downloads
# -rw-r--r-- 1 ubuntu ubuntu 120 Jul 13 18:21 README.md
cd ~/Documents
pwd
# /home/ubuntu/Documents
Create, copy, move, remove
mkdir creates a directory, cp copies, mv moves or renames, and rm removes. Before using rm, run pwd and ls. Linux assumes you meant what you typed.
mkdir practice
cp notes.txt practice/
mv practice/notes.txt practice/linux-notes.txt
rm practice/linux-notes.txt
Read files and get help
less opens long text one screen at a time. grep searches text. man opens the built-in manual — every command on the system has one.
less /var/log/syslog
grep -i "error" /var/log/syslog
man grep
Update and install
Most everyday Linux administration comes down to two commands: apt update followed by apt upgrade. The first refreshes the list of available packages; the second installs the upgrades.
sudo apt update
sudo apt upgrade -y
sudo apt install htop
sudo apt remove htop
Find what is happening
ps lists running processes. top (and the prettier htop) shows live CPU and memory use. df -h shows disk space. These four commands answer the most common “why is my machine slow” questions.
top
df -h
free -h
ps aux | grep nginx
Permissions and ownership
Every file has an owner, a group, and three permission bits per role. ls -l reads them. chmod changes them. chown changes the owner. You will see chmod +x in almost every tutorial.
ls -l /usr/local/bin/script.sh
# -rwxr-xr-x 1 root root 1.2K Jul 15 14:00 /usr/local/bin/script.sh
chmod +x script.sh
chown ubuntu:ubuntu file.txt
The one safety habit that matters
Do not paste commands you do not understand, especially commands beginning with sudo. Break a long command into pieces, inspect paths first, and use the manual when a flag is unfamiliar.
The terminal is not a place where clever happens. It is a place where transparent happens. Every keystroke records, every command documents itself in man, every change can be undone (mostly).
The Linux Institute team
What to learn next
- Shell pipes.
cat file.txt | grep word | sort | uniq. Four commands, glued into one fact-finding tool. - SSH.
ssh user@hostto log into another machine.scpto copy.ssh-keygento stop typing passwords. - systemd.
systemctl status nginx,journalctl -u nginx -f. The two commands you reach for when something stops working. - cron.
crontab -eto schedule a script. The 5-field syntax is the rest of the day.