Daily Shaarli
May 4, 2025
Finding System Information
cat /etc/redhat-release→ Red Hat versionuname -a→ Linux hostname, kernel, architecturedmidecode→ hardware, BIOS, system infoarch→ x86_64 or i386/32-bit
Common Keyboard Shortcuts
Ctrl + U→ erase command lineCtrl + C→ stop/kill current commandCtrl + Z→ suspend commandCtrl + D→ exit interactive session
Record Terminal Session
-
script mylog.log→ record shell session- Use
exitto stop recording
- Use
Root Password Recovery
- Reboot → enter GRUB menu
- Press
e→ edit boot params - Add
rd.breakat end of kernel line Ctrl + Xto boot- Mount root with
chroot /sysroot passwd root→ change passwordtouch /.autorelabel→ SELinux relabeling on reboot
View Environment Variables
printenv,echo $PATH,echo $SHELL
Set Environment Variables
- Temporary:
export TEST=1,echo $TEST -
Permanent:
vi ~/.bashrc TEST=123 export TEST
Global → vi /etc/profile or /etc/bashrc
-
Basic Replace Syntax:
-
sed -i 's/KENNY/LENNY/g' filename -
Substitute all occurrences of "KENNY" with "LENNY"
-
-
Delete Line Containing String:
sed -i '/SEINFELD/d' filename
-
Delete Empty Lines:
sed -i '/^$/d' filename
-
Delete First Line:
sed '1d' filename
-
sed '1,2d' filename→ delete the first two lines -
sed 's/\t/ /g' filename→ replace tabs with spaces -
sed -n '12,18p' filename→ print only lines 12 to 18 -
sed '12,18d' filename→ delete lines 12 to 18 -
sed G filename→ insert an empty line after every line -
sed '8!s/seinfeld/S1/' filename→ replace "seinfeld" with "S1" on every line except line 8
Crontab Basics
crontab -e→ edit crontabcrontab -l→ list crontab entriescrontab -r→ remove crontab entriessystemctl status crond→ check crond service status
AT: One-time Scheduled Tasks
- Used to schedule jobs only once.
Scheduling Examples:
at HH:MM PM→ schedule a job interactively-
at 11:23AM 12/24/25- Enter job (e.g.,
echo "test") and pressCtrl + Dto finish
- Enter job (e.g.,
at 2:45PM 01/30/25at 4PM + 4 daysat now + 5 hoursat 8:00AM Sunat 10:00AM next month
Managing AT Jobs
atq→ list the scheduled at jobsatrm #→ remove a specific at job (use number fromatq)systemctl status atd→ check atd daemon status
Disk and Memory Info
df→ disk partition infodf -h→ human-readable formatdu→ size of file/directoryfree→ memory infocat /proc/cpuinfo→ CPU infocat /proc/meminfo→ memory info
System Logs & Diagnostics
dmesg→ check kernel ring buffer logsiostat→ check disk I/O statsip route | column -t→ check routing tabless→ view open ports/sockets
Log Directory Structure
-
Logs in
/var/log/boot→ startup recordschronyd→ NTP infocron→ cron jobsmaillog→ mail daemonsecure→ login/logout trackingmessages→ general trace logshttpd→ web server errors
Log Monitoring
tail -f filename→ follow log file in real time
System Shutdown & Boot Control
shutdown→ graceful shutdowninit 0-6→ runlevels (0=off, 3=multi-user, 6=reboot)reboot→ reboot systemhalt→ force shutdown immediately
Hostname Management
cat /etc/hostname→ current hostnamehostnamectl set-hostname myhostname→ change hostname
-
Essential Commands:
useradd,groupadd,userdel,groupdel,usermod- Modify 3 files:
/etc/passwd,/etc/group,/etc/shadow
Create User with Custom Options
useradd -G mygroup -s /bin/bash \
-c "User Description" -m \
-d "/home/myuser" myuser
Other Useful User Commands
useradd myuser→ create userid myuser→ check if user existsgroupadd→ create groupcat /etc/group→ check groupuserdel -r myuser→ delete user and home directorygroupdel mygroup→ delete groupusermod -G mygroup myuser→ change user's groupchgrp -R mygroup myuser→ change group ownership recursivelypasswd myuser→ set or update user's password
Password Aging with chage
-
chage→ manage password aging-m→ minimum days-M→ maximum days-d→ last password change-I→ inactive days-E→ expiration date-W→ warning days
-
Example:
chage -M 5 -M 90 -W 10 -I 10 username
Edit Password Policies
-
File:
/etc/login.defsPASS_MAX_DAYS 9999PASS_MIN_DAYS 0PASS_MIN_LEN 5PASS_WARN_AGE 7
Switch User Privileges
-
visudo→ edit sudo permissions config (/etc/sudoers)- Add user to
wheelgroup for sudo access
- Add user to
usermod -aG wheel myuser→ grant sudo rights
User Info and Monitoring Commands
who→ see logged in userslast→ list last login recordsw→ who is logged in with more detailsfinger→ show user detailsid→ show UID, GID and groupsid myuser→ check user info
Send Messages to Users
-
wall→ broadcast message to all users- Type message, then
Ctrl + Dto send
- Type message, then
-
write myuser→ send message to specific user- Type message, then
Ctrl + Dto send
- Type message, then
Basic System Info Commands
uptime→ time, uptime, users, load averagehostname→ current hostnameip hostname→ show IP & hostnameuname -a→ current OS and kernel infowhich command→ path to a command-
cal→ calendar for current month/yearcal 2025→ full year
bc→ basic calculator
System Monitoring
systemctl→ interact with systemd system managerps→ view current processestop→ dynamic view of process usage
Systemctl Usage
systemctl start|stop|status servicename.service→ manage service statesystemctl enable servicename.service→ start service at bootsystemctl restart|reload servicename→ restart or reload servicesystemctl list-units --all→ list all units-
To add a service:
- Create a unit file in
/etc/systemd/system/servicename.service
- Create a unit file in
Process Management
-
Start a process in the background:
Ctrl + Zthenjobs→ suspend and backgroundbg→ continue in backgroundfg→ bring back to foreground
-
Run process detached from terminal:
nohup process &→ keep running after logoutnohup process > /dev/null 2>&1 &→ suppress all logs/output
Killing and Prioritizing
pkill name→ kill process by name-
nice→ start process with a priority (range -20 to 19)- lower = higher priority
nice -20 top
Jobs Monitoring
jobs→ list background/foreground job states
Vi Editor Commands
i→ insert modeI→ insert at line startESC→ escape to command modeR→ replace modex→ delete characterdd→ delete lineyy→ copy linep→ pastev→ visual modeo→ open new line below and insertO→ open new line above and inserta→ append after cursorA→ append at end of line:q!→ quit without saving:wqorZZ→ save and quit