Practical Usage of linux Admin Commands in Devops/Cloud Engineer Role

akhil_mittal

akhil mittal

Posted on September 14, 2024

Practical Usage of linux Admin Commands in Devops/Cloud Engineer Role

Linux admin commands are fundamental tools for DevOps and Cloud Engineers, enabling them to manage systems, automate tasks, and troubleshoot issues efficiently. Here are some practical use cases of common Linux admin commands with examples:

1. System Monitoring and Performance

Use Case: Monitor system performance and resource utilization.

Example Command: Using top to monitor CPU and memory usage.

top

Enter fullscreen mode Exit fullscreen mode

Explanation: The top command provides a real-time view of system processes, CPU, and memory usage. This is useful for identifying resource hogs and diagnosing performance issues.

Example Command: Using vmstat to report virtual memory statistics.

vmstat 5
Enter fullscreen mode Exit fullscreen mode

Explanation: The vmstat command shows system performance, including memory, swap, and CPU statistics. The 5 argument specifies an interval of 5 seconds between updates.

2. File and Directory Management

Use Case: Manage files and directories on a server.

Example Command: Using rsync to synchronize files between servers.

rsync -avz /local/directory/ user@remote:/remote/directory/
Enter fullscreen mode Exit fullscreen mode

Explanation: The rsync command synchronizes files and directories between local and remote systems. The -a flag preserves file attributes, -v enables verbose mode, and -z compresses data during transfer.

Example Command: Using find to locate files and directories.

find /var/log -type f -name "*.log"

Enter fullscreen mode Exit fullscreen mode

Explanation: The find command searches for files in the /var/log directory with a .log extension. This is useful for locating specific log files or performing batch operations.

3. Networking

Use Case: Diagnose and manage network connections and configurations.

Example Command: Using netstat to display network connections and listening ports.

netstat -tuln
Enter fullscreen mode Exit fullscreen mode

Explanation: The netstat command shows active network connections and listening ports. The -t flag displays TCP connections, -u shows UDP connections, -l lists listening ports, and -n shows numerical addresses.

Example Command: Using curl to test HTTP endpoints.

curl -I http://example.com

Enter fullscreen mode Exit fullscreen mode

Explanation: The curl command fetches HTTP headers from a URL. The -I flag requests only the headers, which is useful for checking the status of a web service.

4. User and Permissions Management

Use Case: Manage user accounts and file permissions.

Example Command: Using chmod to change file permissions.

chmod 755 /path/to/script.sh

Enter fullscreen mode Exit fullscreen mode

Explanation: The chmod command sets file permissions. The 755 permission allows the owner to read, write, and execute the file, while others can only read and execute.

Example Command: Using chown to change file ownership.

chown user:group /path/to/file.txt

Enter fullscreen mode Exit fullscreen mode

Explanation: The chown command changes the owner and group of a file. This is useful for managing access control and ensuring that files are owned by the correct user and group.

5. Service Management

Use Case: Manage and control system services.

Example Command: Using systemctl to start and stop services.

systemctl start nginx
systemctl stop nginx
systemctl status nginx

Enter fullscreen mode Exit fullscreen mode

Explanation: The systemctl command manages system services. start and stop commands control the service, while status checks its current state.

Example Command: Using service to manage services on older systems.

service apache2 restart

Enter fullscreen mode Exit fullscreen mode

Explanation: The service command restarts the Apache2 service. This is useful for applying configuration changes or troubleshooting issues.

6. Log Management

Use Case: Monitor and analyze system logs.

Example Command: Using tail to view the end of a log file.

tail -f /var/log/syslog

Enter fullscreen mode Exit fullscreen mode

Explanation: The tail command displays the last part of a file. The -f flag follows the file, showing new log entries in real-time.

Example Command: Using grep to search for specific log entries.

grep "ERROR" /var/log/app.log

Enter fullscreen mode Exit fullscreen mode

Explanation: The grep command searches for lines containing the word "ERROR" in the log file. This helps in identifying error messages and troubleshooting issues.

7. Backup and Restore

Use Case: Create and manage backups of important data.

Example Command: Using tar to create a compressed archive.

tar -czf backup.tar.gz /path/to/directory

Enter fullscreen mode Exit fullscreen mode

Explanation: The tar command creates a compressed archive of a directory. The -c flag creates the archive, -z compresses it using gzip, and -f specifies the output file.

Example Command: Using scp to transfer a backup to a remote server.

scp backup.tar.gz user@remote:/backups/

Enter fullscreen mode Exit fullscreen mode

Explanation: The scp command copies files to a remote server over SSH. This is useful for offsite backups and data transfer.

Summary

In a DevOps and Cloud Engineer role, Linux admin commands are vital for managing and automating various aspects of system administration, from monitoring and performance tuning to file management and backup. By using these commands effectively, you can streamline operations, ensure system reliability, and handle complex tasks efficiently.

💖 💪 🙅 🚩
akhil_mittal
akhil mittal

Posted on September 14, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related