Sysadmin's linux CLI commands


The artwork was generated by DALL·E 2

Ah, the command line Linux’s very own battlefield, where the wars of uptime and performance are won and lost in mere keystrokes. If you’re a sysadmin, this isn’t just your toolbox, it’s your Excalibur. Let’s dive into some CLI wizardry that might make you feel a bit like a digital Merlin.

The Power of grep

This command isn’t just a search tool it’s your best friend in the whirlwind world of logs and config files. Need to find all instances of that pesky error in a log file? grep is your hound:

grep "error 404" /var/log/nginx/error_log

The Almighty awk

While grep finds your data, awk slices and dices it. It’s like having a scalpel when performing data surgery. Extract columns, add values, or filter out noise—all in a day’s work for awk:

awk '{print $1,$3}' error_log | sort | uniq

The Stealthy sed

Editing files or slaying unwanted text, sed does it on the fly. Imagine you need to quickly anonymize user emails in a file—sed sneaks in and swaps them out:

sed -i 's/user@domain.com/anonymous@example.com/g' users.txt

The Time-traveling cron

cron is your scheduling wizard. Whether it’s database backups or late-night scripts that keep your systems purring, cron ensures they run on time, every time:

0 3 * * * /usr/bin/backup.sh

The Ever-watchful top and htop

Want to see what’s munching on your server’s resources? top is your lookout. For an even better perspective, htop gives you a colorful, interactive map of the CPU and memory treasure trove.

The Quick-footed scp

Need to securely move files faster than a speeding bullet? scp is your secure courier, making sure your data gets from point A to point B intact:

scp file.txt user@192.168.1.1:/remote/directory

The Master Key ssh

And finally, ssh, the tool that turns the world into your office. Securely connect to any server, any workstation, anywhere if it’s on the network, ssh can get you there, no VPN needed.

ssh -i key.pem user@example.com

The Enigmatic strace

Dive deep into the workings of your programs with strace. This command allows you to trace system calls and signals, giving you a microscopic view of what your application is actually doing behind the scenes. Troubleshoot like a pro, knowing exactly where your application is spending its time or why it’s not behaving as expected:

strace -c -p1234

The Network Whisperer tcpdump

Uncover the secrets of network traffic with tcpdump. This tool is crucial for any sysadmin looking to understand the mysterious world of packets and protocols. Capture and analyze network packets to debug issues, monitor suspicious activities, or ensure that no data leakage is occurring:

tcpdump -i eth0 port 80 -w capture_file.pcap

The Resource Alchemist iotop

Monitor how your system’s input/output is being spent with iotop. For those who need to keep a close eye on disk usage by processes, this tool is invaluable. It helps identify processes that are slowing down your storage devices, allowing you to optimize or troubleshoot as necessary:

iotop -o

The System Sentinel journalctl

Explore system logs like never before with journalctl, part of the systemd suite. This command lets you efficiently sift through your system’s logs, making it easier to pinpoint issues from boot messages to application logs. It’s your go-to for a chronological insight into your system’s soul:

journalctl -u nginx.service --since today

Some others

Directory and File Management Commands

Navigate directories and manage files with precision:

# Display the current working directory
$ pwd

# Change directory to 'my_folder'
$ cd my_folder/

# Create a new directory called 'ngdir'
$ mkdir ngdir

# Move 'testfile' into 'ngdir'
$ mv testfile ngdir/

File Operations

Efficiently copy, remove, and link files within the file system:

# Copy 'testfile' to 'ngdir'
$ cp testfile ngdir/

# Remove 'testfile' from 'ngdir'
$ rm ngdir/testfile

# Create a new blank file named 'newfile'
$ touch newfile

# Create a symbolic link named 'newfile-link' pointing to 'newfile'
$ ln -sv newfile newfile-link

# View the contents of a file and use paging for long files
$ cat /etc/services | less

Examining and Manipulating File Content

Harness the power of cat, echo, and less for file interaction:

# Output the contents of 'newfile'
$ cat newfile

# Display a simple message
$ echo "I love Linux"

# Use 'less' for controlled viewing of large files
$ cat /etc/services | less

System Information and Management

Manage running processes, view system status, and maintain efficient operations:

# Check the running kernel version and system info
$ uname -a

# Find out which user you are logged in as
$ whoami

# Check running processes
$ ps

# Kill a process by ID
$ kill 1234

# Display disk space usage in a human-readable format
$ df -h

Networking and Security

Configure and troubleshoot network settings and security:

# Display all network interfaces and IP addresses
$ ip address show

# Trace the network path to google.com
$ traceroute google.com

# Allow HTTP traffic through the firewall using iptables
$ iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT

As a sysadmin, mastering these commands is like learning the ancient runes that unlock the mysteries of the digital realm. Use them wisely, and watch your kingdom of servers flourish under your vigilant rule. Or just use them to fix stuff when it breaks your call.



Tags: | Words: 935