Common Linux Commands
Open a terminal and use this guide to find files, inspect their contents, and answer basic questions about your Linux system. The examples assume Bash on Linux. Replace sample paths with paths on your system when adapting a command.
Navigate directories
| Command | What it does |
|---|---|
pwd | Prints the full path to your current directory. |
ls -lah | Lists files with details, including hidden entries (-a) and readable sizes (-h, with -l). |
cd ~/Downloads | Opens the Downloads directory in your home directory, if it exists. |
cd .. | Moves up to the parent directory. |
cd - | Returns to your previous working directory. |
An absolute path starts at /, as in /etc/os-release. A relative path starts from your current directory, as in reports/today.txt. Quote paths that contain spaces, such as cd "Project Notes".
Create, copy, and rename files
mkdir reports
touch notes.txt
cp -i notes.txt notes-backup.txt
mv -i notes-backup.txt archived-notes.txt
mkdir creates a directory. touch creates an empty file or updates the timestamps on an existing file. cp copies a file, and mv moves or renames it. For both commands, -i prompts before overwriting an existing destination.
Use rm -i archived-notes.txt to prompt before removing a file. rm typically bypasses the desktop trash. Use rmdir reports to remove an empty directory.
Read and search text
cat app.log
less app.log
head -n 5 app.log
tail -n 5 app.log
grep -n 'ERROR' app.log
find . -type f -name '*.log'
catprints the whole file.lesslets you scroll through it. Pressqto exit.head -n 5andtail -n 5show the first and last five lines.grep -nprints each matching line with its line number. For example,2:ERROR disk fullshows a match on line 2.findsearches beneath the current directory (.).-type flimits results to regular files. Quoting'*.log'letsfindmatch the pattern in each directory it visits.
Use pipes and redirection
grep 'ERROR' app.log | wc -l
grep 'ERROR' app.log > errors.log
grep 'WARNING' app.log >> errors.log
The pipe (|) sends the matching lines to wc -l for counting. The > operator writes output to a file and replaces any existing contents. The >> operator appends output. Both operators create the destination file if it is missing.
Inspect and change permissions
id
ls -l notes.txt
chmod u=rw,go= notes.txt
id displays your user ID and group memberships. ls -l shows a file's permissions and ownership. The chmod example grants the owner read and write permissions and clears permissions for the group and others. Afterward, ls -l notes.txt shows permissions starting with -rw-------.
Check system resources
| Question | Command | What to look for |
|---|---|---|
| Which filesystem is running out of space? | df -h | The Use% column shows how full each mounted filesystem is. |
| How much space does this directory use? | du -sh . | A single human-readable total for the current directory. |
| How much memory can applications use? | free -h | The available column estimates how much RAM is available for new applications without swapping. |
| Which processes are active? | ps -ef | A snapshot with process IDs (PIDs) and command lines. |
| What is using CPU or memory right now? | top | A live view of processes and resource use. Press q to exit. |
| Which distribution am I running? | cat /etc/os-release | The distribution name and version. |
If you need to stop a process you own, identify its PID with ps -ef, then run kill PID with that number. The default signal, SIGTERM, requests that the process terminate and gives it a chance to clean up. Double-check the PID before sending the signal.
Check basic connectivity
| Command | What it tells you |
|---|---|
ip -brief address | Which interfaces are present and which IP addresses they have. |
ip route | Which routes the system knows about, including the default gateway when one is configured. |
ping -c 4 example.com | Whether the host responds to up to four ICMP echo requests. A firewall can block these requests while normal web traffic still works. |
curl -I https://example.com | The HTTP response headers, including the status code, if DNS resolution and the connection succeed. Some servers handle HEAD requests differently from GET requests. |
Find help and software
Use man ls to open the manual, ls --help for a short option summary, and help cd for Bash's built-in commands. Use command -v curl to see whether Bash can find curl. Minimal Linux installations may omit tools such as man, less, or curl.
Package tools vary by distribution. Try apt search curl on Ubuntu or Debian, dnf search curl on Fedora, or pacman -Ss curl on Arch Linux. These commands search package metadata. Installing or removing system packages modifies the machine and generally requires administrator privileges.