The basic Linux commands are pwd, ls and cd to move around, mkdir, cp, mv and rm to manage files, cat, less, head and tail to read them, and grep and find to search. Learn those and the handful of options below and you can do most day-to-day work in a terminal.
All examples were run in a Bash shell with GNU coreutils 8.32, grep and GNU findutils 4.10, the same tools most Linux distributions ship. The error messages shown are the real ones. Names like alex are placeholders.
Commands at a glance
| Task | Command | Example |
|---|---|---|
| Where am I? | pwd | pwd |
| List files | ls | ls -lah |
| Change directory | cd | cd ~/projects |
| Make a directory | mkdir | mkdir -p notes/2026 |
| Create an empty file | touch | touch todo.txt |
| Copy | cp | cp -r notes backup |
| Move or rename | mv | mv draft.txt final.txt |
| Delete | rm | rm -i old.log |
| Show a file | cat, less | less /var/log/syslog |
| Start or end of a file | head, tail | tail -f app.log |
| Search inside files | grep | grep -rin "error" logs/ |
| Find files by name | find | find . -name "*.py" |
| Disk usage | du, df | du -sh backup, df -h |
| Manual page | man | man ls |
Moving around: pwd, ls, cd
pwd prints the directory you are in. cd changes it: cd projects goes into a subfolder, cd .. goes up one level, cd ~ (or just cd) goes to your home directory, and cd - jumps back to the previous directory.
ls lists the current directory. The options worth memorising:
-l: long format, one file per line with permissions, owner, size and date.-a: include hidden files (names starting with., such as.bashrc).-h: with-l, sizes like1K,234M,2Ginstead of bytes.-t: newest first.-S: largest first.-r: reverse the sort.
$ ls -lh notes
total 1.0K
drwxr-xr-x 1 alex alex 0 Oct 26 13:33 a
-rw-r--r-- 1 alex alex 35 Oct 26 13:33 app.log
The first column is the file type and permissions (d means directory); Linux file permissions explained covers how to read and change them. If you mistype a directory name, Bash says cd: nope: No such file or directory. Press Tab while typing a name to have the shell complete it, which avoids most of those typos.
Creating directories and files: mkdir, touch
mkdir notes
mkdir -p notes/2026/october
touch notes/todo.txt
Without -p, mkdir fails if the folder exists (mkdir: cannot create directory 'notes': File exists) or if a parent folder is missing. -p creates any missing parents and stays quiet if the directory is already there. touch creates an empty file, or updates the timestamp of an existing one.
Copying, moving and renaming: cp, mv
cp report.txt report-backup.txt # copy a file
cp -r notes backup # copy a directory and everything in it
mv draft.txt final.txt # rename
mv final.txt ~/Documents/ # move into another directory
The most common beginner error is copying a directory without -r:
$ cp notes backup
cp: -r not specified; omitting directory 'notes'
-r means recursive. Two more useful options: -i asks before overwriting an existing file, and -a (archive) copies recursively while preserving timestamps, permissions and links, which is what you want for backups. mv doesn't need -r for directories, and it overwrites an existing target without asking unless you add -i.
Deleting: rm, rmdir
rm old.log # delete a file
rm -i *.tmp # ask before each one
rm -r build/ # delete a directory and its contents
rmdir empty-folder # delete a directory only if it is empty
By default rm refuses directories, and rmdir refuses non-empty ones:
$ rm notes
rm: cannot remove 'notes': Is a directory
$ rmdir notes
rmdir: failed to remove 'notes': Directory not empty
There is no trash can. rm deletes immediately, and -f additionally suppresses every prompt and ignores files that don't exist. Before running rm -rf on a path built from a variable or a wildcard, run ls on the same path first to see exactly what it matches. -I is a gentler safety net than -i: it asks once when you delete more than three files or delete recursively.
Reading files: cat, less, head, tail, wc
cat fileprints the whole file. Fine for short files.less fileopens a scrollable viewer: arrow keys or Space to move,/wordto search,qto quit. Use this for anything long.head -n 20 fileandtail -n 20 fileshow the first or last 20 lines (10 by default).tail -f app.logkeeps the file open and prints new lines as they are written. Ctrl+C stops it.wc -l filecounts lines.
Searching inside files: grep
$ grep -in error notes/app.log
1:error: disk full
3:Error: timeout
-i ignores case (so it matched both error and Error), and -n shows line numbers. Other options you will use constantly:
-r: search every file under a directory, for examplegrep -rn "TODO" src/.-v: show lines that do not match.-l: print only the names of files that contain a match.-c: print the number of matching lines instead of the lines.
grep's exit status is useful in scripts: 0 if something matched, 1 if nothing matched, 2 if there was an error such as a missing file.
Finding files: find
find . -name "*.log" # by name, from the current directory down
find /var/log -type f -size +100M # files over 100 MiB
find . -mtime -1 # modified in the last 24 hours
Quote the pattern. Unquoted, the shell expands *.log before find sees it, which leads to the error find: paths must precede expression. find has many more tests and actions; Linux find command examples walks through them.
Disk space: du, df
df -h shows free space on each mounted filesystem. du -sh folder shows how much one folder uses, and du -sh * lists the size of everything in the current directory. To hunt down what is filling a disk, see how to find large files.
Combining commands: pipes and redirection
ls -lt | head -n 5 # five most recently changed files
grep -r "error" logs/ | wc -l # how many error lines in total
ls > files.txt # write output to a file (overwrites)
echo "done" >> files.txt # append to a file
The pipe | sends one command's output into the next. > replaces a file's contents, so double-check the target name; >> appends.
If a command isn't found
bash: sl: command not found means the program isn't installed or isn't on your PATH. Check the spelling, then run type name to see whether the shell knows it. Minimal installs (Docker images, small cloud servers) often leave out tools like less or man; install them with your distribution's package manager, for example sudo apt install less on Debian and Ubuntu.
Frequently asked questions
- How do I get help for a Linux command?
- Run man followed by the command name, for example man ls, to open its manual page; press q to quit and / to search inside it. Most GNU commands also print a shorter summary with --help, for example ls --help.
- Is there an undo for rm?
- No. rm deletes files directly; it does not move them to a trash folder. The rm manual notes that deleted contents can sometimes be recovered with enough skill and time, but you should not count on it. Use rm -i to be asked before each deletion, and keep backups.
- Do these commands work on macOS?
- Mostly yes. macOS ships BSD versions of commands such as ls, cp and find, which share the basic options shown here but can differ in long options (the ones starting with --) and output details. Running man on the Mac shows the exact options for its version.
- How can I practise Linux commands on Windows?
- Install the Windows Subsystem for Linux (WSL), which runs a real Linux distribution such as Ubuntu inside Windows. Git for Windows also includes Git Bash, which provides GNU versions of many of these commands.