Linux Command for System Administrator
Basic command for system monitoring
sudo du -a / | sort -n -r | head -n 20
# list disk usagejournalctl | grep "error"
# log messages, kernel messages, and other system-related informationdmesg --ctime | grep error
# Show kernel ring buffersudo journalctl -p 3 -xb
# Check the lock filesudo systemctl --failed
# Service that failed to loaddu -sh .config
# File size of a specific directoryfind . -type f -exec grep -l "/dev/nvme0n1" {} +
# find file and exce command with grep, {} is the output for each & +,\; is the terminator
Reset password (for forgotten password)
Reser Root
init=/bin/bash
# from grub commnad mode, find the kernel line containing linux then add at the end of linux commandctrl+x
orF10
# to save the changes and bootmount -o remount,rw /
# mount the root system for (r,w)passwd
# change the passwordreboot -f
# force reboot, after that you can boot with new passwd you set
Reser User
rw init=/bin/bash
# from grub commnad mode, find the kernel line containing linux then add at the end of linux commandctrl+x
orF10
# to save the changes and bootpasswd username
# change the passwordreboot -f
# force reboot, after that you can boot with new passwd you set
Some useful Command
grep -Irl "akib" .
# this will find file contain akib in the current dirgrep -A 3 -B 3 "nvme" flake.nix
# this will find nvme in flake.nix file with before and after with 3,3 linesed -i "s/akib/withNewText/g" file.txt
# sed will changes the all occurance with new text in a filecat /etc/passwd | column -t -s ":" -N USERNAME,PW,UID,GUID,COMMENT,HOME,INTERPRETER -J -n passwdFile
# will seperate passwd file based on ":" delemeter and show as column format then the "-J" flag will convert it into json filecat /etc/passwd | awk -F: 'BEGIN {printf "user\tPW\tUID\tGUID\tCOMMENT\tHOME\tINTERPRETER\n"} {printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\n", $1, $2, $3, $4, $5, $6, $7}'
cat /etc/passwd | column -t -s ":" -N USERNAME,PW,UID,GUID,COMMENT,HOME,INTERPRETER -H PW -O UID,USERNAME,GUID,COMMENT,HOME,INTERPRETER
# "-H" remove specific column "-O" reorder column