Essential Linux Commands Every User Should Know (With Examples)
A small set of Linux commands covers most everyday work in the terminal. With them you can move around folders, manage and find files, search text, see what’s running, check disk space, change permissions and edit a file over SSH. Each section below gives the command, what it does and an example you can try right away. The commands work the same way on Ubuntu, Debian, Fedora, Arch Linux and almost every other distribution.
The terminal on Linux Mint 19.2 Xfce Edition, running the cmatrix command
Getting help: man and –help
Before anything else, know how to look up a command. man opens the full manual page, and most commands print a short summary with --help. In man, press / to search and q to quit.
$ man grep
$ ls --help
Navigating and listing files
pwdprints the current working directory.ls -lalists all files, including hidden ones, with permissions, owner, size and modification date.cd <path>changes directory.cd ..goes up one level andcd ~(or justcd) goes to your home directory.
$ pwd
/home/user/projects
$ ls -la
drwxr-xr-x 4 user user 4096 Aug 3 10:00 .
-rw-r--r-- 1 user user 220 Aug 3 10:00 notes.txt
Creating, copying, moving and deleting files
mkdir -p a/b/ccreates a directory, including any missing parent directories.cp file copycopies a file. Add-rto copy a directory and everything in it.mv old newmoves or renames a file or directory.rm filedeletes a file.rm -r dirdeletes a directory and its contents.
$ mkdir -p backups/2026
$ cp -r projects backups/2026/
$ mv notes.txt notes-old.txt
rm does not use a trash bin, so deleted files are gone. Add -i to be asked before each deletion while you get used to it.
Viewing file contents
cat fileprints a whole file, which is handy for short files.less fileopens a long file one screen at a time. Use the arrow keys to scroll,/to search andqto quit.head -n 20 fileandtail -n 20 fileshow the first or last 20 lines.tail -f filekeeps printing new lines as they are added, which is useful for watching logs.
$ tail -f /var/log/syslog
Finding files with find
find searches a directory tree for files that match a name or other conditions.
$ find <directory> -name "<pattern>" # case-sensitive name match
$ find <directory> -iname "<pattern>" # case-insensitive name match
For example, to find every .log file under /var/log:
$ find /var/log -name "*.log"
A few more conditions you can combine with the name:
-type for-type dmatches only files or only directories.-mtime -7matches files modified in the last 7 days.-size +100Mmatches files larger than 100 MB.
$ find ~ -type f -size +100M
By default find does not follow symbolic links. To follow them, put -L before the directory: find -L /path -name "*.conf".
Searching text inside files with grep
grep prints every line that contains a piece of text.
$ grep "text" <file>
$ grep -r "text" <directory> # search every file under a directory
Example: find every mention of “TODO” in the current project, with line numbers.
$ grep -rn "TODO" .
./src/app.js:42:// TODO: handle empty response
Useful options:
-iignores case.-nshows the line number of each match.-llists only the names of files that match.-vinverts the match and shows lines that do not contain the text.-cprints the number of matching lines instead of the lines.-Eenables extended regular expressions, such asgrep -E "error|warning".
Pipes and redirection
Pipes and redirection let you combine commands and save their output.
command > filewrites the output to a file, replacing its contents.command >> fileappends the output to the end of a file.command1 | command2sends the output ofcommand1tocommand2as input.
$ ls -la /etc | grep ".conf"
$ dmesg | tail -n 50 > boot-messages.txt
Checking running processes
ps auxlists every running process.top(orhtop, if installed) shows a live view of processes sorted by CPU or memory use. Pressqto quit.kill <pid>asks a process to stop, using its process ID frompsortop.kill -9 <pid>forces a process to stop. Use it only when a normalkilldoesn’t work, because the program gets no chance to save its data.
$ ps aux | grep firefox
user 2345 2.3 4.1 ... firefox
$ kill 2345
Checking disk space
df -hshows free and used space on each mounted drive, in human-readable sizes.du -sh <directory>shows how much space a directory uses.
$ df -h /
$ du -sh ~/Downloads
File permissions and sudo
ls -l shows permissions as a 10-character string such as -rwxr-xr--. After the first character (the file type), the three groups of rwx are read, write and execute permissions for the owner, the group and everyone else.
chmod +x script.shmakes a file executable.chmod 755 filegives the owner read, write and execute access, and everyone else read and execute access.chown user:group filechanges the owner and group of a file.sudo <command>runs a single command with administrator (root) rights, for example to install software or edit system files.
$ chmod +x backup.sh
$ sudo chown www-data:www-data /var/www/site
Editing files with vi and vim
vi, or its improved version vim, is the editor you are most likely to find on any Linux server. It has two main modes:
- Normal mode is for moving around and running commands. vi starts in this mode.
- Insert mode is for typing text. Press
ito enter it andEscto return to normal mode.
Saving and quitting (type these in normal mode):
:wsaves the file.:qquits, and:q!quits without saving.:wqsaves and quits.
Moving around:
h,j,kandlmove left, down, up and right.wandbjump one word forward or back.0and$jump to the start or end of the line.Ggoes to the last line, andnGgoes to linen.
Editing:
iinserts text before the cursor, andaappends text after it.xdeletes the character under the cursor.dddeletes the current line.cwreplaces the rest of the word, andccreplaces the whole line.yycopies (yanks) the current line, andppastes after the cursor.uundoes the last change.
Searching and replacing:
/textsearches forward and?textsearches backward.nandNjump to the next or previous match.:s/old/new/replaces the first match on the current line.:%s/old/new/greplaces every match in the whole file.
If you’d prefer a more modern terminal app to run these commands in, Tabby is worth a look.
Next steps
Practise these commands on a test directory until they feel natural, and use man <command> whenever you need an option that isn’t listed here. To work with media and documents from the terminal, see our guides to FFmpeg commands, converting images with ImageMagick and reducing PDF file size with Ghostscript.