Blog / Operating systems & apps /

The Linux command line: ten commands to learn first

The command line looks like a black box with a blinking cursor. No buttons, no menus, no hints. For a first-time user that’s intimidating, and the internet doesn’t help, with its habit of pasting long commands that nobody explains.

Here’s the good news: you need very few commands to be useful. Ten will get you through most beginner tasks, whether you’re on a Linux server, a Chromebook’s Linux environment, a Mac terminal or Windows’ Linux subsystem. If you want the case for learning this at all, I made it in why every web admin should know a little Linux.

A note before we start: the examples below are safe to try in a practice folder. Never run a command you don’t understand, especially one that starts with sudo or contains rm.

How to read a command

A command usually has three parts:

command  -options  target
ls       -l        Documents

The command says what to do, options change how it does it, and the target says what to do it to. Press Enter to run it. Press the Tab key to auto-complete file names, which saves typing and mistakes.

1. pwd: where am I?

pwd

“Print working directory” shows the folder you’re currently in. When you open a terminal you start in your home folder, and it’s easy to forget where you’ve wandered. If a command can’t find a file, pwd is the first thing to check.

2. ls: what’s here?

ls
ls -l
ls -a

ls lists the files and folders in the current directory. -l shows details like size, owner and date, and -a also shows hidden files (those whose names start with a dot). Combine them as ls -la.

3. cd: move around

cd Documents
cd ..
cd ~

cd changes directory. cd Documents goes into a folder called Documents, cd .. goes up one level, and cd ~ returns to your home folder. Typing cd alone also takes you home on most systems.

Think of folders as rooms in a house: pwd tells you which room you’re in, ls shows what’s in the room, and cd walks you through the door.

4. mkdir: make a folder

mkdir practice

Creates a new folder called practice. To create nested folders in one go, add -p: mkdir -p projects/site/images.

Make a practice folder now, cd into it, and do the rest of this post inside it.

5. touch: create an empty file

touch notes.txt

Creates an empty file, or updates the timestamp if it already exists. Handy for practising without risk. (If you’d rather start with something that has content, echo "hello" > hello.txt creates a file containing the word hello.)

6. cp and mv: copy and move

cp notes.txt notes-backup.txt
mv notes-backup.txt archive.txt

cp copies a file. mv moves it, and it’s also how you rename: moving a file to a new name in the same folder renames it. To copy a whole folder, use cp -r foldername newname (the -r means recursive, so it includes everything inside).

Careful: if the destination already exists, both commands can overwrite it without asking. Adding -i makes them ask first: cp -i, mv -i.

7. cat and less: read a file

cat notes.txt
less notes.txt

cat prints a file to the screen. That’s fine for short files. For long ones, less lets you scroll with the arrow keys and search with /; press q to quit. Reading logs on a web server is where you’ll use less most.

8. grep: find text

grep "error" logfile.txt
grep -i "error" logfile.txt
grep -r "title" .

grep searches for text inside files. -i ignores upper and lower case, and -r searches through every file in a folder (the dot means “here”). If something goes wrong on a site, searching a log for a word like “error” or a page’s address is often the quickest way to find the cause.

You can chain commands with the pipe symbol |, which passes the output of one into another:

ls -l | grep "notes"

That lists files and keeps only the lines containing “notes”.

9. rm: delete (carefully)

rm archive.txt
rmdir emptyfolder

rm removes files. There is no Recycle Bin on the command line. Once it’s gone, it’s gone. Beginners should follow a few rules:

  • Use rm -i so it asks first.
  • Never run rm -r (which deletes folders and everything inside) unless you’ve checked with pwd and ls where you are.
  • Never copy and paste a command that includes rm -rf from somewhere you don’t trust.

rmdir only removes empty folders, so it’s the safer choice for folders.

10. man and --help: ask for help

man ls
ls --help

man opens the manual page for a command. It’s dense, but it lists every option. Press q to leave. --help gives a shorter summary for many commands. When you meet a new command, run it with --help before you use it. That habit makes you more independent than any list of memorised commands.

Two extras worth knowing

sudo: run as administrator

sudo apt update

sudo runs a command with administrator rights. It’s needed for installing software and changing system files, and it’s also where damage happens. Use it only for commands you understand. If a guide tells you to put sudo in front of something unfamiliar, stop and read what the command does first.

chmod: file permissions

Linux controls who can read, write and run each file. chmod changes those permissions. You’ll meet it when a script won’t run or a web server can’t read a file. Learn the idea (read, write, execute for owner, group and others) before memorising the numbers.

A practice session

Try this from top to bottom in a safe folder:

cd ~
mkdir practice
cd practice
touch notes.txt
echo "first line" > notes.txt
cp notes.txt copy.txt
ls -l
cat copy.txt
grep "first" notes.txt
mv copy.txt renamed.txt
ls

If every step makes sense, you’ve learned more than you think.

Where this helps if you run websites

  • Servers. Hosting control panels hide a lot, but SSH access gives you direct control. You can read error logs, check disk space and move files faster.
  • Backups. Copying and archiving a site’s files is quicker on the command line.
  • Version control and scripts. Tools like Git live here.
  • Learning environments. You can practise safely in the Linux box on a Chromebook (Linux apps on Chromebooks) or in Windows via Windows Subsystem for Linux.

If you want a system to practise on, which Linux distribution should a beginner try can help.

Common beginner mistakes

  • Typos. Linux is case-sensitive, so Notes.txt and notes.txt are different files.
  • Spaces in names. Wrap names that contain spaces in quotes.
  • Being in the wrong folder. Check with pwd.
  • Pasting commands blindly. Read first.

Key takeaways

  • Ten commands (pwd, ls, cd, mkdir, touch, cp, mv, cat/less, grep, rm) plus man and --help cover most beginner needs.
  • rm and sudo need extra care.
  • Practise in a throwaway folder.

Open a terminal and run the practice session above. Which command surprised you most?