- A small set of Linux commands covers most daily work:
ls,cd,cp,mv,rm,catandgrep. - Pipes (
|) connect simple tools to answer harder questions. rmhas no recycle bin, so double-check before you press Enter.- Use
manor--helpwhenever you forget an option.
Most servers, containers and cloud machines run Linux, and they usually do not have a graphical desktop. That is why learning Linux commands is such a useful skill for developers and testers alike. You do not need to memorize hundreds. A few dozen will carry you a long way.
We tested the file, search and pipe examples in Git Bash on Windows, which provides the same core tools, and the output comes from that run. We did not run the commands for permissions, services, packages and remote access, because they depend on a real Linux system. Details can vary by distribution, so check your own system’s documentation.
Getting started safely
You do not need to install Linux to practise. Good options include:
- Windows: Windows Subsystem for Linux (WSL), or Git Bash for the basics.
- macOS: the built-in Terminal, whose commands are very similar, though some options differ.
- Any system: a container. Our Docker tutorial for beginners shows how to start one.
Practise in a throwaway folder, and remember that everything in Linux is case-sensitive: Notes.txt and notes.txt are different files.
Anatomy of a command
ls -l /var/log
^ ^ ^
| | argument: what to act on
| option: how to behave
command: what to run
Short options can usually be combined, so ls -l -a and ls -la are the same. Long options use two dashes, as in --help. For help, run man ls for the full manual, or ls --help for a summary. Press q to leave a manual page.
Move around the file system
| Command | What it does |
|---|---|
pwd |
Prints your current folder |
ls |
Lists files |
ls -la |
Lists all files, including hidden ones, with details |
cd folder |
Moves into a folder |
cd .. |
Moves up one level |
cd ~ |
Goes to your home folder |
cd - |
Returns to the previous folder |
Press Tab to auto-complete file names, and the up arrow to bring back earlier commands. These two habits save more time than any other tip here. A file name beginning with a dot, such as .env, is hidden, and ls shows it only with -a.
Manage files and folders
| Command | What it does |
|---|---|
mkdir -p project/logs |
Creates folders, including parents |
touch notes.txt |
Creates an empty file |
cp a.txt b.txt |
Copies a file |
cp -r src/ backup/ |
Copies a folder |
mv a.txt b.txt |
Renames or moves a file |
rm a.txt |
Deletes a file |
rm -r folder/ |
Deletes a folder and everything in it |
Here is a short session from our run:
$ mkdir -p project/logs
$ cd project
$ touch notes.txt
$ ls
logs notes.txt
$ cp notes.txt backup.txt
$ mv backup.txt old.txt
$ ls
logs notes.txt old.txt
$ rm old.txt
$ ls
logs notes.txt
Tip: rm does not use a recycle bin, and deleted files are generally gone. Be especially careful with rm -r and wildcards. Run ls with the same pattern first, to see exactly what would match, and use rm -i if you want a prompt for each file.
View file contents
| Command | What it does |
|---|---|
cat file |
Prints a whole file |
less file |
Scrolls through a long file (q to quit) |
head -n 5 file |
Shows the first five lines |
tail -n 5 file |
Shows the last five lines |
tail -f file |
Follows new lines as they are written |
wc -l file |
Counts lines |
For the next few examples, we created a small log file:
$ cat logs/app.log
ERROR db down
INFO started
ERROR disk full
INFO stopped
$ head -n 1 logs/app.log
ERROR db down
$ tail -n 1 logs/app.log
INFO stopped
$ wc -l logs/app.log
4 logs/app.log
tail -f is a daily tool for watching a live application log while you reproduce a bug. Press Ctrl+C to stop it.
Search with grep and find
grep searches inside files, and find searches for the files themselves:
$ grep ERROR logs/app.log
ERROR db down
ERROR disk full
$ grep -c ERROR logs/app.log
2
$ find . -name "*.log"
./logs/app.log
| Option | Meaning |
|---|---|
grep -i |
Ignores case |
grep -r |
Searches a folder recursively |
grep -n |
Shows line numbers |
grep -v |
Shows lines that do not match |
grep -c |
Counts matching lines |
Pipes and redirection
This is the idea that makes the command line so powerful. Each tool does one small job, and you connect them:
| Symbol | What it does |
|---|---|
| |
Sends one command’s output into the next |
> |
Writes output to a file, replacing its contents |
>> |
Appends output to a file |
2> |
Writes error messages to a file |
$ echo "hello" > greeting.txt
$ echo "world" >> greeting.txt
$ cat greeting.txt
hello
world
Be careful with a single >, because it silently overwrites what was already in the file.
A real example: summarize a log
How many lines of each type are in our log? Combining four simple commands gives the answer:
$ cut -d' ' -f1 logs/app.log | sort | uniq -c
2 ERROR
2 INFO
Reading from left to right: cut takes the first space-separated word on each line, sort groups identical words together, and uniq -c counts each group. The sort step matters, because uniq only collapses neighbouring duplicates. Add | sort -nr to the end to list the most common first.
This kind of one-liner is a great help when you are investigating failures. It can quickly tell you whether an error happened twice or two thousand times, which is useful detail to put in a bug report.
File permissions
Run ls -l and you will see something like this:
-rwxr-xr-- 1 asha devs 512 Nov 1 10:00 deploy.sh
After the first character, which shows the file type, there are three groups of three characters, for the owner, the group and everybody else. Each can have r (read), w (write) and x (execute).
| Command | What it does |
|---|---|
chmod +x deploy.sh |
Makes a script executable |
chmod 644 file |
Owner can read and write, others can read |
chmod 755 script.sh |
Owner has full access, others can read and run |
chown asha file |
Changes the owner |
sudo command |
Runs a command as an administrator |
The numbers add up: read is 4, write is 2 and execute is 1. So 7 means all three, and 5 means read and execute. Avoid chmod 777, which gives everyone full access, as a quick fix for permission errors. Find the real cause instead. And use sudo carefully, since it removes the safety checks that normally protect the system.
Processes and system information
| Command | What it does |
|---|---|
ps aux |
Lists running processes |
top or htop |
Shows a live view of CPU and memory |
kill 1234 |
Asks process 1234 to stop |
df -h |
Shows free disk space |
du -sh folder |
Shows a folder’s size |
free -h |
Shows memory use |
systemctl status nginx |
Shows a service’s status |
journalctl -u nginx |
Shows a service’s logs |
To install software, use your distribution’s package manager, such as sudo apt install curl on Debian and Ubuntu, or sudo dnf install curl on Fedora and RHEL.
Archives and remote work
$ tar -czf logs.tar.gz logs
$ tar -tzf logs.tar.gz
logs/
logs/app.log
In tar, c means create, z means gzip, f names the file and t lists the contents. To extract an archive, use tar -xzf logs.tar.gz. For working with other machines, these three are what you need:
| Command | What it does |
|---|---|
ssh user@server |
Opens a remote terminal |
scp file user@server:/path/ |
Copies a file over SSH |
curl -I https://example.com |
Shows a URL’s response headers |
These same commands are used inside Dockerfiles and CI/CD pipelines, so this knowledge pays off across DevOps work.
Common mistakes
- Using
rm -rfwithout looking. Check your folder withpwdfirst, and be careful with spaces in paths. - Overwriting with
>. Use>>when you meant to append. - Running everything with
sudo. Use it only when it is required. - Pasting commands you do not understand. Read them first, especially anything piping a download into a shell.
- Forgetting quotes. A file name with spaces, like
"my file.txt", needs them.
Final thoughts
You do not learn the terminal by reading about it. Open a shell, make a practice folder and run each section’s commands. Then try to answer a real question using a pipe, like which error appears most often in a log. Start with navigation and files this week, add grep and pipes next, and the rest will follow as you need it.
Frequently asked questions
What are the most basic Linux commands?
Start with pwd, ls, cd, mkdir, cp, mv, rm, cat and grep. These cover moving around, managing files and searching, which makes up most everyday terminal work.
How can I practise Linux commands on Windows?
Use Windows Subsystem for Linux for a full environment, or Git Bash for the basics. Running a Linux container with Docker also works well.
What is the difference between > and >> in Linux?
A single > replaces the file’s contents with the output. A double >> adds the output to the end of the file and keeps what is already there.
Can I undo the rm command?
Generally no, because rm does not use a recycle bin. Recovery tools sometimes help but are not reliable, so keep backups and check carefully first.
What does sudo mean?
sudo runs a single command with administrator rights. It is needed for tasks such as installing software, and it should be used with care.
Keep learning
Need help with testing, WordPress or SEO?
We help teams ship better software and grow their sites. Tell us what you are working on and we will suggest a clear next step.