Linux Commands

Essential Linux/Unix commands for system administration.

File Operations

ls -la

List all files with details

cd <directory>

Change directory

pwd

Print working directory

cp <source> <dest>

Copy file or directory

cp -r <source> <dest>

Copy directory recursively

mv <source> <dest>

Move or rename file

rm <file>

Remove file

rm -rf <directory>

Remove directory recursively

mkdir <directory>

Create directory

touch <file>

Create empty file

cat <file>

Display file contents

less <file>

View file with pagination

head <file>

Show first 10 lines

tail <file>

Show last 10 lines

tail -f <file>

Follow file updates

File Permissions

chmod 755 <file>

Change file permissions

chmod +x <file>

Make file executable

chown user:group <file>

Change file owner

chown -R user:group <dir>

Change owner recursively

Process Management

ps aux

List all running processes

top

Display processes in real-time

htop

Interactive process viewer

kill <pid>

Kill process by ID

kill -9 <pid>

Force kill process

killall <name>

Kill all processes by name

bg

Resume job in background

fg

Bring job to foreground

jobs

List background jobs

System Information

uname -a

Show system information

df -h

Show disk usage

du -sh <directory>

Show directory size

free -h

Show memory usage

uptime

Show system uptime

whoami

Show current user

hostname

Show system hostname

Network

ping <host>

Test network connectivity

curl <url>

Transfer data from URL

wget <url>

Download file from URL

netstat -tuln

Show listening ports

ss -tuln

Show socket statistics

ip addr

Show IP addresses

ifconfig

Show network interfaces

Search & Find

find . -name "*.txt"

Find files by name

grep "pattern" <file>

Search text in file

grep -r "pattern" <dir>

Search recursively

locate <file>

Find file by name (fast)

which <command>

Show command location

Archive & Compression

tar -czf archive.tar.gz <dir>

Create compressed archive

tar -xzf archive.tar.gz

Extract compressed archive

zip -r archive.zip <dir>

Create zip archive

unzip archive.zip

Extract zip archive

gzip <file>

Compress file

gunzip <file.gz>

Decompress file

User Management

sudo <command>

Run command as superuser

su - <user>

Switch user

useradd <user>

Create new user

passwd <user>

Change user password

usermod -aG <group> <user>

Add user to group