Legend has it that using the terminal makes you a ninja with superpowers. It might look like a boring black window with not much going on, but once you know your way around, it becomes your go-to tool for most tasks. The terminal gives you speed, efficiency, and easy automation that GUI apps can’t match.

Here are the Linux commands every programmer should know.

How to read this post: the gray boxes show commands being used in a terminal. Type the part after the $ (don’t type the $ itself), and the lines below it show what you’ll see.

The sample file

Most examples use this file, names.txt:

Name,Country
Brian Lara,Trinidad & Tobago
Shivnarine Chanderpaul,Guyana
Ramnaresh Sarwan,Guyana
Chris Gayle,Jamaica
Darren Bravo,Trinidad & Tobago
Christopher Barnwell,Guyana

1. man and --help

These are the first two things any Linux developer should learn, because they teach you everything else. man (manual) gives a full description and usage details for almost any command. --help gives a shorter summary.

They’re called differently: man goes before the command, --help goes after it.

$ man ls
$ ls --help

In the manual, scroll with j (down) and k (up), or d and u for half a page at a time. Press q to quit.

2. ls

Unless you have a photographic memory for every file on your system, you’ll need ls. It lists files and directories, and it’s what makes working without a GUI possible.

$ ls
days.txt  names.txt

It has plenty of options for how results are displayed. My favourite combination:

$ ls -lrth
total 8.0K
-rw-r--r-- 1 pi pi 176 Feb 26 19:27 names.txt
-rw-r--r-- 1 pi pi  57 Feb 26 19:52 days.txt

That’s long format, reverse order, sorted by time (newest at the bottom), with human-readable sizes.

3. grep

Probably one of the most used commands. Simply put, grep searches. What makes it great is its flexibility, and the fact that it can search almost anything in the terminal.

Say you want every line in a file containing “Guyana”:

$ grep Guyana names.txt
Shivnarine Chanderpaul,Guyana
Ramnaresh Sarwan,Guyana
Christopher Barnwell,Guyana

A few options I use all the time:

$ grep -i guyana names.txt       # ignore upper/lower case
$ grep -v Guyana names.txt       # lines that DON'T match
$ grep -c Guyana names.txt       # count matching lines
$ grep -r "TODO" ~/projects      # search every file in a folder

And it’s not just for files. Pipe any command’s output into it (more on pipes in #12):

$ ps aux | grep nginx            # is nginx running?
$ history | grep docker          # what was that docker command again?

4. less

less shows a file, or another command’s output, in a scrollable view. It’s great for long files like application logs.

$ less names.txt

Search inside it by typing / followed by a word, then press n to jump to the next match. Press q to quit.

It also works with other commands’ output:

$ grep Guyana names.txt | less

5. cat

cat concatenates files and prints the result to the screen. I mostly use it to quickly see what’s in a file, or to join files together.

$ cat girls.txt boys.txt
Jane
Mary
John
Mark

Tip: save the result to a file with the > redirect:

$ cat girls.txt boys.txt > allnames.txt

Careful: > overwrites the file if it already exists. Use >> to add to the end instead.

6. cut

This one does exactly what it sounds like: it cuts a segment out of each line. You can cut by position (characters 5 to 10, say) or by a delimiter character.

To split on commas with -d and return the 2nd field with -f:

$ cut -d ',' -f 2 names.txt
Country
Trinidad & Tobago
Guyana
Guyana
Jamaica
Trinidad & Tobago
Guyana

To cut by character position, use -c:

$ cut -c 1-5 names.txt
Name,
Brian
Shivn
Ramna
Chris
Darre
Chris

Challenge: how would you get just the first name of each cricketer? The answer is at the end.

7. head and tail

No, we’re not flipping a coin. head shows the top of a file and tail shows the bottom, 10 lines by default. They’re handy for peeking at a file.

$ head -n 3 names.txt
Name,Country
Brian Lara,Trinidad & Tobago
Shivnarine Chanderpaul,Guyana

$ tail -n 2 names.txt
Darren Bravo,Trinidad & Tobago
Christopher Barnwell,Guyana

Bonus: tail -f follows a file, printing new lines as they’re added. It’s perfect for watching a log in real time. Press Ctrl+C to stop.

$ tail -f /var/log/nginx/access.log

8. alias

alias lets you do magic with fewer keystrokes. It creates a shortcut for any command; think of it as a short link for commands.

Say your terminal had a command called thisisanimaginarycommandthatdoesmagic. Typing that every time would get old fast. Give it an alias instead:

Creating the alias:

# Note: NO spaces around the = sign
$ alias doMagic='echo "This Is An Imaginary Command That Does Magic"'
# Note: NO spaces around the = sign
$ alias doMagic='echo "This Is An Imaginary Command That Does Magic"'

$ doMagic
This Is An Imaginary Command That Does Magic

It might seem trivial, but used smartly, aliases will save you tons of time. One of my favourites:

$ alias ls='ls -lrth'

Making aliases permanent: aliases created this way disappear when you close the terminal. To keep them, add the same line to the end of your ~/.bashrc file, then reload it:

$ echo "alias ls='ls -lrth'" >> ~/.bashrc
$ source ~/.bashrc

9. history

history lists the commands you’ve run. It’s great when you’re too lazy to retype something, or you want to know when you ran it.

Timestamps aren’t shown by default. To turn them on, add this line to ~/.bashrc, then run source ~/.bashrc:

export HISTTIMEFORMAT="%F %T "
$ history
...
601  2019-12-27 21:13:54 ls -lrth
602  2019-12-27 21:13:58 cd
603  2019-12-27 21:13:59 pwd
604  2019-12-27 21:14:01 ls
605  2019-12-27 21:14:03 history

Two shortcuts worth knowing:

  • Ctrl+R searches your history as you type. Press it again to cycle through older matches.
  • !! repeats the last command. The classic use is sudo !! when you forgot sudo.

10. wc

wc (word count) counts lines, words, and characters. It’s handy if you’re writing your 5,000-word essay in the terminal and wondering if you’ve hit the target.

$ wc -l names.txt      # lines
7 names.txt

$ wc -c names.txt      # characters (bytes)
176 names.txt

11. htop

If you’re coming from Windows, think of htop as Task Manager for Linux. It’s an interactive view of running processes and resource usage, and you can manage processes from it.

It isn’t always installed by default:

$ sudo apt install htop      # Debian, Ubuntu, Raspberry Pi OS
$ sudo dnf install htop      # Fedora, Amazon Linux

Press q to exit.

12. The pipe |

The pipe sends one command’s output into another command as input. It’s what lets you chain small commands into powerful ones. On most keyboards, it shares a key with the backslash \.

For example, search for a pattern, then count how many lines matched:

$ grep Guyana names.txt | wc -l
3

13. bg, fg, and jobs

These let you move running processes (jobs) to the background or foreground.

Say you’re reading a file with less names.txt and need to check something else quickly. Press Ctrl+Z to pause it and send it to the background:

$ less names.txt
# Ctrl+Z pressed
[1]+  Stopped                 less names.txt

The number in brackets is the job ID. jobs lists everything that’s paused or running in the background:

$ jobs
[1]-  Stopped                 less names.txt
[2]+  Stopped                 less days.txt

Bring one back with fg and its ID:

$ fg 1

bg resumes a paused job but keeps it in the background. That’s useful for long-running tasks you don’t need to watch.

Summary

These are just a few of my favourite, most-used commands. The possibilities really are endless. Learn these and you’ll be well on your way to becoming the next Linux ninja. Careful with that shuriken.

What are your favourite commands?

Challenge answer: skip the header with tail, cut out the first name deflimited by the space:

$ tail -n +2 names.txt | cut -d ' ' -f 1
Brian
Shivnarine
Ramnaresh
Chris
Darren
Christopher

Last Update: October 29, 2026