0% found this document useful (0 votes)
26 views5 pages

DevOps Linux Commands Exercises

The document provides a comprehensive guide on essential Linux commands specific to DevOps, covering system resource usage, network troubleshooting, disk space management, log monitoring, process management, service control, boot history, Docker troubleshooting, file permissions, and package issues. Each section includes practical exercises to reinforce learning and application of the commands. The commands are designed to help users effectively manage and troubleshoot Linux systems in a DevOps environment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views5 pages

DevOps Linux Commands Exercises

The document provides a comprehensive guide on essential Linux commands specific to DevOps, covering system resource usage, network troubleshooting, disk space management, log monitoring, process management, service control, boot history, Docker troubleshooting, file permissions, and package issues. Each section includes practical exercises to reinforce learning and application of the commands. The commands are designed to help users effectively manage and troubleshoot Linux systems in a DevOps environment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

DevOps Specific Linux Commands with

Examples and Practice Exercises


1. Check System Resource Usage
$ top
Real-time view of system processes and resource usage.

$ htop
Interactive process viewer (may need to install: `sudo apt install htop`).

$ free -m
Display memory usage in megabytes.

$ vmstat 1 5
Show system performance metrics at 1-second intervals (5 times).

Practice Exercise:

Run each command and note the CPU, memory usage, and top processes on your system.

2. Troubleshoot Network Connectivity


$ ping google.com
Check if the host is reachable.

$ curl -I https://yourdomain.com
Check HTTP response headers.

$ ss -tuln
List active listening ports and sockets.

$ traceroute google.com
Trace route to a domain.

$ telnet smtp.gmail.com 587


Check connectivity to a specific port.

$ dig yourdomain.com
Check DNS resolution and records.

Practice Exercise:
Try pinging, using curl, and tracerouting a public domain like example.com. Observe the
outputs.

3. Check Disk Space and Inodes


$ df -h
Show human-readable disk space usage.

$ du -sh /var/log/*
Show sizes of each directory under /var/log.

$ lsblk
List all block devices.

$ find / -xdev -type f -size +100M


Find files larger than 100MB.

$ stat /var/log/syslog
Show file metadata.

Practice Exercise:

Identify which directories are consuming the most disk space.

4. Monitor Logs and File Changes


$ tail -f /var/log/syslog
Live monitor system logs.

$ grep -i error /var/log/nginx/error.log


Search for 'error' (case-insensitive).

$ less +F /var/log/messages
Scrollable real-time file viewer.

$ watch -n 2 ls -l /tmp/myfile
Watch a file for changes.

$ journalctl -u nginx
View logs for nginx service.

Practice Exercise:

Monitor a log file in real-time while generating events (like restarting a service).
5. Check Running Processes
$ ps aux | grep java
Find all Java processes.

$ pgrep -fl nginx


Find nginx process details.

$ pstree -p
Visualize process tree with PIDs.

$ kill -9 1234
Forcefully kill a process by PID.

Practice Exercise:

Start a background process and locate it using ps/pgrep, then terminate it.

6. Manage Services
$ systemctl status nginx
Check status of nginx service.

$ systemctl restart nginx


Restart nginx service.

$ systemctl is-enabled nginx


Check if nginx starts on boot.

Practice Exercise:

Stop and start a service on your system and verify its status using systemctl.

7. Boot and Shutdown History


$ uptime
Show system uptime.

$ last reboot
List previous reboot events.

$ who -b
Display last boot time.
$ dmesg | tail
Show last few kernel ring buffer messages.

Practice Exercise:

Check when your system was last rebooted and find any recent hardware/kernel messages.

8. Docker/Container Troubleshooting
$ docker ps -a
List all containers.

$ docker logs <container_id>


View logs of a container.

$ docker exec -it <container_id> bash


Access shell inside a container.

$ docker inspect <container_id>


View container metadata.

Practice Exercise:

Create a simple container, inspect it, and check its logs.

9. File Permissions and Ownership


$ ls -l /var/www/
List permissions of files and directories.

$ chmod 755 /var/www/html


Change permissions.

$ chown nginx:nginx /var/www/html


Change ownership.

$ getfacl /var/www/html
View ACL-based permissions.

Practice Exercise:

Create a file, change its permissions and ownership, then verify.


10. Package and Library Issues
$ which python3
Find path of the binary used.

$ ldd /usr/bin/curl
Check shared libraries used.

$ strace -p 1234
Trace system calls of a running process.

$ dpkg -l | grep nginx


Check if nginx is installed (Debian/Ubuntu).

$ yum list installed | grep nginx


Check if nginx is installed (RHEL/CentOS).

Practice Exercise:

Trace a running process using `strace` and find library dependencies using `ldd`.

You might also like