Common Commands
A reference for the Linux commands I use most. The command line feels like a lot to memorize at first, but you lean on a small core every day and look up the rest as needed.
Two habits make that lookup painless: almost every command supports --help for
a quick summary of its options, and most have a full manual page available with
man <command> (e.g. man ls).
Tip:
command --helpis great for a fast reminder of flags, whileman commandgives the complete documentation. Insideman, press/to search,nfor the next match, andqto quit.
Files and directories
ls- Lists files and folders in the current or a specified directory.ls- current directoryls Downloads- a relative pathls /usr/share/- an absolute pathHandy flags:
ls -l(long/detailed view),ls -a(include hidden dotfiles),ls -lh(human-readable sizes),ls -lt(sort by time, newest first),ls -lS(sort by size). They combine:ls -lah.
cd- Changes into a specified directory.cd Downloadsorcd /usr/sharecd ~(or justcd) returns to your home directory,cd -jumps back to the previous directory, andcd ..moves up one level.
pwd- Prints the full path of the directory you are currently in ("print working directory").tree- Shows a directory as an indented tree (install with your package manager).tree -L 2limits it to two levels deep.touch- Creates an empty file, or updates the timestamp of an existing one.touch hello-world.txt
mkdir- Makes a folder.mkdir HelloFoldermkdir -p a/b/ccreates the whole nested path, making parent folders as needed.
mv- Moves a file/folder; also used to rename.mv Hello.txt Documents/Hello.txt- movesHello.txtintoDocumentsmv Hello.txt Goodbye.txt- renamesHello.txttoGoodbye.txt
cp- Copies a file to a specified file/folder.cp Hello.txt Documents/- copiesHello.txtinto theDocumentsfoldercp Hello.txt Hello.txt.bak- makes aHello.txt.bakbackupcp -r MyFolder Documents/- copies a folder and everything inside it (recursive)
rm- Removes a file.rm Hello.txtrm -r MyFolderremoves a folder and its contents.rmis permanent - there is no recycle bin, so double-check paths, and be extremely careful withrm -rf(recursive + force, no prompts). Never runrm -rfwith a path you haven't read twice.
rmdir- Removes an empty directory (safer thanrm -rwhen you expect it to be empty - it refuses if it isn't).rmdir MyFolder
ln -s- Creates a symbolic link (a pointer to another file/folder), widely used for dotfiles and shared configs.ln -s /path/to/real/file linkname
Finding files
find- Walks the filesystem live, so results are always current (if slower).find . -name "Hello.txt"- by name, under the current directoryfind . -iname "*.pdf"- case-insensitive, with a wildcardfind /var/log -type f -mtime -1- files modified in the last dayfind . -name "*.tmp" -delete- find and delete matches
locate- Searches a prebuilt index for files by name (very fast).locate Hello.txtThe index is refreshed by
sudo updatedb, so a freshly created file may not appear until then. Provided by themlocate/plocatepackage;findis the slower-but-always-current alternative.
which/type- Show where a command comes from.which python3prints the executable's path;type llalso reveals aliases and shell builtins.
Viewing and inspecting files
cat- Concatenates file(s) to standard output (prints file contents). Best for short files.cat hello-world.txt
less- Opens a file in a scrollable pager - the right tool for long files. Navigate with arrows/PgUp/PgDn, search with/, quit withq.less /var/log/syslog
head/tail- Show the first/last lines of a file (10 by default).head -n 20 file.txt- first 20 linestail -n 50 file.txt- last 50 linestail -f logfile- follow a file, printing new lines as they're written (invaluable for watching logs live)
wc- Counts lines, words, and bytes.wc -l file.txtcounts lines.grep- Searches file(s) for keywords/patterns; often piped from another command.grep dog hello-world.txt- search a file directlycat hello-world.txt | grep dog- search piped inputSee SED, AWK, and Grep for a deeper dive into grep, sed, and awk.
Redirection, pipes, and wildcards
Small operators that combine commands are where the shell gets its power.
>- Redirects a command's output to a file, overwriting it if it exists.echo "Hello" > Hello.txt
>>- Appends a command's output to a file (creates it if missing).echo "Hello" >> Hello.txt
|- Pipe: sends the output of one command as the input of the next.cat Hello.txt | grep dog | wc -l- count matching lines
2>/&>- Redirect error output (2>) or both output and errors (&>).command > out.log 2> err.log- split normal output and errors
&&/||- Run the next command only if the previous succeeded (&&) or failed (||).mkdir build && cd build- onlycdif themkdirworked
Wildcards (globbing) - the shell expands these before running the command:
*matches any characters,?a single character, and[...]a set.ls *.txt,rm log_2025-0?.csv,cp img_[12].png backup/
Networking
ip- Shows or manipulates routing, devices, and tunnels. The modern, more powerful replacement forifconfig/route/arp.ip address(orip a) - show interfaces and IP addressesip route(orip r) - show the routing tableip neigh- show the ARP/neighbor cache
ifconfig- Interface config: shows IP address, name, MAC address, etc. Being phased out in favor ofip(it's in the oldernet-toolspackage, not installed by default on many modern distros).iwconfig- Likeifconfigbut for wireless interfaces (SSID, signal, etc.). The modern equivalent isiw.ssh- Secure Shell: remotely and securely connect to another machine.ssh user@ipssh -p 2222 user@host- use a non-default portPairs well with tmux on the remote host so your session survives a dropped connection.
scp/rsync- Copy files over SSH.rsync -av src/ user@host:dest/is the efficient choice for anything repeated - it only transfers what changed.ping host- Quick reachability test (is the host up and routable?).curl/wget- Fetch URLs from the command line.curl -O <url>downloads a file;wget <url>does the same with a simpler interface.Legacy tools you may still see:
route(useip route) andarp(useip neigh).
Processes and the system
ps aux- Snapshot of all running processes.top/htop- Live, interactive view of processes and resource use.htop(install separately) is friendlier - scroll, search, and kill from the UI.kill/killall- Stop a process.kill <PID>asks it to stop politely;kill -9 <PID>forces it;killall firefoxtargets by name.df -h- Free disk space per filesystem, human-readable.du -sh <dir>- Total size of a directory (-ssummarize,-hreadable).free -h- Memory usage.uname -a- Kernel and system info;lsb_release -ashows the distro version.
Services (systemd)
Most modern distros use systemd, managed with systemctl. The older
service command still works as a wrapper on many systems. Running these
usually requires sudo - see Permissions and sudo.
sudo systemctl start <service>- Start a service now.sudo systemctl start pcscd
sudo systemctl stop <service>- Stop a service now.sudo systemctl restart <service>- Restart it (e.g. after a config change).sudo systemctl enable <service>- Start the service automatically on boot.sudo systemctl enable --now pcscdenables and starts it in one step.
sudo systemctl disable <service>- Don't start the service on boot.systemctl status <service>- Show whether a service is running, plus recent logs. (Older equivalents:sudo service pcscd start/stop.)journalctl -u <service>- Read a service's full logs; add-fto follow them live, liketail -f.
Installing / updating / upgrading
How you install, update, and upgrade software depends on your distribution's
package manager. These commands change the whole system, so they need sudo -
see Permissions and sudo for why.
Debian-based distros (Ubuntu, Kubuntu, Mint, Kali, …)
sudo apt update- Refreshes the list of available packages from the repositories (does not install anything yet).sudo apt upgrade- Installs the newest versions of already-installed packages. Run it afterapt update.sudo apt install <package>- Installs a package.sudo apt install git-yauto-confirms prompts:sudo apt install -y git
sudo apt remove <package>- Removes a package (keeps its config files;sudo apt purge <package>removes those too).apt search <term>- Find a package by keyword.
Arch-based distros (Arch, Manjaro, …)
sudo pacman -S <package>- Installs a package (-S= sync).sudo pacman -Syu- Syncs the package database and upgrades the whole system (the standard way to update a rolling-release Arch box).sudo pacman -R <package>- Removes a package (-Rnsalso removes its dependencies and config).pacman -Ss <term>- Search for a package.
Fedora / RHEL-based distros
dnf is the modern tool; yum is the older name and still works on many
systems.
sudo dnf upgrade- Upgrades installed packages.sudo dnf install <package>- Installs a package.sudo dnf remove <package>- Removes a package.dnf search <term>- Search for a package.
For installing Python command-line tools specifically, prefer
pipxover the system package manager - see Python Pip Pipx Venv.
Aliases
Aliases are shortcuts for longer commands, and can even replace existing
commands. They live either in your shell's config file (.zshrc for Zsh,
.bashrc for Bash - the two most common shells) or in a dedicated alias file
(such as .bash_aliases). Add them there so they persist across new terminals,
then reload with source ~/.zshrc (or just open a new terminal). These config
files are themselves dotfiles worth versioning - see Linux General > Dotfiles.
Some examples:
alias upd='sudo apt update && sudo apt upgrade -y'- typeupdto refresh repositories and upgrade installed packages in one go, without being prompted.alias ffs='sudo $(fc -l -n -1)'- if you ran a command that neededsudo,ffsre-runs that last command withsudo("for... sake"). This is the alias version of the built-insudo !!(see Permissions and sudo > Handy sudo tips).alias ..='cd ..'- go up one directory.alias ...='cd ../..'- go up two directories.alias ll='ls -lah'- a detailed, human-readable listing including dotfiles.
To see what an alias expands to, run type <name> (e.g. type upd). To run a
command's original version, ignoring any alias, prefix it with a backslash:
\ls.
Related notes
Permissions and sudo - who can run what, and how to step up to root.
SED, AWK, and Grep - searching and transforming text in pipelines.
TMUX - keep these commands running in persistent sessions.
Linux - the hub for all of these notes.
Last updated