Command | Why We Use It? | Where We Use It? | Usage in Cloud & DevOps |
---|---|---|---|
ssh | Securely login to a remote Linux system. | Remote server access, troubleshooting, deployment. | Used in AWS EC2, GCP VMs, Azure VMs for secure access to cloud instances. |
df -h | Check disk space usage in human-readable format. | Monitoring system storage, detecting low disk space. | Used in Kubernetes, Docker, EC2 instances to monitor disk usage. |
du | Display directory size usage. | Checking large files consuming disk space. | Used in log management, persistent storage in containers, cloud storage analysis. |
ps | Show currently running processes. | Identifying high CPU/memory-consuming processes. | Used in AWS, Kubernetes, EC2 instances to monitor application performance. |
top | Real-time monitoring of CPU, memory, processes. | Troubleshooting high resource utilization. | Used in containers, cloud instances, on-premises servers for monitoring. |
fuser | Identify processes using a file or port. | Checking which process is locking a file or using a port. | Used in troubleshooting blocked ports in DevOps pipelines and CI/CD runners. |
kill | Stop a running process. | Killing unresponsive applications. | Used in AWS, Docker, Kubernetes nodes to terminate problematic processes. |
nohup | Run processes in the background even after logout. | Running long scripts, jobs, or servers persistently. | Used in background execution of deployments, cron jobs, and monitoring scripts. |
free -h | Show available and used memory (RAM). | Checking system memory usage. | Used in AWS, Azure, Kubernetes, EC2 to monitor memory before scaling. |
vmstat | Monitor CPU, memory, disk, and system performance. | Detecting performance bottlenecks. | Used in performance tuning, debugging high CPU/memory usage in cloud environments. |
1. SSH (Secure Shell) – Remote Login
Used For: Secure remote login to a Linux system.
How It Works:
- Uses the SSH protocol to establish a secure encrypted connection between the client and the remote server.
- Can use password authentication or SSH key-based authentication for enhanced security.
Usage & Examples:
Password-Based Authentication
ssh username@remote-server-ip
Example:
ssh devops@192.168.1.100
Key-Based Authentication (More Secure)
ssh -i /path/to/private_key username@remote-server-ip
Example:
ssh -i ~/.ssh/id_rsa devops@192.168.1.100
📌 Best Practice: Use SSH keys instead of passwords for security.
2. df -h
– Check Disk Space Usage
Used For: Displaying available and used disk space in human-readable format.
How It Works:
- Fetches data from the
/proc
filesystem to display mounted partitions and their usage.
Usage & Example:
df -h
Output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 25G 25G 50% /
tmpfs 8G 0 8G 0% /dev/shm
📌 Best Practice: Run df -hT
to also display the filesystem type.
3. du
– Check Directory Size
Used For: Displaying the size of files and directories.
How It Works:
- Recursively calculates the space occupied by directories and files.
Usage & Example:
du -sh /var/logs
Output:
2.4G /var/logs
📌 Best Practice: Use du -h --max-depth=1 /home/
to get sizes of immediate subdirectories only.
4. ps
– View Running Processes
Used For: Displaying currently running processes.
How It Works:
- Retrieves process information from
/proc
and displays process ID (PID), CPU usage, and command execution details.
Usage & Example:
ps aux | grep nginx
Output:
root 1221 0.0 0.3 94800 3772 ? Ss 10:10 0:00 nginx: master process
📌 Best Practice: Use ps -ef
for a full listing with parent-child process hierarchy.
5. top
– Monitor System Performance
Used For: Viewing real-time CPU, memory, and process usage.
How It Works:
- Continuously updates system performance statistics and active processes.
Usage:
top
📌 Best Practice: Use htop
for a more user-friendly version.
6. fuser
– Identify Processes Using a File or Port
Used For: Finding processes that are using a specific file, directory, or port.
How It Works:
- Retrieves process information from the kernel and
/proc
.
Usage:
fuser -v /var/log/syslog
📌 Best Practice: Use fuser -k <port>
to kill processes using a port.
7. kill
– Terminate a Process
Used For: Stopping a running process.
How It Works:
- Sends signals to processes (default is
SIGTERM
which allows cleanup before exiting).
Usage:
kill 1234 # Terminate process with PID 1234
kill -9 5678 # Force kill process with PID 5678
📌 Best Practice: Use kill -15 <PID>
first to allow graceful shutdown.
8. nohup
– Run Commands in the Background
Used For: Running commands in the background even after logout.
How It Works:
- Redirects output to
nohup.out
and ignoresSIGHUP
signals.
Usage:
nohup python script.py &
📌 Best Practice: Use nohup command & disown
to completely detach from the shell.
9. free -h
– Check Memory Usage
Used For: Displaying free and used memory (RAM).
How It Works:
- Reads memory usage stats from
/proc/meminfo
.
Usage & Example:
free -h
Output:
total used free shared buff/cache available
Mem: 16G 5G 8G 1G 3G 9G
📌 Best Practice: Use free -m
to display in megabytes.
10. vmstat
– System Performance Monitoring
Used For: Monitoring CPU, memory, swap, I/O, and system performance.
How It Works:
- Collects statistics from
/proc/stat
and/proc/meminfo
.
Usage & Example:
vmstat 1 5
📌 Best Practice: Use vmstat -d
to see disk statistics.
DevOps & Cloud Use Cases
- Infrastructure Monitoring:
df -h
,du
,free -h
,top
, andvmstat
for resource utilization in cloud VMs & Kubernetes nodes. - Process Management:
ps
,fuser
,kill
,nohup
for managing services and applications in production. - Remote Access:
ssh
for secure remote login to AWS EC2, GCP, and Azure instances. - Automation & Troubleshooting:
nohup
for running long processes during deployment and automation scripts.