Learning Linux commands is one of the quickest ways to become comfortable with a Linux server, desktop distribution, virtual machine, or container. The terminal gives you precise control over files, processes, services, permissions, networking, and system resources without relying on a graphical interface.
This guide explains 30 practical commands with safe examples, expected results, and troubleshooting notes. Most examples work on common GNU/Linux distributions, including Ubuntu, Debian, Fedora, Rocky Linux, AlmaLinux, and openSUSE. Some options differ between distributions, so check a command’s local manual page with man command when in doubt.
30 Linux commands: quick reference
| Command | Typical purpose |
|---|---|
ssh |
Connect securely to a remote host |
mkdir, touch |
Create directories and files |
ls, pwd, cd |
List, identify, and change locations |
rm, mv, cp |
Remove, move, and copy files |
vi, vim, nano |
Edit text files |
cat, grep, wc |
Read, search, and count text |
zip, unzip, tar |
Compress and archive data |
ps, top, kill |
Inspect and control processes |
systemctl |
Manage system services |
df, du |
Check disk space and directory size |
chmod, chown, passwd |
Manage permissions, ownership, and passwords |
netstat, ifconfig, wget |
Inspect networking and download files |
find, history |
Locate files and review previous commands |
These Linux commands are useful on a local terminal and during remote administration. Before running a command, confirm your current directory with pwd, inspect the target with ls, and avoid using sudo unless elevated privileges are necessary.
Linux commands for navigation and file management
1. ssh: connect to a remote Linux host
ssh means Secure Shell. It opens an encrypted remote terminal session using the SSH protocol. Replace the example account and address with values supplied by your administrator or hosting provider.
ssh username@hostname
ssh [email protected]
Use exit or press Ctrl+D to close the session. If the connection fails, verify the hostname, port, credentials, firewall rules, and whether the SSH service is running. Do not paste passwords into scripts or expose private keys.
2. mkdir: create directories
mkdir creates a directory. The -p option also creates missing parent directories and avoids an error when the target already exists.
mkdir adminhint
mkdir -p adminhint/firstdir/secdir
Check the result with ls -la adminhint. Use quotes around paths containing spaces, such as mkdir "Project Files".
3. touch: create a file or update its timestamp
touch creates an empty file when the file does not exist. If it already exists, it updates its modification timestamp without changing the contents.
touch notes.txt
Use ls -l notes.txt to verify the file and its timestamp.
4. ls: list files and directories
ls displays directory contents. Long and hidden-file views are especially useful when investigating permissions or configuration files.
ls
ls -la
ls -lh
The -l option shows detailed metadata, -a includes hidden entries, and -h uses readable size units. A directory listing does not prove that a file can be opened; permissions still apply.
5. cd: change directory
cd changes the current working directory. An absolute path starts at the filesystem root, while a relative path starts from your current location.
cd /var/log
cd ..
cd ~
cd -
.. moves to the parent directory, ~ moves to your home directory, and - returns to the previous location. Run pwd if you are unsure where you are.
6. pwd: print the current directory
pwd prints the absolute path of the current working directory. It is a useful safety check before moving or deleting files.
pwd
7. cp: copy files and directories
cp copies a file. To copy a directory and its contents, use -r. The options -v and -p provide progress output and preserve suitable metadata.
cp report.txt report-backup.txt
cp -r source-directory destination-directory
cp -rvp source destination
Check the destination with ls -l. Be careful: copying to an existing filename can overwrite it. Create a backup or use an interactive option such as cp -i when appropriate.
8. mv: move or rename files
mv moves files and directories or renames them when the destination is in the same directory.
mv oldname.txt newname.txt
mv report.txt /tmp/report.txt
Use mv -i to request confirmation before overwriting an existing destination.
9. rm: remove files and directories
rm permanently removes directory entries; it normally does not move them to a recycle bin. Start with a single file and confirm the path before using recursive options.
rm unwanted.txt
rm -r old-directory
rm -i important-file.txt
-r removes a directory tree, while -f suppresses prompts and many errors. Avoid commands such as rm -rf unless you have carefully verified the complete path. There is usually no simple rollback, so maintain backups and use ls first.
10. vi, vim, and nano: edit text files
vi, vim, and nano are terminal editors. nano is often easier for beginners, while Vim provides modal editing and is commonly available on servers.
nano filename
vim filename
In Nano, press Ctrl+O to write the file and Ctrl+X to exit. In Vim, press Esc, type :wq, and press Enter to save and exit. Use :q! to exit Vim without saving. Before changing a service configuration, make a backup with cp file file.bak.
Text processing and command line basics
11. cat: display or combine text
cat prints file contents to standard output and can combine files. For long files, less is usually easier to read, but cat is convenient for short configuration or text files.
cat filename
cat file1 file2 > combined.txt
cat *.txt > all-text.txt
The > operator replaces the destination file. Use >> to append instead, and confirm the destination before redirecting output.
12. grep: search text
grep searches for matching text in one or more files. Common options include -i for case-insensitive matching, -n for line numbers, and -r for recursive searches.
grep -n "error" application.log
grep -ri "server_name" /etc/nginx
If a search returns no output, the pattern may not match or the user may not have permission to read the file.
13. wc: count lines, words, and characters
wc counts content in a file or stream. Use -l for lines, -w for words, and -m for characters.
wc -l access.log
wc -w document.txt
wc -m document.txt
With no option, wc reports lines, words, and bytes or characters depending on the platform and options used.
Archives and downloads
14. zip and 15. unzip: work with ZIP archives
zip creates a ZIP archive and unzip extracts one. ZIP files are convenient for exchanging files across Linux, Windows, and macOS systems.
zip -r project.zip project-directory
unzip project.zip
unzip -l project.zip
The final command lists archive contents without extracting them. Review filenames before extraction, particularly when an archive comes from an untrusted source.
16. tar: create and extract archives
tar packages files into an archive. Compression is added with options such as -z for gzip or -J for xz.
tar -cvf project.tar project-directory
tar -xvf project.tar
tar -czf project.tar.gz project-directory
tar -tzf project.tar.gz
Here, c creates, x extracts, t lists, v shows activity, and f identifies the archive file. List an archive before extraction to avoid unexpected paths or overwrites.
17. wget: download a resource
wget downloads content from a URL. Use an HTTPS URL where available and verify the source before executing downloaded software.
wget https://example.org/archive.tar.gz
wget -O saved-name.tar.gz https://example.org/archive.tar.gz
Check the exit status and downloaded file with ls -lh. A successful download does not prove that the file is authentic or safe.
Process management and system services
18. ps: inspect running processes
ps displays processes associated with the current session or system. A portable starting point is ps aux; on some systems, ps -ef is also common.
ps aux
ps aux | grep nginx
Look for the process ID, or PID, before taking action. The second example may also match the search command itself.
19. top: monitor CPU and memory activity
top provides a live view of processes, CPU use, memory use, and system load.
top
top -c
The -c option displays full command lines on implementations that support it. Press q to quit. High usage is a symptom, not automatically a fault; check logs and the process identity before stopping anything.
20. kill: send a signal to a process
kill sends a signal to a process by PID. Start with the default termination signal, which allows a program to close cleanly.
kill 1234
kill -TERM 1234
kill -KILL 1234
Use the forceful KILL signal only when a process will not terminate normally. It prevents cleanup and can cause data loss. Confirm the PID with ps immediately before acting.
21. systemctl: manage services
systemctl manages services on systems using systemd. The older service command may still exist as a compatibility interface, but systemctl is the usual interface on modern systemd distributions.
systemctl status service-name
sudo systemctl start service-name
sudo systemctl restart service-name
sudo systemctl enable service-name
Use stop to stop a service and disable to prevent it starting automatically. After a change, run systemctl status service-name and inspect logs with journalctl -u service-name. Restarting a production service can interrupt users, so schedule changes carefully and retain a configuration backup.
Disk space and network troubleshooting
22. df: check filesystem space
df reports used and available space on mounted filesystems. The human-readable option is useful for quick diagnosis.
df -h
df -h /var
If a filesystem is full, identify large directories with du. Do not delete unknown system files simply to recover space.
23. du: measure directory usage
du estimates the space used by files and directories. Use -s for a summary and -h for readable units.
du -sh /var/log
du -h --max-depth=1 /home
Options vary slightly between implementations. The -h option means human-readable; it does not show modification dates. Compare du with df when totals appear different because open-but-deleted files, reserved space, or mount points can affect results.
24. netstat: inspect network sockets
netstat can show listening ports and active connections when the package is installed. The options below request TCP, UDP, numeric, program, and listening information.
netstat -tunpl
Many modern distributions prefer ss, for example ss -tuln. If netstat is unavailable, use the distribution’s package documentation or the newer tool. Check both local firewall rules and the service configuration when a port is unreachable.
25. ifconfig: view network interfaces
ifconfig displays interface addresses and status on systems that provide the legacy net-tools package.
ifconfig
On current distributions, ip address is generally preferred. If an interface is missing an address, check the network manager, DHCP configuration, cable or virtual network, and firewall settings.
File permissions and account security
26. chmod: change permissions
chmod changes read, write, and execute permissions for the owner, group, and others. Numeric permissions use read as 4, write as 2, and execute as 1.
chmod 644 file.txt
chmod 755 script.sh
For 644, the owner can read and write, while the group and others can read. For 755, the owner can read, write, and execute, while the group and others can read and execute. Avoid making sensitive files world-writable.
27. chown: change ownership
chown changes the owner and optionally the group of a file or directory.
sudo chown user:group file.txt
sudo chown -R user:group project-directory
Use recursive ownership changes carefully. A wrong owner can prevent a service from reading its configuration or expose private data. Validate with ls -l.
28. passwd: change a password
passwd changes the current user’s password. An administrator may specify another account when permitted by the system’s access policy.
passwd
sudo passwd username
Follow your organisation’s password and multi-factor authentication policies. Never include a password in a command line, shell history, ticket, or script.
Finding files and reviewing command history
29. find: locate files
find searches a directory tree using names, types, times, sizes, permissions, and other conditions.
find /var/log -name "*.log"
find /home -type f -name "report.txt"
find . -type f -mtime -7
Start with a narrow search path to reduce noise. Be cautious with actions such as -delete; first run the search without an action and review the results.
30. history: review previous commands
history lists commands stored by the shell. It can help you repeat a safe command or investigate what changed during a session.
history
history 20
!!
Shell history may contain sensitive paths, tokens, or accidentally entered secrets. Review and remove sensitive entries according to your shell’s documentation. History is not a substitute for change records or backups.
How to practise Linux commands safely
Use a non-production virtual machine, container, or test directory while learning. Begin with read-only commands such as pwd, ls, df, and ps. Before changing data, record the original state, make a backup, and test the smallest possible command.
- Confirm the current user and directory before administrative work.
- Use absolute paths when a command could affect important files.
- Read the manual page and verify option meanings on your distribution.
- Check command output and exit status after each significant change.
- Keep a rollback plan, such as a configuration backup or tested restore point.
- Do not copy commands blindly from an unknown source, especially commands involving
sudo, downloads, permissions, or recursive deletion.
Once these Linux commands become familiar, combine them with pipes and redirection to build useful workflows, such as searching logs with grep, counting matches with wc, and saving results to a file. For service monitoring and web-server administration, continue with the related AdminHint guides below.
Related guides
Conclusion
These Linux commands cover the everyday tasks most beginners and administrators encounter: moving around the filesystem, editing text, managing archives, inspecting processes, checking storage, troubleshooting networks, and controlling permissions. Practise them deliberately, validate results, and protect important data with backups before making destructive changes.

