A clean, structured reference handbook for learning Linux commands step by step.
- File & Directory Management
- File Viewing & Editing
- File Searching
- Permissions & Ownership
- Process Management
- Networking
- Package Management
- Disk Management
- User Management
- Archiving & Compression
- System Information & Control
- Redirects, Pipes & Useful Tricks
pwdDisplays the full path of the current directory you are in.
$ pwd
/home/username/Documentsls [options] [directory]Lists files and folders in the current (or specified) directory.
ls # basic listing
ls -la # detailed list including hidden filescd [directory]Navigates to a specified directory.
cd /home/username/Documents # go to a specific path
cd .. # go one level up
cd ~ # go to home directorymkdir [options] directory_nameCreates a new directory.
mkdir projects # create a single folder
mkdir -p projects/web/css # create nested folders at oncermdir directory_nameDeletes an empty directory.
rmdir old_foldertouch filenameCreates a new empty file, or updates the timestamp of an existing one.
touch notes.txt
touch file1.txt file2.txt # create multiple files at oncecp [options] source destinationCopies a file or directory from one location to another.
cp report.txt backup/report.txt # copy a file
cp -r projects/ projects_backup/ # copy a directory recursivelymv [options] source destinationMoves a file/directory to a new location, or renames it.
mv old_name.txt new_name.txt # rename a file
mv report.txt /home/username/docs/ # move a file to another directoryrm [options] fileDeletes files or directories. Use with caution — this is irreversible.
rm unwanted.txt # delete a file
rm -rf old_project/ # forcefully delete a directory and its contentsln -s target link_nameCreates a symbolic (soft) link to a file or directory.
ln -s /usr/local/bin/python3 ~/mypy # create a shortcut to python3cat [options] filenamePrints the entire content of a file to the terminal.
cat notes.txt
cat file1.txt file2.txt # display multiple files in sequenceless filenameOpens a file for scrollable reading. Press q to quit, arrow keys to navigate.
less /var/log/sysloghead [options] filenameDisplays the first 10 lines of a file by default.
head access.log # first 10 lines
head -n 20 access.log # first 20 linestail [options] filenameDisplays the last 10 lines of a file. Useful for monitoring logs.
tail error.log # last 10 lines
tail -f /var/log/syslog # follow live log updates in real timenano filenameOpens a beginner-friendly terminal editor. Use Ctrl+O to save, Ctrl+X to exit.
nano config.txtvim filenameA powerful editor. Press i to enter insert mode, Esc then :wq to save and quit.
vim script.shwc [options] filenameCounts lines, words, and characters in a file.
wc -l report.txt # count lines only
wc -w essay.txt # count words onlyfind [path] [options] [expression]Searches for files and directories based on name, type, size, and more.
find /home -name "*.txt" # find all .txt files in /home
find . -type d -name "config" # find directories named "config"grep [options] pattern [file]Searches for a specific pattern (text or regex) within files.
grep "error" server.log # find lines containing "error"
grep -ri "todo" ~/projects/ # case-insensitive recursive searchlocate filenameSearches a pre-built database for files (much faster than find). Run sudo updatedb to refresh the database.
locate nginx.confwhich command_nameShows the full path of a command's executable.
which python3
which gitchmod [options] mode fileChanges read/write/execute permissions for a file or directory.
chmod 755 script.sh # rwx for owner, rx for group & others
chmod +x deploy.sh # add execute permission for everyonePermission reference:
| Number | Permission |
|---|---|
| 4 | Read (r) |
| 2 | Write (w) |
| 1 | Execute (x) |
chown [options] owner[:group] fileChanges the owner (and optionally the group) of a file or directory.
chown alice report.txt # change owner to alice
chown alice:developers project/ # change owner and groupchgrp group_name fileChanges only the group ownership of a file.
chgrp developers app.pyumask [mask]Displays or sets the default permission mask applied when new files are created.
umask # show current mask
umask 022 # set default: files get 644, dirs get 755ps [options]Shows a snapshot of currently running processes.
ps aux # show all running processes with details
ps aux | grep nginx # find a specific processtopDisplays a live, updating view of running processes and system resource usage. Press q to quit.
tophtopA more user-friendly, colorful alternative to top (may need to be installed).
htopkill [signal] PIDSends a signal to a process, usually to terminate it.
kill 1234 # gracefully stop process with PID 1234
kill -9 1234 # forcefully kill the processkillall process_nameKills all running processes with the specified name.
killall firefox
killall -9 nginxbg [job_id]
fg [job_id]bg resumes a suspended process in the background; fg brings it to the foreground.
bg %1 # resume job 1 in the background
fg %1 # bring job 1 to the foregroundjobsLists all jobs running in the background of the current shell session.
jobsnohup command &Runs a command immune to hangups, keeping it running even after you log out.
nohup python3 server.py &ping [options] hostSends ICMP packets to a host to check if it's reachable.
ping google.com
ping -c 4 192.168.1.1 # send exactly 4 packetscurl [options] URLFetches content from a URL. Useful for testing APIs and downloading files.
curl https://example.com
curl -O https://example.com/file.zip # download a filewget [options] URLDownloads files from the internet directly to your machine.
wget https://example.com/archive.tar.gz
wget -c https://example.com/bigfile.zip # resume a partial downloadifconfig
ip addr showDisplays or configures network interface settings (IP addresses, etc.).
ifconfig # show all network interfaces (older systems)
ip addr show # modern equivalentnetstat [options]Displays active network connections, ports, and routing tables.
netstat -tuln # show listening TCP/UDP ports
netstat -an | grep :80 # check if port 80 is in usessh [options] user@hostConnects to a remote machine securely over the network.
ssh alice@192.168.1.10
ssh -p 2222 alice@server.example.com # connect on a custom portscp source user@host:destinationCopies files between local and remote machines securely.
scp report.txt alice@192.168.1.10:/home/alice/
scp alice@192.168.1.10:/var/log/app.log ./local/ # download from remotenslookup domain
dig domainQueries DNS to resolve a domain name to an IP address.
nslookup google.com
dig openai.comsudo apt update # refresh package list
sudo apt upgrade # upgrade all installed packages
sudo apt install package # install a package
sudo apt remove package # uninstall a package
sudo apt search keyword # search for a packageExamples:
sudo apt update && sudo apt upgrade
sudo apt install git curl vimsudo dnf update # update all packages
sudo dnf install package # install a package
sudo dnf remove package # remove a package
sudo dnf search keyword # search packagesExamples:
sudo dnf install nginx
sudo dnf remove httpdsnap install package_name
snap remove package_name
snap listInstalls sandboxed, self-contained applications.
sudo snap install code --classic # install VS Code
snap list # list installed snapsdf [options]Shows disk space usage for all mounted filesystems.
df -h # human-readable sizes (KB, MB, GB)
df -h /home # check a specific partitiondu [options] [path]Shows how much disk space files or directories are using.
du -sh ~/Documents # total size of Documents folder
du -sh * | sort -h # list sizes sorted smallest to largestlsblkDisplays a tree of all storage devices and their partitions.
lsblk
lsblk -f # also show filesystem types and mount pointsmount device mountpoint
umount mountpointAttaches or detaches a storage device to the filesystem tree.
sudo mount /dev/sdb1 /mnt/usb
sudo umount /mnt/usbsudo fdisk -lLists all disk partitions. Use interactively to create/delete partitions.
sudo fdisk -l # list all partitions
sudo fdisk /dev/sdb # open partition editor for /dev/sdbwhoamiPrints the username of the currently logged-in user.
$ whoami
alicewhoLists all users currently logged into the system.
whoid [username]Displays the UID, GID, and group memberships of a user.
id
id alicesudo useradd [options] usernameCreates a new user account.
sudo useradd -m bob # create user with a home directory
sudo useradd -m -s /bin/bash carolpasswd [username]Sets or changes a user's password.
passwd # change your own password
sudo passwd bob # change another user's password (as root)sudo userdel [options] usernameRemoves a user account from the system.
sudo userdel bob # remove user only
sudo userdel -r bob # remove user and their home directorysudo usermod [options] usernameModifies an existing user's properties.
sudo usermod -aG sudo alice # add alice to the sudo group
sudo usermod -l newname oldname # rename a usergroups [username]Lists all groups a user belongs to.
groups
groups alicesudo commandRuns a command with administrator (root) privileges.
sudo apt update
sudo nano /etc/hoststar [options] archive_name filesCreates or extracts .tar archives. Commonly combined with compression flags.
tar -czvf archive.tar.gz folder/ # create a compressed archive
tar -xzvf archive.tar.gz # extract a compressed archive
tar -tzvf archive.tar.gz # list contents without extractingFlag reference:
| Flag | Meaning |
|---|---|
-c |
Create archive |
-x |
Extract archive |
-z |
Use gzip compression |
-j |
Use bzip2 compression |
-v |
Verbose (show progress) |
-f |
Specify filename |
gzip filename
gunzip filename.gzCompresses a file into .gz format, or decompresses it.
gzip report.txt # creates report.txt.gz
gunzip report.txt.gz # restores report.txtzip archive.zip file1 file2
unzip archive.zipCreates or extracts .zip archives.
zip -r project.zip project/ # zip a folder recursively
unzip project.zip -d /tmp/output/ # extract to a specific directoryuname [options]Displays system and kernel information.
uname -a # all system info (kernel, architecture, hostname)
uname -r # kernel version onlyuptimeShows how long the system has been running, and the current load average.
uptimefree [options]Displays total, used, and free RAM and swap memory.
free -h # human-readable formathistory [n]Lists previously entered commands. Use !number to re-run a command.
history # show full history
history 20 # show last 20 commands
!42 # re-run command number 42date [options]Displays the current date and time, or sets it.
date
date "+%Y-%m-%d %H:%M:%S" # custom formatsudo reboot
sudo shutdown [options] [time]Reboots or shuts down the system.
sudo reboot
sudo shutdown -h now # shut down immediately
sudo shutdown -r +5 # reboot in 5 minutessystemctl [command] service_nameControls systemd services (start, stop, restart, enable on boot, etc.).
sudo systemctl start nginx # start the nginx service
sudo systemctl stop nginx # stop it
sudo systemctl restart nginx # restart it
sudo systemctl enable nginx # start on boot
sudo systemctl status nginx # check its statusjournalctl [options]Queries and displays logs from the systemd journal.
journalctl -u nginx # logs for the nginx service
journalctl -f # follow live log output
journalctl --since "1 hour ago" # recent logsalias name='command'Creates a shortcut for a longer command. Add it to ~/.bashrc to make it permanent.
alias ll='ls -la'
alias update='sudo apt update && sudo apt upgrade'Sends the output of one command as input to another.
ls -la | less # scroll through a long listing
ps aux | grep python # filter process list
cat access.log | grep "404" # find 404 errors in a log> overwrites a file; >> appends to it.
echo "Hello World" > hello.txt # write (overwrite)
echo "Another line" >> hello.txt # append
ls -la > file_list.txt # save directory listing to fileFeeds a file's contents as input to a command.
sort < names.txt
wc -l < report.txtRedirects standard error (stderr) to a file separately from normal output.
command 2> errors.log # save errors only
command > output.log 2>&1 # save both output and errors to one file&& runs the next command only if the previous one succeeded. || runs it only if the previous one failed.
sudo apt update && sudo apt upgrade # upgrade only if update succeeds
mkdir newdir && cd newdir # create dir and enter it
ping -c1 google.com || echo "No internet"command | xargs another_commandTakes output from one command and passes it as arguments to another.
find . -name "*.log" | xargs rm # delete all found .log files
cat urls.txt | xargs wget # download all URLs in a filecommand | tee filenameWrites output to both the terminal and a file at the same time.
ls -la | tee directory_listing.txt
ping google.com | tee ping_results.txtclearClears all text from the terminal window. Shortcut: Ctrl + L.
man command_nameOpens the official manual/documentation for any Linux command. Press q to quit.
man ls
man grep
man chmod| Category | Key Commands |
|---|---|
| Navigation | pwd, ls, cd, tree |
| Files | touch, cp, mv, rm, mkdir, rmdir |
| Viewing | cat, less, head, tail, wc |
| Searching | find, grep, locate, which |
| Permissions | chmod, chown, chgrp, umask |
| Processes | ps, top, kill, jobs, bg, fg |
| Networking | ping, curl, wget, ssh, scp |
| Packages | apt, dnf, snap |
| Disk | df, du, lsblk, mount |
| Users | whoami, useradd, passwd, sudo, usermod |
| Archiving | tar, gzip, zip, unzip |
| System | uname, uptime, free, systemctl, history |
| Shell Tricks | |, >, >>, &&, man, alias |
💡 Tip: When in doubt, use
man <command>orcommand --helpto explore options for any Linux command.
Guide level: Beginner → Intermediate | Best used as a study and daily reference.