Linux Commands

This article is a practical reference for essential Linux commands, particularly useful for users transitioning from Windows. Linux's command-line interface (CLI) is its greatest strength: most system administration, development, and automation tasks can be accomplished efficiently through the terminal. While the graphical desktop has improved greatly, the CLI remains the preferred tool for developers, system administrators, and power users.

Commands are organized by category with brief explanations and practical examples. For pipes, redirection, and combining commands, see the dedicated section below.

File System Navigation

Linux uses a single unified file system tree rooted at /, unlike Windows with its drive letters (C:, D:).

CommandPurposeExample
pwdPrint working (current) directorypwd/home/alice
cdChange directorycd /var/log
cd ..Move up one directorycd ..
cd ~Go to home directorycd ~ (or just cd)
cd -Go to previous directorycd -
lsList directory contentsls -la /etc
ls -lLong format with permissions, sizesls -l *.txt
ls -aShow hidden files (starting with .)ls -a ~
findSearch for files by name, type, date, etc.find /home -name "*.pdf" -type f
locateFast file search using a pre-built indexlocate wikantik.properties
treeDisplay directory tree structuretree -L 2 /var

Key differences from Windows:

File Operations

CommandPurposeExample
cpCopy files or directoriescp file.txt backup/
cp -rCopy directories recursivelycp -r project/ project_backup/
mvMove or rename filesmv old_name.txt new_name.txt
rmRemove filesrm unwanted.txt
rm -rRemove directories recursivelyrm -r old_directory/
rm -iRemove with confirmation promptrm -i important.txt
mkdirCreate a directorymkdir new_project
mkdir -pCreate nested directoriesmkdir -p src/main/java
touchCreate an empty file or update timestamptouch newfile.txt
chmodChange file permissionschmod 755 script.sh
chownChange file ownershipchown alice:developers file.txt
ln -sCreate a symbolic linkln -s /usr/bin/python3 /usr/bin/python

Permissions

Linux file permissions use three groups (owner, group, others) and three types (read, write, execute):

-rwxr-xr-- 1 alice developers 4096 Jan 15 10:30 script.sh
│├─┤├─┤├─┤
│ │   │  └── Others: read only (4)
│ │   └───── Group: read + execute (5)
│ └───────── Owner: read + write + execute (7)
└──────────── File type (- = regular file, d = directory, l = link)

Numeric notation: read=4, write=2, execute=1. So chmod 755 means owner=rwx(7), group=r-x(5), others=r-x(5).

Text Processing

Text processing is where Linux truly excels. These commands form a powerful toolkit for analyzing and transforming text data.

CommandPurposeExample
catDisplay entire file contentscat config.txt
lessView file with scrolling (q to quit)less /var/log/syslog
headShow first N lines (default 10)head -20 logfile.txt
tailShow last N linestail -50 error.log
tail -fFollow a file in real timetail -f /var/log/syslog
grepSearch for patterns in textgrep "ERROR" app.log
grep -rSearch recursively in directoriesgrep -r "TODO" src/
grep -iCase-insensitive searchgrep -i "warning" output.txt
grep -cCount matching linesgrep -c "404" access.log
sedStream editor for text substitutionsed 's/old/new/g' file.txt
awkPattern scanning and processingawk '{print \$1, \$3}' data.txt
wcCount lines, words, characterswc -l file.txt
sortSort linessort -n numbers.txt
uniqRemove adjacent duplicatessort names.txt \| uniq -c
cutExtract columns from textcut -d',' -f2 data.csv
trTranslate or delete charactersecho "HELLO" \| tr 'A-Z' 'a-z'
diffCompare two filesdiff file1.txt file2.txt

Practical Examples

Count unique IP addresses in an access log:

awk '{print \$1}' access.log | sort | uniq -c | sort -rn | head -10

Replace all occurrences of a string in multiple files:

find . -name "*.java" -exec sed -i 's/oldMethod/newMethod/g' {} +

Extract the third column from a CSV, sorted and deduplicated:

cut -d',' -f3 data.csv | sort -u

Process Management

CommandPurposeExample
psShow running processesps aux
ps auxDetailed list of all processesps aux \| grep java
topReal-time process monitortop
htopEnhanced process monitor (interactive)htop
killSend signal to a processkill 1234
kill -9Force kill a processkill -9 1234
killallKill processes by namekillall firefox
bgResume a stopped job in backgroundbg %1
fgBring a background job to foregroundfg %1
jobsList background jobsjobs
nohupRun command immune to hangupsnohup ./server.sh &
&Run command in background./long_task.sh &
Ctrl+CInterrupt (kill) foreground process
Ctrl+ZSuspend foreground process

Package Management

Different Linux distributions use different package managers:

DistributionPackage ManagerInstall ExampleUpdate System
Ubuntu/Debianaptsudo apt install nginxsudo apt update && sudo apt upgrade
Fedora/RHELdnfsudo dnf install nginxsudo dnf upgrade
Arch Linuxpacmansudo pacman -S nginxsudo pacman -Syu
openSUSEzyppersudo zypper install nginxsudo zypper update

Common patterns:

Disk and System Information

CommandPurposeExample
df -hDisk space usage (human-readable)df -h
du -shDirectory size summarydu -sh /var/log
du -h --max-depth=1Size of immediate subdirectoriesdu -h --max-depth=1 /home
free -hMemory usagefree -h
uname -aSystem informationuname -a
lsblkList block devices (disks/partitions)lsblk
lscpuCPU informationlscpu
uptimeSystem uptime and load averagesuptime
hostnameDisplay system hostnamehostname

Networking

CommandPurposeExample
ip addrShow network interfaces and IP addressesip addr
ip routeShow routing tableip route
ss -tlnpShow listening TCP portsss -tlnp
curlTransfer data from/to a URLcurl -O https://example.com/file.tar.gz
wgetDownload fileswget https://example.com/file.tar.gz
pingTest network connectivityping -c 4 google.com
digDNS lookupdig example.com
sshSecure remote loginssh user@192.168.1.100
scpSecure copy over SSHscp file.txt user@host:/path/
rsyncEfficient file synchronizationrsync -avz src/ user@host:dest/
netstat -tlnp(Legacy) Show listening portsnetstat -tlnp

Pipes and Redirection

Pipes and redirection are fundamental to the Linux philosophy of combining small, focused tools into powerful pipelines.

OperatorPurposeExample
\|Pipe: send output of one command to anotherls -l \| grep ".txt"
>Redirect output to file (overwrite)echo "hello" > file.txt
>>Redirect output to file (append)echo "line 2" >> file.txt
<Redirect file as inputsort < unsorted.txt
2>Redirect error outputcommand 2> errors.log
2>&1Redirect errors to same place as outputcommand > all.log 2>&1
&>Redirect both stdout and stderrcommand &> all.log
teeWrite to file AND display on screencommand \| tee output.log
xargsBuild commands from piped inputfind . -name "*.tmp" \| xargs rm

Pipeline Example

Find the 10 largest files in a directory tree:

find /var -type f -exec du -h {} + 2>/dev/null | sort -rh | head -10

Compression and Archiving

CommandPurposeExample
tar -czfCreate compressed archive (.tar.gz)tar -czf backup.tar.gz /home/user/
tar -xzfExtract .tar.gz archivetar -xzf backup.tar.gz
tar -xjfExtract .tar.bz2 archivetar -xjf archive.tar.bz2
gzipCompress a filegzip large_file.txt
gunzipDecompress a .gz filegunzip large_file.txt.gz
zipCreate ZIP archivezip -r archive.zip directory/
unzipExtract ZIP archiveunzip archive.zip

User Management

CommandPurposeExample
sudoRun command as superusersudo apt update
suSwitch to another usersu - alice
whoamiShow current usernamewhoami
idShow user ID and group membershipsid
groupsShow groups current user belongs togroups
passwdChange passwordpasswd
useraddCreate a new usersudo useradd -m newuser
usermodModify a user accountsudo usermod -aG docker alice

Essential Tips for Windows Users

  1. Tab completion works everywhere — press Tab to auto-complete file names and commands.
  2. Ctrl+R searches your command history — start typing and it finds matching previous commands.
  3. man command opens the manual page for any command (man grep, man chmod).
  4. command --help provides a quick usage summary.
  5. The home directory (~ or /home/username) is the equivalent of C:\Users\Username.
  6. sudo is the equivalent of "Run as Administrator."
  7. Use alias to create shortcuts: alias ll='ls -la' in your .bashrc.