Linux Commands Frequently Used by DevOps Engineers
Table of Contents
- Overview
- System Information
- File and Directory Management
- Text Processing
- Process Management
- Networking
- User and Permission Management
- Disk and Storage
- Compression and Archiving
1. Overview
This document is a reference guide for Linux commands frequently used by DevOps engineers in server management, deployment, and monitoring tasks.
Commands are categorized by task type, with options and examples for immediate practical use.
This guide targets entry to intermediate level DevOps engineers who need quick reference material.
Chapters by Task Type
| Chapter | Description |
|---|---|
| System Information | Query basic system information such as hostname, kernel version, and uptime. Used as the first step in troubleshooting and status checks. |
| File and Directory Management | Create, copy, move, delete, and search files/directories. Essential for deployment scripts and daily server maintenance. |
| Text Processing | Process text-based tasks including log analysis, config file editing, and data extraction. Powerful automation through pipeline combinations. |
| Process Management | Query, terminate running processes, and control system services. Core commands for resource monitoring and incident response. |
| Networking | Check network connectivity, download files, and test APIs. Essential for infrastructure configuration and debugging. |
| User and Permission Management | Manage user accounts and file permissions. Used for security policy enforcement and access control. |
| Disk and Storage | Check disk capacity, mount status, and partition information. Used for storage management and capacity monitoring. |
| Compression and Archiving | Compress, decompress, and create archives. Used for backup and deployment package creation. |
2. System Information
Commands for querying basic system status and information.
These are typically the first commands run during incident response, environment verification, and documentation.
Command List
| Command | Function |
|---|---|
| hostname | Check or set system hostname |
| uname | Display kernel and system information |
| uptime | Check system uptime and load |
| date | Check or set system date/time |
| whoami | Display current logged-in user |
| id | Display user UID/GID information |
hostname
Check or set the system hostname.
Key Options
| Option | Description |
|---|---|
-f |
Display FQDN (Fully Qualified Domain Name) |
-i |
Display host IP address |
-s |
Display short hostname |
Examples
# Check current hostname
hostname
# Check FQDN
hostname -f
# Check IP address
hostname -i
uname
Display kernel version, architecture, and other system information.
Key Options
| Option | Description |
|---|---|
-a |
Display all system information |
-r |
Display kernel release version |
-m |
Display hardware architecture |
-n |
Display network node hostname |
Examples
# Display all system information
uname -a
# Check kernel version only
uname -r
# Check architecture (x86_64, arm64, etc.)
uname -m
uptime
Check system uptime, logged-in users, and system load.
Key Options
| Option | Description |
|---|---|
-p |
Display uptime in human-readable format |
-s |
Display system start time |
Examples
# Default output (uptime, users, load average)
uptime
# Human-readable uptime format
uptime -p
# Check system start time
uptime -s
date
Check or set the system date and time.
Key Options
| Option | Description |
|---|---|
+FORMAT |
Output in specified format |
-u |
Display UTC time |
-d STRING |
Parse specified date/time string |
Common Formats
| Format | Example Output |
|---|---|
+%Y-%m-%d |
2024-01-15 |
+%H:%M:%S |
14:30:25 |
+%Y%m%d_%H%M%S |
20240115_143025 |
Examples
# Check current date/time
date
# Output in ISO format
date +%Y-%m-%d
# Timestamp for log filenames
date +%Y%m%d_%H%M%S
# Check UTC time
date -u
# Calculate date (7 days ago)
date -d "7 days ago" +%Y-%m-%d
whoami
Display the current logged-in username.
Examples
# Check current user
whoami
id
Display UID, GID, and group information for current or specified user.
Key Options
| Option | Description |
|---|---|
-u |
Display UID only |
-g |
Display primary GID only |
-G |
Display all group IDs |
-n |
Display names instead of numbers |
Examples
# Full information for current user
id
# Check specific user information
id username
# Check UID only
id -u
# Check group names
id -nG
3. File and Directory Management
Perform basic filesystem operations including create, copy, move, delete, and search files and directories.
Most frequently used commands in deployment scripts, backup tasks, and daily server management.
Command List
| Command | Function |
|---|---|
| ls | List directory contents |
| cd | Change directory |
| pwd | Print working directory path |
| mkdir | Create directory |
| rm | Remove files/directories |
| cp | Copy files/directories |
| mv | Move or rename files/directories |
| find | Search for files/directories |
| ln | Create links (hard/symbolic) |
| touch | Create empty file or update timestamp |
ls
List directory contents.
Key Options
| Option | Description |
|---|---|
-l |
Long format (permissions, owner, size, date) |
-a |
Show all including hidden files |
-h |
Human-readable file sizes |
-R |
Recursive listing of subdirectories |
-t |
Sort by modification time |
-S |
Sort by file size |
Examples
# Long format listing
ls -l
# Include hidden files with readable sizes
ls -lah
# Sort by modification time
ls -lt
# List specific pattern files
ls -l *.log
cd
Change the working directory.
Examples
# Go to home directory
cd ~
cd
# Go to parent directory
cd ..
# Go to absolute path
cd /var/log
# Go to previous directory
cd -
pwd
Print the absolute path of the current working directory.
Key Options
| Option | Description |
|---|---|
-P |
Print physical path (resolve symlinks) |
-L |
Print logical path (default) |
Examples
# Check current path
pwd
# Physical path (resolve symlinks)
pwd -P
mkdir
Create new directories.
Key Options
| Option | Description |
|---|---|
-p |
Create parent directories as needed |
-m MODE |
Set permissions on creation |
-v |
Verbose output |
Examples
# Create single directory
mkdir logs
# Create nested directories at once
mkdir -p /app/logs/2024/01
# Create with specific permissions
mkdir -m 755 scripts
rm
Remove files or directories.
Key Options
| Option | Description |
|---|---|
-r |
Recursive removal for directories |
-f |
Force removal (no confirmation) |
-i |
Prompt before removal |
-v |
Verbose output |
Examples
# Remove file
rm file.txt
# Remove directory and all contents
rm -rf directory/
# Prompt before removal
rm -i important.txt
# Remove files matching pattern
rm -f *.tmp
⚠️ Warning: rm -rf / or critical paths are unrecoverable
cp
Copy files or directories.
Key Options
| Option | Description |
|---|---|
-r |
Recursive copy for directories |
-p |
Preserve permissions, ownership, timestamps |
-a |
Archive mode (-rp + preserve symlinks) |
-v |
Verbose output |
-i |
Prompt before overwrite |
Examples
# Copy file
cp source.txt dest.txt
# Copy directory
cp -r source_dir/ dest_dir/
# Copy preserving attributes
cp -a /var/www/ /backup/www/
# Copy multiple files to directory
cp file1.txt file2.txt dest_dir/
mv
Move or rename files and directories.
Key Options
| Option | Description |
|---|---|
-i |
Prompt before overwrite |
-f |
Force move (no confirmation) |
-v |
Verbose output |
-n |
Do not overwrite existing files |
Examples
# Rename file
mv old_name.txt new_name.txt
# Move file
mv file.txt /path/to/destination/
# Move directory
mv source_dir/ /new/location/
# Move multiple files
mv *.log /var/log/archive/
find
Search for files and directories matching conditions.
Key Options
| Option | Description |
|---|---|
-name PATTERN |
Search by filename pattern |
-type f/d |
Specify file(f) or directory(d) |
-mtime +/-N |
Search by modification time (days) |
-size +/-N |
Search by file size |
-exec CMD {} \; |
Execute command on results |
-perm MODE |
Search by permissions |
Examples
# Search by name
find /var/log -name "*.log"
# Find files older than 7 days
find /tmp -type f -mtime +7
# Find files larger than 100MB
find / -type f -size +100M
# Search and delete
find /tmp -name "*.tmp" -exec rm {} \;
# Find empty directories
find /app -type d -empty
# Find files with 777 permissions
find / -type f -perm 0777
ln
Create links to files.
Key Options
| Option | Description |
|---|---|
-s |
Create symbolic link |
-f |
Overwrite existing link |
-v |
Verbose output |
Examples
# Create symbolic link
ln -s /path/to/original /path/to/link
# Symbolic link for config file
ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/
# Create hard link
ln original.txt hardlink.txt
# Replace existing link
ln -sf /new/target /path/to/link
touch
Create empty files or update existing file timestamps.
Key Options
| Option | Description |
|---|---|
-a |
Change access time only |
-m |
Change modification time only |
-t STAMP |
Set specific timestamp |
-d STRING |
Set time from date string |
Examples
# Create empty file
touch newfile.txt
# Create multiple files
touch file1.txt file2.txt file3.txt
# Update timestamp
touch existing_file.txt
# Set specific date
touch -d "2024-01-01 00:00:00" file.txt
4. Text Processing
Process text-based tasks including log file analysis, config file editing, and data extraction/transformation.
Powerful data processing automation is possible through pipeline (|) combinations.
Command List
| Command | Function |
|---|---|
| cat | Display file contents |
| head | Display beginning of file |
| tail | Display end of file |
| grep | Pattern search |
| awk | Text processing and data extraction |
| sed | Stream editor |
| cut | Extract fields |
| sort | Sort lines |
| uniq | Remove duplicates |
| wc | Count lines/words/characters |
cat
Display file contents or concatenate files.
Key Options
| Option | Description |
|---|---|
-n |
Number all output lines |
-b |
Number non-empty lines only |
-s |
Squeeze multiple blank lines |
-A |
Show all control characters |
Examples
# Display file contents
cat file.txt
# Display with line numbers
cat -n file.txt
# Concatenate files
cat file1.txt file2.txt > combined.txt
# Append to file
cat newdata.txt >> existing.txt
head
Display the beginning of a file. Default is 10 lines.
Key Options
| Option | Description |
|---|---|
-n N |
Display first N lines |
-c N |
Display first N bytes |
Examples
# Display first 10 lines
head file.txt
# Display first 20 lines
head -n 20 file.txt
# Display first 100 bytes
head -c 100 file.txt
tail
Display the end of a file. Essential for log monitoring.
Key Options
| Option | Description |
|---|---|
-n N |
Display last N lines |
-f |
Follow file changes in real-time |
-F |
Follow + detect file recreation |
-c N |
Display last N bytes |
Examples
# Display last 10 lines
tail file.txt
# Display last 50 lines
tail -n 50 file.txt
# Real-time log monitoring
tail -f /var/log/syslog
# Monitor with log rotation support
tail -F /var/log/nginx/access.log
# Monitor multiple files
tail -f /var/log/*.log
grep
Search for patterns in files.
Key Options
| Option | Description |
|---|---|
-i |
Case-insensitive search |
-r |
Recursive directory search |
-n |
Display line numbers |
-v |
Invert match (non-matching lines) |
-c |
Count matching lines |
-l |
Display only filenames with matches |
-E |
Extended regular expressions |
-A N |
Display N lines after match |
-B N |
Display N lines before match |
Examples
# Basic search
grep "error" /var/log/syslog
# Case-insensitive
grep -i "error" logfile.txt
# Recursive search in directory
grep -r "TODO" /app/src/
# Display with line numbers
grep -n "failed" app.log
# Exclude pattern
grep -v "DEBUG" app.log
# Multiple patterns
grep -E "error|warning|critical" app.log
# Display context (3 lines before and after)
grep -B 3 -A 3 "Exception" app.log
awk
Process text field by field and extract data.
Basic Syntax
awk 'pattern { action }' file
Key Built-in Variables
| Variable | Description |
|---|---|
$0 |
Entire line |
$1, $2, ... |
1st, 2nd, ... field |
NF |
Number of fields |
NR |
Current line number |
FS |
Field separator |
Examples
# Print specific fields
awk '{print $1, $3}' file.txt
# Specify field separator
awk -F: '{print $1}' /etc/passwd
# Conditional printing
awk '$3 > 100 {print $1, $3}' data.txt
# Print line numbers
awk '{print NR, $0}' file.txt
# Calculate sum
awk '{sum += $1} END {print sum}' numbers.txt
# Process lines matching pattern
awk '/error/ {print $0}' logfile.txt
# Print last field
awk '{print $NF}' file.txt
sed
Stream editor for text substitution and transformation.
Basic Syntax
sed 's/pattern/replacement/flags' file
Key Options
| Option | Description |
|---|---|
-i |
Edit file in-place |
-e |
Execute multiple commands |
-n |
Suppress automatic output |
g |
Global replacement (flag) |
Examples
# String substitution (first occurrence)
sed 's/old/new/' file.txt
# Global substitution
sed 's/old/new/g' file.txt
# Edit file in-place
sed -i 's/old/new/g' file.txt
# Delete specific line
sed '5d' file.txt
# Delete empty lines
sed '/^$/d' file.txt
# Print specific lines only
sed -n '10,20p' file.txt
# Multiple substitution commands
sed -e 's/foo/bar/g' -e 's/baz/qux/g' file.txt
cut
Extract specific fields or character ranges from lines.
Key Options
| Option | Description |
|---|---|
-d DELIM |
Specify field delimiter |
-f N |
Extract Nth field |
-c N-M |
Extract character positions N to M |
Examples
# Extract first field (colon-delimited)
cut -d: -f1 /etc/passwd
# Extract multiple fields
cut -d, -f1,3,5 data.csv
# Extract by character position
cut -c1-10 file.txt
# Tab-delimited file (default)
cut -f2 data.tsv
sort
Sort lines.
Key Options
| Option | Description |
|---|---|
-n |
Numeric sort |
-r |
Reverse sort |
-k N |
Sort by Nth field |
-t DELIM |
Specify field delimiter |
-u |
Remove duplicates after sort |
Examples
# Alphabetical sort
sort file.txt
# Numeric sort
sort -n numbers.txt
# Reverse sort
sort -r file.txt
# Sort by 2nd field
sort -t: -k2 data.txt
# Sort and remove duplicates
sort -u file.txt
# Sort by file size (ls output)
ls -l | sort -k5 -n
uniq
Remove consecutive duplicate lines. Usually used with sort.
Key Options
| Option | Description |
|---|---|
-c |
Display count of occurrences |
-d |
Display only duplicated lines |
-u |
Display only unique lines |
-i |
Case-insensitive comparison |
Examples
# Remove duplicates (requires sorted input)
sort file.txt | uniq
# Count occurrences
sort file.txt | uniq -c
# Show only duplicated lines
sort file.txt | uniq -d
# Sort by count
sort file.txt | uniq -c | sort -rn
wc
Count lines, words, and characters in files.
Key Options
| Option | Description |
|---|---|
-l |
Line count |
-w |
Word count |
-c |
Byte count |
-m |
Character count |
Examples
# Full statistics
wc file.txt
# Line count only
wc -l file.txt
# Multiple file statistics
wc -l *.log
# Use with pipe
cat file.txt | grep "error" | wc -l
5. Process Management
Query running processes, monitor, terminate, and control system services.
Core commands for system resource management and incident response.
Command List
| Command | Function |
|---|---|
| ps | Display process status |
| top | Real-time process monitoring |
| htop | Enhanced process monitoring |
| kill | Terminate process |
| pkill | Terminate process by name |
| systemctl | Manage system services |
| journalctl | Query system logs |
| nohup | Run process immune to hangups |
ps
Display information about running processes.
Key Options
| Option | Description |
|---|---|
aux |
Detailed output of all processes |
-ef |
Full format of all processes |
-u USER |
Specific user's processes |
--forest |
Tree view |
Examples
# Display all processes
ps aux
# Full format output
ps -ef
# Search specific process
ps aux | grep nginx
# Process tree view
ps aux --forest
# Specific user's processes
ps -u www-data
# Top CPU-consuming processes
ps aux --sort=-%cpu | head -10
# Top memory-consuming processes
ps aux --sort=-%mem | head -10
top
Monitor system status and processes in real-time.
Runtime Shortcuts
| Key | Function |
|---|---|
q |
Quit |
k |
Kill process |
M |
Sort by memory usage |
P |
Sort by CPU usage |
1 |
Show per-CPU stats |
c |
Show full command path |
Key Options
| Option | Description |
|---|---|
-d N |
Refresh interval N seconds |
-u USER |
Specific user's processes only |
-p PID |
Monitor specific PID |
-b |
Batch mode (for file output) |
Examples
# Default execution
top
# 2-second refresh interval
top -d 2
# Specific user's processes only
top -u nginx
# Batch mode for file output
top -b -n 1 > top_output.txt
htop
Enhanced version of top. Colorful interface with mouse support.
Runtime Shortcuts
| Key | Function |
|---|---|
F5 |
Tree view |
F6 |
Select sort column |
F9 |
Kill process |
F10 |
Quit |
/ |
Search |
\ |
Filter |
Examples
# Default execution
htop
# Specific user's processes only
htop -u nginx
# Start with tree view
htop -t
kill
Send signals to processes to terminate them.
Key Signals
| Signal | Number | Description |
|---|---|---|
SIGTERM |
15 | Graceful termination request (default) |
SIGKILL |
9 | Force termination |
SIGHUP |
1 | Restart/reload configuration |
SIGSTOP |
19 | Pause process |
Examples
# Graceful termination request
kill 1234
# Force termination
kill -9 1234
kill -SIGKILL 1234
# Terminate multiple processes
kill 1234 5678 9012
# Reload configuration (nginx, etc.)
kill -HUP 1234
pkill
Terminate processes by name or conditions.
Key Options
| Option | Description |
|---|---|
-f |
Search in full command line |
-u USER |
Specific user's processes |
-signal |
Specify signal to send |
Examples
# Terminate by name
pkill nginx
# Force termination
pkill -9 nginx
# Search in full command
pkill -f "python app.py"
# Terminate specific user's processes
pkill -u www-data
systemctl
Manage systemd-based services.
Key Commands
| Command | Description |
|---|---|
start |
Start service |
stop |
Stop service |
restart |
Restart service |
reload |
Reload configuration |
status |
Check service status |
enable |
Enable auto-start on boot |
disable |
Disable auto-start on boot |
Examples
# Check service status
systemctl status nginx
# Start service
sudo systemctl start nginx
# Stop service
sudo systemctl stop nginx
# Restart service
sudo systemctl restart nginx
# Reload configuration (without restart)
sudo systemctl reload nginx
# Enable auto-start on boot
sudo systemctl enable nginx
# List all services
systemctl list-units --type=service
# List failed services
systemctl --failed
journalctl
Query systemd journal logs.
Key Options
| Option | Description |
|---|---|
-u UNIT |
Specific service logs |
-f |
Follow logs in real-time |
-n N |
Show last N lines |
--since |
Logs since specific time |
-p LEVEL |
Filter by log level |
-b |
Logs since current boot |
Examples
# View all logs
journalctl
# Specific service logs
journalctl -u nginx
# Follow logs in real-time
journalctl -f -u nginx
# Last 100 lines
journalctl -n 100
# Today's logs only
journalctl --since today
# Error level and above only
journalctl -p err
# Specific time range
journalctl --since "2024-01-01" --until "2024-01-02"
nohup
Run processes that continue after terminal closes.
Examples
# Run in background
nohup ./script.sh &
# Specify output file
nohup ./script.sh > output.log 2>&1 &
# Discard output
nohup ./script.sh > /dev/null 2>&1 &
6. Networking
Perform network-related tasks including connectivity checks, file downloads, and API testing.
Essential commands for infrastructure configuration, troubleshooting, and external service integration.
Command List
| Command | Function |
|---|---|
| ping | Test network connectivity |
| curl | Transfer data via URL and API testing |
| wget | Download files |
| ss | Socket statistics |
| netstat | Network connection status |
| ip | IP address and routing management |
| dig | DNS lookup |
| nslookup | DNS lookup (simple) |
| traceroute | Trace network path |
| scp | Copy files via SSH |
| rsync | File synchronization |
ping
Send ICMP packets to test network connectivity.
Key Options
| Option | Description |
|---|---|
-c N |
Stop after N packets |
-i N |
Send interval N seconds |
-W N |
Timeout N seconds |
-s SIZE |
Specify packet size |
Examples
# Basic ping
ping google.com
# Send 4 packets only
ping -c 4 google.com
# 1 second timeout
ping -c 4 -W 1 192.168.1.1
curl
Transfer data via URLs. Essential for API testing.
Key Options
| Option | Description |
|---|---|
-X METHOD |
Specify HTTP method |
-H HEADER |
Add header |
-d DATA |
POST data |
-o FILE |
Output to file |
-O |
Save with remote filename |
-L |
Follow redirects |
-s |
Silent mode |
-v |
Verbose output |
-I |
Headers only |
-k |
Skip SSL certificate verification |
Examples
# GET request
curl https://api.example.com/users
# POST request (JSON)
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name": "John", "email": "john@example.com"}'
# Check headers
curl -I https://example.com
# Download file
curl -O https://example.com/file.tar.gz
# Include auth token
curl -H "Authorization: Bearer TOKEN" https://api.example.com/data
# Verbose debug
curl -v https://example.com
# Output HTTP status code only
curl -s -o /dev/null -w "%{http_code}" https://example.com
wget
Download files from URLs.
Key Options
| Option | Description |
|---|---|
-O FILE |
Specify output filename |
-q |
Quiet mode |
-c |
Resume download |
-r |
Recursive download |
-P DIR |
Specify download directory |
--limit-rate |
Limit download speed |
Examples
# Basic download
wget https://example.com/file.tar.gz
# Specify filename
wget -O myfile.tar.gz https://example.com/file.tar.gz
# Resume download
wget -c https://example.com/largefile.iso
# Background download
wget -b https://example.com/file.tar.gz
# Limit speed
wget --limit-rate=1m https://example.com/file.tar.gz
ss
Display socket statistics. Modern replacement for netstat.
Key Options
| Option | Description |
|---|---|
-t |
TCP sockets |
-u |
UDP sockets |
-l |
Listening sockets |
-n |
Numeric output (no DNS lookup) |
-p |
Show process information |
-a |
All sockets |
Examples
# Listening TCP ports
ss -tlnp
# All TCP connections
ss -tan
# Check specific port
ss -tlnp | grep :80
# ESTABLISHED connections
ss -t state established
# Connections by process
ss -tp
netstat
Display network connections, routing tables, and interface statistics.
Key Options
| Option | Description |
|---|---|
-t |
TCP connections |
-u |
UDP connections |
-l |
Listening state |
-n |
Numeric output |
-p |
Process information |
-r |
Routing table |
Examples
# Check listening ports
netstat -tlnp
# All connections
netstat -an
# Routing table
netstat -r
# Interface statistics
netstat -i
ip
Manage IP addresses, routing, and network interfaces.
Key Subcommands
| Command | Description |
|---|---|
ip addr |
IP address management |
ip link |
Network interface management |
ip route |
Routing table management |
ip neigh |
ARP table query |
Examples
# Check IP addresses
ip addr
ip a
# Specific interface
ip addr show eth0
# Routing table
ip route
ip r
# Check default gateway
ip route | grep default
# Enable/disable interface
sudo ip link set eth0 up
sudo ip link set eth0 down
# Add IP address
sudo ip addr add 192.168.1.100/24 dev eth0
dig
Query DNS records in detail.
Key Options
| Option | Description |
|---|---|
+short |
Brief output |
-t TYPE |
Specify record type |
@SERVER |
Specify DNS server |
Examples
# A record query
dig example.com
# Brief output
dig +short example.com
# MX record
dig -t MX example.com
# NS record
dig -t NS example.com
# Query specific DNS server
dig @8.8.8.8 example.com
# Reverse lookup
dig -x 8.8.8.8
nslookup
Perform simple DNS lookups.
Examples
# Basic lookup
nslookup example.com
# Use specific DNS server
nslookup example.com 8.8.8.8
# Reverse lookup
nslookup 8.8.8.8
traceroute
Trace the network path to a destination.
Key Options
| Option | Description |
|---|---|
-n |
No DNS lookup |
-m N |
Maximum hops |
-w N |
Timeout seconds |
Examples
# Basic trace
traceroute google.com
# Without DNS lookup
traceroute -n google.com
# Maximum 15 hops
traceroute -m 15 google.com
scp
Copy files between hosts via SSH.
Key Options
| Option | Description |
|---|---|
-r |
Recursive copy for directories |
-P PORT |
Specify SSH port |
-i KEY |
Specify SSH key file |
-v |
Verbose output |
Examples
# Local → Remote
scp file.txt user@server:/path/to/dest/
# Remote → Local
scp user@server:/path/to/file.txt ./
# Copy directory
scp -r mydir/ user@server:/path/to/dest/
# Specify port
scp -P 2222 file.txt user@server:/path/
# Use key file
scp -i ~/.ssh/mykey.pem file.txt user@server:/path/
rsync
Efficiently synchronize files. Transfers only changed parts.
Key Options
| Option | Description |
|---|---|
-a |
Archive mode (preserve permissions, times) |
-v |
Verbose output |
-z |
Compress during transfer |
--delete |
Delete files not in source |
--dry-run |
Test run |
-e |
Specify remote shell |
--progress |
Show progress |
Examples
# Local synchronization
rsync -av source/ dest/
# Sync to remote server
rsync -avz source/ user@server:/path/to/dest/
# Sync from remote to local
rsync -avz user@server:/path/to/source/ ./dest/
# Full sync with deletion
rsync -av --delete source/ dest/
# Test run
rsync -av --dry-run source/ dest/
# Specify SSH port
rsync -avz -e "ssh -p 2222" source/ user@server:/path/
# Show progress
rsync -av --progress source/ dest/
7. User and Permission Management
Manage user accounts and file/directory permissions for access control.
Essential commands for security policy enforcement and system administration.
Command List
| Command | Function |
|---|---|
| chmod | Change file permissions |
| chown | Change file ownership |
| useradd | Create user |
| usermod | Modify user |
| userdel | Delete user |
| passwd | Change password |
| sudo | Execute with admin privileges |
| su | Switch user |
| groups | Check group membership |
chmod
Change file or directory permissions.
Permission Notation
| Symbol | Meaning |
|---|---|
r (4) |
Read |
w (2) |
Write |
x (1) |
Execute |
u |
Owner |
g |
Group |
o |
Others |
a |
All |
Key Options
| Option | Description |
|---|---|
-R |
Recursive |
-v |
Verbose |
Examples
# Numeric mode
chmod 755 script.sh # rwxr-xr-x
chmod 644 file.txt # rw-r--r--
chmod 600 secret.key # rw-------
# Symbolic mode
chmod +x script.sh # Add execute permission
chmod u+w file.txt # Add owner write permission
chmod go-rwx file.txt # Remove all permissions for group/others
# Recursive for directory
chmod -R 755 /var/www/
# Directories 755, files 644
find /var/www -type d -exec chmod 755 {} \;
find /var/www -type f -exec chmod 644 {} \;
chown
Change file or directory ownership and group.
Key Options
| Option | Description |
|---|---|
-R |
Recursive |
-v |
Verbose |
Examples
# Change owner
sudo chown user file.txt
# Change owner and group
sudo chown user:group file.txt
# Change group only
sudo chown :group file.txt
# Recursive
sudo chown -R www-data:www-data /var/www/
useradd
Create a new user account.
Key Options
| Option | Description |
|---|---|
-m |
Create home directory |
-s SHELL |
Specify default shell |
-g GROUP |
Specify primary group |
-G GROUPS |
Specify supplementary groups |
-d DIR |
Specify home directory path |
Examples
# Create basic user
sudo useradd username
# Create with home directory
sudo useradd -m username
# Specify shell and groups
sudo useradd -m -s /bin/bash -G sudo,docker username
# Create system user (for services)
sudo useradd -r -s /usr/sbin/nologin serviceuser
usermod
Modify existing user account.
Key Options
| Option | Description |
|---|---|
-aG GROUP |
Add to group |
-s SHELL |
Change shell |
-L |
Lock account |
-U |
Unlock account |
-l NAME |
Change username |
Examples
# Add to group
sudo usermod -aG docker username
sudo usermod -aG sudo username
# Change shell
sudo usermod -s /bin/zsh username
# Lock account
sudo usermod -L username
# Unlock account
sudo usermod -U username
userdel
Delete a user account.
Key Options
| Option | Description |
|---|---|
-r |
Remove home directory and mail spool |
-f |
Force deletion |
Examples
# Delete user only
sudo userdel username
# Delete including home directory
sudo userdel -r username
passwd
Set or change user password.
Key Options
| Option | Description |
|---|---|
-l |
Lock account |
-u |
Unlock account |
-d |
Delete password |
-e |
Expire password (force change on next login) |
Examples
# Change own password
passwd
# Change another user's password (root)
sudo passwd username
# Force password change on next login
sudo passwd -e username
sudo
Execute commands with another user's privileges (typically root).
Key Options
| Option | Description |
|---|---|
-u USER |
Execute as specific user |
-i |
Start login shell |
-s |
Start shell |
-l |
List allowed commands |
Examples
# Execute with root privileges
sudo apt update
# Start root shell
sudo -i
# Execute as specific user
sudo -u www-data whoami
# Check allowed commands
sudo -l
su
Switch to another user.
Key Options
| Option | Description |
|---|---|
- |
Login shell |
-c CMD |
Execute command and return |
Examples
# Switch to root
su -
# Switch to specific user
su - username
# Execute command and return
su -c "whoami" username
groups
Display group membership.
Examples
# Current user's groups
groups
# Specific user's groups
groups username
8. Disk and Storage
Check and manage disk capacity, partitions, and mount status.
Used for storage management, capacity monitoring, and system maintenance.
Command List
| Command | Function |
|---|---|
| df | Display disk usage |
| du | Display directory size |
| lsblk | List block devices |
| mount | Mount filesystem |
| umount | Unmount filesystem |
| fdisk | Partition management |
| blkid | Display block device UUID |
df
Display filesystem disk usage.
Key Options
| Option | Description |
|---|---|
-h |
Human-readable units (GB, MB) |
-T |
Show filesystem type |
-i |
Show inode usage |
Examples
# Check disk usage
df -h
# Include filesystem type
df -hT
# Inode usage
df -i
# Specific path
df -h /var
du
Display file and directory sizes.
Key Options
| Option | Description |
|---|---|
-h |
Human-readable units |
-s |
Summary only |
-d N |
Depth N levels |
--max-depth=N |
Maximum depth |
-a |
Include files |
Examples
# Current directory size
du -sh
# Subdirectory sizes
du -h --max-depth=1
# Find large directories
du -h --max-depth=1 | sort -hr | head -10
# Specific directory
du -sh /var/log/
# Top 10 largest files/directories
du -ah / 2>/dev/null | sort -hr | head -10
lsblk
Display block device information in tree format.
Key Options
| Option | Description |
|---|---|
-f |
Include filesystem information |
-a |
Include empty devices |
-o COLUMNS |
Specify output columns |
Examples
# Basic output
lsblk
# Include filesystem information
lsblk -f
# Detailed information
lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT,UUID
mount
Mount filesystems or check mount status.
Key Options
| Option | Description |
|---|---|
-t TYPE |
Filesystem type |
-o OPTIONS |
Mount options |
-a |
Mount all entries in /etc/fstab |
Examples
# Current mount status
mount
# Mount device
sudo mount /dev/sdb1 /mnt/data
# Specify type
sudo mount -t ext4 /dev/sdb1 /mnt/data
# Read-only mount
sudo mount -o ro /dev/sdb1 /mnt/data
# Mount ISO file
sudo mount -o loop image.iso /mnt/iso
# NFS mount
sudo mount -t nfs server:/share /mnt/nfs
umount
Unmount mounted filesystems.
Key Options
| Option | Description |
|---|---|
-l |
Lazy unmount |
-f |
Force unmount |
Examples
# Unmount
sudo umount /mnt/data
# Unmount by device name
sudo umount /dev/sdb1
# Force unmount
sudo umount -f /mnt/stuck
# Lazy unmount (even if busy)
sudo umount -l /mnt/busy
fdisk
Manage disk partitions.
Key Options
| Option | Description |
|---|---|
-l |
List partitions |
Examples
# List all disk partitions
sudo fdisk -l
# Partition specific disk
sudo fdisk /dev/sdb
# Interactive commands: n(new), d(delete), p(print), w(write)
blkid
Display block device UUID and filesystem information.
Examples
# All device information
sudo blkid
# Specific device
sudo blkid /dev/sda1
# UUID only
sudo blkid -s UUID -o value /dev/sda1
9. Compression and Archiving
Compress, decompress, and create archives.
Used for backup, deployment package creation, and log archiving.
Command List
| Command | Function |
|---|---|
| tar | Create/extract archives |
| gzip | gzip compression/decompression |
| gunzip | gzip decompression |
| zip | zip compression |
| unzip | zip extraction |
| zcat | Display compressed file contents |
tar
Archive files or compress archives.
Key Options
| Option | Description |
|---|---|
-c |
Create archive |
-x |
Extract archive |
-v |
Verbose output |
-f FILE |
Specify filename |
-z |
gzip compression |
-j |
bzip2 compression |
-J |
xz compression |
-t |
List contents |
-C DIR |
Specify target directory |
Examples
# Create tar.gz
tar -czvf archive.tar.gz directory/
# Extract tar.gz
tar -xzvf archive.tar.gz
# Extract to specific directory
tar -xzvf archive.tar.gz -C /path/to/dest/
# List contents (without extraction)
tar -tzvf archive.tar.gz
# Create tar.bz2
tar -cjvf archive.tar.bz2 directory/
# Archive specific files
tar -czvf logs.tar.gz /var/log/*.log
# Exclude specific pattern
tar -czvf backup.tar.gz --exclude='*.tmp' directory/
gzip
Compress files with gzip. Replaces original file.
Key Options
| Option | Description |
|---|---|
-d |
Decompress |
-k |
Keep original file |
-v |
Verbose output |
-1~-9 |
Compression level (9 is maximum) |
Examples
# Compress
gzip file.txt # → file.txt.gz
# Keep original
gzip -k file.txt
# Decompress
gzip -d file.txt.gz
# Maximum compression
gzip -9 largefile.txt
gunzip
Decompress gzip files.
Examples
# Decompress
gunzip file.txt.gz
# Keep original
gunzip -k file.txt.gz
zip
Compress files in zip format.
Key Options
| Option | Description |
|---|---|
-r |
Include directories recursively |
-e |
Set password |
-9 |
Maximum compression |
Examples
# Compress files
zip archive.zip file1.txt file2.txt
# Compress directory
zip -r archive.zip directory/
# Set password
zip -e secure.zip file.txt
# Maximum compression
zip -9 -r archive.zip directory/
unzip
Extract zip files.
Key Options
| Option | Description |
|---|---|
-d DIR |
Specify target directory |
-l |
List contents |
-o |
Overwrite without prompt |
Examples
# Extract
unzip archive.zip
# Extract to specific directory
unzip archive.zip -d /path/to/dest/
# List contents
unzip -l archive.zip
zcat
Display compressed file contents without extraction.
Examples
# Display gzip file contents
zcat file.txt.gz
# Use with pipe
zcat access.log.gz | grep "404"
# Multiple files
zcat *.gz | grep "error"
References
Last updated: 2024
'블라베 IT world > 취향 IT Topic' 카테고리의 다른 글
| 데브옵스 엔지니어 필수 리눅스 명령어 세트, CI/CD, 컨테이너,네트워크 디버깅, 자동화 스크립팅 요약편 (0) | 2026.01.12 |
|---|---|
| Essential Linux Commands for DevOps Engineers: CI/CD Pipeline Management, Container Orchestration, Network Debugging, and Real-time Monitoring & Log Analysis. (0) | 2026.01.12 |
| DevOps 엔지니어가 자주 사용하는 Linux 명령어 세트 (0) | 2026.01.11 |
| 집중력 향상에 관한 연구 요약 (2) | 2025.06.12 |
| 보안 3요소 CIA (기밀성, 무결성, 가용성) (0) | 2023.11.01 |