Introduction

The Linux command line is a sysadmin's most powerful tool. This tutorial covers essential commands for navigating, managing, and troubleshooting Linux servers, transforming you from beginner to confident command-line user.

Navigation and File Management

Essential navigation: ls -la (list all files with details), cd /path (change directory), pwd (print working directory), mkdir (create directory), rm -rf (remove recursively - use carefully!). File operations: cp (copy), mv (move/rename), touch (create empty file), cat (view file), less (scrollable view), head/tail (view start/end).

File Permissions and Ownership

Understanding rwx (read, write, execute) for user/group/others. chmod (change mode): numeric (chmod 755 file) or symbolic (chmod u+x file). chown (change owner): chown user:group file. Special permissions: setuid, setgid, sticky bit (/tmp directory).

Process Management

ps aux (all processes), top/htop (interactive monitor), kill (terminate by PID), killall (terminate by name), pkill (pattern match). Job control: & (background), fg (foreground), bg (background), jobs (list). nohup (immune to hangups), disown (remove from shell job control).

Text Processing Power Tools

grep (search patterns): grep -r "text" /path, grep -v (invert), grep -i (case-insensitive). awk (field processing): awk '{print $1}' file. sed (stream editor): sed 's/old/new/g' file. cut (extract columns), sort (sort lines), uniq (unique lines), wc (word count).

Networking Commands

ip addr (interfaces), ss -tulpn (sockets), netstat (traditional). curl/wget (HTTP requests), ping (connectivity), traceroute (routing path), nslookup/dig (DNS queries), nc/netcat (TCP/UDP connections), scp/rsync (secure file transfer).

Disk Management and Monitoring

df -h (disk usage by filesystem), du -sh * (directory sizes), lsblk (block devices), fdisk (partition tool), mount (mount filesystems). Find large files: find / -type f -size +100M -exec ls -lh {} ;. Monitor I/O: iotop, iostat.

System Information and Logs

uname -a (kernel info), dmesg (boot messages), journalctl (systemd logs): journalctl -u nginx -f (follow service logs). Check logs: /var/log/syslog, /var/log/nginx/error.log. Use tail -f for real-time monitoring, grep for filtering.

Package Management

Debian/Ubuntu (apt): apt update (refresh), apt search, apt install, apt upgrade, apt remove --purge. RHEL/CentOS/Rocky (yum/dnf): dnf install, dnf update, dnf remove, dnf search. Source compilation: ./configure, make, make install.

Shell Scripting Basics

Bash scripts: #!/bin/bash shebang. Variables: name="value", echo $name. Conditionals: if [ condition ]; then ... fi. Loops: for i in {1..5}; do echo $i; done. Functions: myfunc() { echo "Hello"; }. Exit codes: exit 0 (success).

Systemd Service Management

systemctl start/stop/restart/reload service-name. systemctl enable (auto-start at boot), systemctl disable. systemctl status service (check status). systemctl list-units (all running units). journalctl -u service for logs. Create custom services: /etc/systemd/system/myservice.service.

Conclusion

Command line mastery is an ongoing journey. Practice daily, refer to man pages (man command), and build automation scripts for repetitive tasks. Learn about cron for scheduling, aliases for shortcuts, and bashrc customization for improved productivity.