Linux Command Line Basics: A Concise Primer for New Devs
If you're going to build software on a server, you'll live in the terminal. Here are the commands that cover most of what you'll do, explained plainly.
1Where am I? What's here?
pwd # print working directory (where I am)
ls # list files in this directory
ls -la # long format, including hidden files (those starting with .)
cd <dir> # change directory
cd .. # go up one level
cd ~ # go to my home directory
~ is a shortcut for your home. . is the current directory, .. the parent.
2Reading and creating files
cat file.txt # print a file's contents
head -20 file.txt # first 20 lines
tail -20 file.txt # last 20 lines
less file.txt # scroll through a file (q to quit)
touch newfile.txt # create an empty file (or update its timestamp)
nano file.txt # edit a file in a simple editor (Ctrl+O save, Ctrl+X exit)
To see line numbers while reading: cat -n file.txt.
3Moving, copying, removing
cp source.txt dest.txt # copy
mv old.txt new.txt # move or rename
rm file.txt # remove a file
rm -r directory/ # remove a directory and its contents
mkdir newdir # make a directory
rm -r is dangerous — it deletes recursively and permanently. There's no undo. rm -rf / would delete everything; never type that casually.
4Searching inside files
grep finds lines matching text:
grep "error" server.log # lines containing "error"
grep -i "error" server.log # case-insensitive
grep -rn "config" /etc/nginx/ # recursive search across files with line numbers
5Piping: combining commands
The pipe | sends one command's output into the next:
ls -la | grep nginx # list, then filter to lines mentioning nginx
cat server.log | tail -50 # all lines, then keep the last 50
history | grep docker # find a command you ran before
This is the shell's superpower — small commands combined to do big things.
6Permissions
Every file has a user and a group, with read/write/execute rights for each:
ls -l file.txt # shows permissions like -rw-r--r--
chmod +x script.sh # make a script executable
chmod 600 secrets.json # owner read/write only (good for secrets)
chown user:group file # change owner/group
A quick mental map: chmod 600 = owner can read+write, everyone else nothing (for secrets). chmod 755 = owner full, others read+execute (for programs/directories).
7Processes and resources
top # live view of CPU/memory by process
ps aux | grep nginx # find a running process
kill <pid> # end a process by ID
df -h # disk space
free -h # memory
On a small server, free -h and df -h are your first stops when something feels slow.
8Superuser
On Ubuntu, sudo runs a command as root:
sudo apt update # package manager refresh (needs privileges)
sudo is powerful — only use it when a command genuinely needs it, and always double-check the command.
The habit that beats memorizing
You don't need to memorise everything. man <command> opens a command's manual (man ls, man grep), and command --help shows a summary. When stuck:
somecommand --help
That, plus the pipe, plus grep, covers a surprising amount of real work. Everything else you look up as you go.