- Basic Commands
- File Viewing & Editing
- Search & Filter
- File Permissions
- User & Group Management
- Process Management
- Disk Usage & Storage
- Package Management
- Networking
- System Information
- Text Processing
- Compression & Archiving
Basic Commands
Command | Description | Real-World Example |
---|---|---|
pwd | Print the current working directory | Input: pwd Output: /home/user |
ls |
List files and directories in the current location |
Input: ls Output: Documents Downloads file.txt |
cd |
Change the current directory |
Input: cd Documents Output: (no output, just changes to Documents directory) |
cp |
Copy files or directories |
Input: cp file.txt copy.txt Output: (copy.txt created with same content as file.txt) |
mv |
Move or rename files or directories |
Input: mv copy.txt archive/ Output: (copy.txt moved to archive/ directory) |
rm |
Remove files or directories |
Input: rm file.txt Output: (file.txt deleted) |
touch |
Create a new empty file or update timestamp |
Input: touch newfile.txt Output: (newfile.txt created) |
mkdir |
Create a new directory |
Input: mkdir new_folder Output: (new_folder created) |
rmdir |
Remove an empty directory |
Input: rmdir old_folder Output: (old_folder deleted if empty) |
File Viewing & Editing
Command | Description | Real-World Example |
---|---|---|
cat file.txt |
Displays the full content of a file |
Input: cat file.txt Output: Hello world! This is the file content. |
less file.txt | View file content with scroll (page by page) | Input: less file.txt Output: (Shows file in pager; use ↑ ↓ to scroll, q to quit) |
more file.txt | View file content page-by-page (simpler than less) | Input: more file.txt Output: (Displays first page; press space for next) |
head file.txt | Display the first 10 lines of a file | Input: head file.txt Output: Line 1 Line 2 ... Line 10 |
tail file.txt | Display the last 10 lines of a file | Input: tail file.txt Output: Line 91 ... Line 100 |
nano file.txt | Open file in nano text editor (simple and beginner-friendly) | Input: nano file.txt Output: (Opens nano editor; use Ctrl+X to exit) |
vim file.txt | Open file in Vim editor (advanced and powerful) | Input: vim file.txt Output: (Opens file in Vim; press i to edit, :wq to save and quit) |
Search & Filter
Command | Description | Real-World Example |
---|---|---|
grep "hello" file.txt | Search for the word "hello" in file.txt | Input: grep "hello" file.txt Output: hello world, this is a test |
find / -name file.txt |
Search for a file named "file.txt" starting at root |
Input: find / -name file.txt Output: /home/user/Documents/file.txt |
locate file.txt |
Quickly find file using a prebuilt database |
Input: locate file.txt Output: /home/user/Documents/file.txt |
which python |
Show the path of the python executable |
Input: which python Output: /usr/bin/python |
whereis python |
Locate the binary, source, and man pages for a command |
Input: whereis python Output: python: /usr/bin/python /usr/share/man/man1/python.1.gz |
echo 'file1 file2' | xargs rm |
Run rm on each word passed via pipe |
Input: echo 'file1 file2' | xargs rm Output: (file1 and file2 deleted if they exist) |
File Permissions
Command | Description | Real-World Example |
---|---|---|
chmod 755 script.sh |
Change file permissions (rwxr-xr-x) |
Input: chmod 755 script.sh Output: (script.sh is now executable by owner, readable/executable by others) |
chown user:group file.txt | Change the owner and group of a file | Input: chown alice:devs file.txt Output: (Ownership of file.txt changed to alice:devs) |
chgrp devs file.txt | Change group ownership of a file | Input: chgrp devs file.txt Output: (Group of file.txt changed to devs) |
umask | Show or set default permissions for new files | Input: umask Output: 0022 |
umask 0007 | Set new default permissions (restricts access for others) | Input: umask 0007 Output: (New files will default to 770 permissions) |
User & Group Management
Command | Description | Real-World Example |
---|---|---|
adduser alice | Add a new user named "alice" | Input: sudo adduser alice Output: Adding user `alice' ... |
userdel alice | Delete an existing user | Input: sudo userdel alice Output: (User alice deleted) |
usermod -aG sudo alice | Add user to the "sudo" group | Input: sudo usermod -aG sudo alice Output: (alice can now use sudo) |
passwd alice | Change the password for user "alice" | Input: sudo passwd alice Output: Enter new UNIX password: |
groupadd devs | Create a new group named "devs" | Input: sudo groupadd devs Output: (Group devs created) |
groups alice | List all groups the user "alice" belongs to | Input: groups alice Output: alice : alice sudo devs |
id alice | Display user ID, group ID, and group memberships | Input: id alice Output: uid=1001(alice) gid=1001(alice) groups=1001(alice),27(sudo),1002(devs) |
whoami | Print the current user’s username | Input: whoami Output: alice |
Process Management
Command | Description | Real-World Example |
---|---|---|
ps aux | Display a snapshot of all running processes | Input: ps aux Output: USER PID %CPU %MEM COMMAND alice 1234 0.0 0.1 bash |
top | Real-time display of running processes | Input: top Output: (Live list of processes; press q to quit) |
htop | Interactive process viewer (enhanced top) | Input: htop Output: (Colorful, interactive process viewer) |
kill 1234 | Terminate a process by PID | Input: kill 1234 Output: (Process with PID 1234 is terminated) |
killall firefox | Kill all processes by name | Input: killall firefox Output: (All firefox processes terminated) |
nice -n 10 myscript.sh | Start a process with lower priority | Input: nice -n 10 ./myscript.sh Output: (myscript.sh runs with niceness 10) |
renice -n -5 -p 1234 | Change the priority of an existing process | Input: renice -n -5 -p 1234 Output: 1234 (process priority changed to -5) |
jobs | List background jobs in current shell | Input: jobs Output: [1]+ Running ./script.sh & |
fg %1 | Bring background job to foreground | Input: fg %1 Output: (Brings job [1] to foreground) |
bg %1 | Resume a suspended job in background | Input: bg %1 Output: (Job [1] resumes in background) |
Disk Usage & Storage
Command | Description | Real-World Example |
---|---|---|
df -h | Show disk space usage in human-readable format | Input: df -h Output: Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 20G 28G 42% / |
du -sh /home/alice | Show total size of a directory | Input: du -sh /home/alice Output: 2.1G /home/alice |
mount /dev/sdb1 /mnt | Mount a device to a directory | Input: sudo mount /dev/sdb1 /mnt Output: (Device mounted to /mnt) |
umount /mnt | Unmount a mounted device | Input: sudo umount /mnt Output: (Device unmounted from /mnt) |
lsblk | List block devices | Input: lsblk Output: NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk / |
blkid | Show UUID and type of block devices | Input: sudo blkid Output: /dev/sda1: UUID="abcd-1234" TYPE="ext4" |
fdisk -l | List all partitions on all disks | Input: sudo fdisk -l Output: Disk /dev/sda: 50 GiB Device Boot Start End Sectors Size Id Type /dev/sda1 2048 ... |
parted /dev/sda | Interactive tool to manage partitions | Input: sudo parted /dev/sda Output: (parted prompt appears for interactive use) |
Package Management
Command | Description | Real-World Example |
---|---|---|
apt update | Update package index | Input: sudo apt update Output: Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease |
apt install nginx | Install a package | Input: sudo apt install nginx Output: The following packages will be installed: nginx |
dpkg -i package.deb | Install a .deb package manually | Input: sudo dpkg -i package.deb Output: Unpacking package.deb ... |
yum install httpd | Install a package using YUM (older Red Hat/Fedora) | Input: sudo yum install httpd Output: Installed: httpd.x86_64 |
dnf update | Update all packages (Fedora/RHEL 8+) | Input: sudo dnf update Output: Dependencies resolved. Upgraded: ... |
rpm -i package.rpm | Install an RPM package manually | Input: sudo rpm -i package.rpm Output: Preparing... ################################# [100%] |
pacman -Syu | Update system and upgrade packages (Arch Linux) | Input: sudo pacman -Syu Output: :: Synchronizing package databases... |
pacman -S firefox | Install a package on Arch-based systems | Input: sudo pacman -S firefox Output: resolving dependencies... |
Networking
Command | Description | Real-World Example |
---|---|---|
ip a | Display IP address and network interfaces | Input: ip a Output: inet 192.168.1.10/24 brd 192.168.1.255 ... |
ifconfig | Show or configure a network interface (older tool) | Input: ifconfig Output: eth0: inet 192.168.1.10 netmask 255.255.255.0 |
ping google.com | Send ICMP packets to test connectivity | Input: ping google.com Output: 64 bytes from google.com: icmp_seq=1 ttl=117 time=22 ms |
netstat -tuln | List all listening ports and connections | Input: netstat -tuln Output: tcp 0.0.0.0:22 LISTEN |
ss -tuln | Faster and more detailed alternative to netstat | Input: ss -tuln Output: LISTEN 0 128 0.0.0.0:22 |
curl https://example.com | Transfer data from or to a server (shows content) | Input: curl https://example.com Output: <html>...</html> |
wget https://example.com/file.txt | Download files from the web | Input: wget https://example.com/file.txt Output: Saving to: ‘file.txt’ |
scp file.txt user@192.168.1.5:/home/user/ | Securely copy a file to another system | Input: scp file.txt user@192.168.1.5:/home/user/ Output: file.txt 100% 12KB 150.0KB/s 00:00 |
rsync -av file.txt user@192.168.1.5:/home/user/ | Sync files/directories between systems | Input: rsync -av file.txt user@192.168.1.5:/home/user/ Output: sending incremental file list |
ssh user@192.168.1.5 | Securely log into a remote machine | Input: ssh user@192.168.1.5 Output: Welcome to Ubuntu 22.04 LTS |
System Information
Command | Description | Real-World Example |
---|---|---|
uname -a | Display all system information (kernel, architecture, etc.) | Input: uname -a Output: Linux myhost 5.15.0-84-generic #1 SMP ... x86_64 GNU/Linux |
hostname | Show the system's hostname | Input: hostname Output: myhost |
uptime | Shows how long the system has been running | Input: uptime Output: 14:03:26 up 3 days, 2:17, 2 users, load average: 0.16, 0.09, 0.07 |
free -h | Display memory usage (human-readable) | Input: free -h Output: Mem: 7.7Gi 2.1Gi 3.4Gi ... |
vmstat | Report system performance (memory, CPU, I/O) | Input: vmstat Output: procs -----------memory---------- ---swap-- ... |
lscpu | Display CPU architecture information | Input: lscpu Output: Architecture: x86_64 CPU(s): 4 |
lsmem | Show memory block information | Input: sudo lsmem Output: RANGE SIZE STATE ... 0x0000000000000000-0x000000007fffffff 2G online |
dmesg | View kernel ring buffer (boot and hardware messages) | Input: dmesg | tail Output: [ 12.123456] eth0: link up |
Text Processing
Command | Description | Real-World Example |
---|---|---|
awk '{print $1}' file.txt | Print the first column of a file or input stream | Input: awk '{print $1}' employees.txt Output: John Alice |
sed 's/foo/bar/g' file.txt | Replace all occurrences of "foo" with "bar" | Input: sed 's/foo/bar/g' notes.txt Output: bar is a placeholder text |
cut -d',' -f1 names.csv | Cut and show the first field (using comma as delimiter) | Input: cut -d',' -f1 names.csv Output: John Alice |
sort names.txt | Sort lines alphabetically | Input: sort names.txt Output: Alice John Mike |
uniq sorted.txt | Remove duplicate adjacent lines | Input: uniq sorted.txt Output: Alice John |
tr 'a-z' 'A-Z' | Translate lowercase to uppercase | Input: echo "hello" | tr 'a-z' 'A-Z' Output: HELLO |
wc -l file.txt | Count the number of lines in a file | Input: wc -l notes.txt Output: 42 notes.txt |
tee output.txt | Read from input and write to a file and stdout | Input: echo "Log entry" | tee log.txt Output: Log entry (and writes to log.txt) |
split -l 10 large.txt | Split a file into pieces with 10 lines each | Input: split -l 10 large.txt Output: xaa, xab, xac... |
paste file1 file2 | Merge lines from two files side-by-side | Input: paste names.txt ages.txt Output: Alice 25 John 30 |
Compression & Archiving
Command | Description | Real-World Example |
---|---|---|
tar -cvf archive.tar file1 file2 | Create a tar archive | Input: tar -cvf archive.tar file1.txt file2.txt Output: file1.txt file2.txt |
tar -xvf archive.tar | Extract files from a tar archive | Input: tar -xvf archive.tar Output: file1.txt file2.txt |
gzip file.txt | Compress a file using gzip | Input: gzip report.txt Output: Creates report.txt.gz |
gunzip file.txt.gz | Decompress a .gz file | Input: gunzip report.txt.gz Output: Extracts report.txt |
bzip2 file.txt | Compress file using bzip2 | Input: bzip2 data.txt Output: Creates data.txt.bz2 |
xz file.txt | Compress file using xz | Input: xz manual.txt Output: Creates manual.txt.xz |
zip archive.zip file1 file2 | Create a zip archive | Input: zip archive.zip file1.txt file2.txt Output: adding: file1.txt adding: file2.txt |
unzip archive.zip | Extract a zip archive | Input: unzip archive.zip Output: extracting: file1.txt extracting: file2.txt |