application linux commands
In DevOps and systems administration, there are several Linux commands used to
check various aspects of application performance, troubleshooting, resource
usage, and process management. Here’s a list of useful commands that are often
used in DevOps workflows, including lsof , which you mentioned:
1. lsof (List Open Files)
Purpose: Displays a list of all open files and processes using them. Files can
be regular files, directories, or network sockets.
Common Use Cases:
Check which process is using a particular file or port.
Identify processes using network sockets or listening on specific ports.
Example:
lsof -i :80 # List processes using port 80
lsof /path/to/file # Show processes using a specific file
2. top
Purpose: Provides a dynamic, real-time view of system processes, resource
usage (CPU, memory), and more.
Common Use Cases:
Monitor system performance.
Find out which processes are consuming the most CPU or memory.
Example:
application linux commands 1
top # Basic real-time process monitoring
top -u user_name # Show processes running for a specific user
3. htop
Purpose: An interactive process viewer, similar to top , but with a more user-
friendly interface.
Common Use Cases:
Process management, sorting by various resource usages.
Killing processes directly from the interface.
Example:
htop # Start interactive process monitoring
4. ps (Process Status)
Purpose: Provides information about running processes.
Common Use Cases:
List running processes, filter based on criteria, show detailed process
information.
Example:
ps aux # List all running processes with detailed info
ps -ef # Show all processes with full details
ps -p PID # Show information for a specific process by its PID
5. netstat (Network Statistics)
Purpose: Displays network connections, routing tables, interface statistics,
and more.
Common Use Cases:
Check which processes are using specific network ports.
application linux commands 2
Inspect open network connections and their states.
Example:
netstat -tuln # Show listening TCP/UDP ports
netstat -anp # Show all network connections and associated processes
6. ss (Socket Stat)
Purpose: A utility to investigate sockets, similar to netstat , but more efficient
and faster.
Common Use Cases:
View detailed socket statistics, including listening ports and connections.
Example:
ss -tuln # Show listening TCP/UDP sockets
ss -lptn # Show listening sockets with process details
7. df (Disk Free)
Purpose: Reports the amount of disk space used and available on mounted
filesystems.
Common Use Cases:
Check free disk space on various filesystems.
Example:
df -h # Human-readable disk space usage
df -T # Show filesystem types along with disk usage
8. du (Disk Usage)
Purpose: Displays the disk usage of files and directories.
Common Use Cases:
application linux commands 3
Find large files or directories that are consuming disk space.
Example:
du -sh /path/to/dir # Show total size of a directory
du -ah /path/to/dir # Show size of all files in a directory
9. vmstat (Virtual Memory Statistics)
Purpose: Provides a summary of the system’s virtual memory, processes,
paging, block IO, traps, and CPU activity.
Common Use Cases:
Monitor system resource usage (memory, CPU, etc.).
Example:
vmstat 1 # Update every 1 second
10. free
Purpose: Shows memory usage (total, used, free, swap).
Common Use Cases:
Check available memory and swap usage.
Example:
free -h # Display memory usage in a human-readable format
11. iostat (Input/Output Statistics)
Purpose: Provides information about CPU and I/O statistics for devices and
partitions.
Common Use Cases:
Monitor disk I/O and CPU performance.
Example:
application linux commands 4
iostat -x 1 # Get extended I/O statistics every 1 second
12. sar (System Activity Report)
Purpose: Collects, reports, and saves system activity information.
Common Use Cases:
Historical performance monitoring.
Track CPU, memory, I/O, and network usage over time.
Example:
sar -u 1 3 # CPU usage every 1 second, 3 times
13. strace (System Trace)
Purpose: Traces system calls and signals of a process.
Common Use Cases:
Debug applications by seeing which system calls are being made.
Troubleshoot issues like file access errors, memory issues, etc.
Example:
strace -p PID # Trace a specific process by its PID
strace command # Trace a command execution
14. uptime
Purpose: Shows how long the system has been running along with system
load averages.
Common Use Cases:
Check the system uptime and load averages.
Example:
application linux commands 5
uptime # Show system uptime and load averages
15. dmesg (Diagnostic Message)
Purpose: Displays system messages, particularly kernel-related ones, useful
for diagnosing hardware and driver issues.
Common Use Cases:
Check boot messages, hardware issues, or error logs.
Example:
dmesg | grep error # Search for error messages in system logs
16. journalctl (Journal Logs)
Purpose: Queries logs collected by systemd 's journal service.
Common Use Cases:
View logs for system services or applications.
Filter and search logs by severity, time, or service.
Example:
journalctl -u service_name # Show logs for a specific service
journalctl --since "2024-11-10" # Show logs since a specific date
17. watch
Purpose: Executes a command repeatedly at a specified interval and shows
the output in the terminal.
Common Use Cases:
Monitor a command’s output in real-time, like df or ps .
Example:
application linux commands 6
watch -n 1 df -h # Refresh disk usage every second
18. curl / wget
Purpose: Command-line tools for transferring data via URLs (HTTP/HTTPS,
FTP, etc.).
Common Use Cases:
Test web applications, APIs, and network connections.
Example:
curl -I <https://example.com> # Show HTTP headers of a URL
wget <https://example.com> # Download a file from a URL
19. systemctl (Systemd Manager)
Purpose: Used to manage systemd services and their states.
Common Use Cases:
Start, stop, restart, or check the status of services.
Example:
systemctl status service_name # Show service status
systemctl restart service_name # Restart a service
20. find
Purpose: Searches for files and directories based on specified conditions
(name, size, type, etc.).
Common Use Cases:
Locate files in a large filesystem or based on specific criteria.
Example:
application linux commands 7
find /path/to/dir -name "*.log" # Find all .log files
find /path/to/dir -type f -size +100M # Find files larger than 100MB
Conclusion
These are just a few of the many Linux tools that can assist in monitoring,
managing, and debugging applications in a DevOps environment. Each of these
tools helps you interact with
the system in a way that aids performance monitoring, troubleshooting, and
resource management. Depending on your specific needs, these commands can
be invaluable when diagnosing issues or improving application reliability.
application linux commands 8