Infrastructure Knowledge Base
β¬
Back to Infrastructure KB
π§ Linux Basics & Commands
This section covers essential Linux commands used in daily system administration and troubleshooting.
π File & Directory Management
| Command |
Usage & Options |
pwd |
Print working directory |
ls -l |
List files in long format (permissions, owner, size, date); -l β long format |
ls -a |
List all files including hidden files; -a β all |
cd /path |
Change directory to specified path |
mkdir test |
Create a new directory named βtestβ |
rm -rf test |
Remove directory forcefully; -r β recursive, -f β force |
cp file1 file2 |
Copy file1 to file2 |
mv file1 file2 |
Move or rename file |
π File Viewing
| Command |
Usage & Options |
cat file.txt |
Display full file content |
less file.txt |
View file page by page (scrollable) |
head -n 10 file.txt |
Show first 10 lines; -n β number of lines |
tail -f file.txt |
Show last lines and follow live updates; -f β follow (real-time) |
π Permissions
| Command |
Usage & Options |
chmod 755 file.sh |
Change file permissions; 7 β owner (rwx), 5 β group (r-x), 5 β others (r-x) |
chown user:user file.txt |
Change file ownership; user:user β owner:group |
π€ User Management
| Command |
Usage & Options |
useradd testuser |
Create a new user |
passwd testuser |
Set password for user |
id testuser |
Show user ID, group ID, and groups |
π Process Management
| Command |
Usage & Options |
ps aux |
Show all running processes; a β all users, u β detailed format, x β background processes |
top |
Real-time process monitoring |
kill -9 PID |
Terminate process forcefully; -9 β SIGKILL |
π Networking
| Command |
Usage & Options |
ip a |
Show IP address and network interfaces |
ping google.com |
Check network connectivity |
ss -tulnp |
Show listening ports and services; -t β TCP, -u β UDP, -l β listening, -n β numeric, -p β process info |
πΎ Disk Usage
| Command |
Usage & Options |
df -h |
Show disk space usage; -h β human readable (MB/GB) |
du -sh * |
Show size of files/directories; -s β summary, -h β human readable |
lsblk |
List block devices: disks, partitions |
π Logs
| Command |
Usage & Options |
journalctl -xe |
View system logs; -x β detailed explanation, -e β jump to end |
dmesg |
Show kernel logs: boot/system messages |
π₯ Useful Command
| Command |
Usage & Options |
watch -n 1 "df -h" |
Run command every 1 second, monitor disk usage in real-time; -n β interval in seconds |