alias l="ls -al" → define alias
unalias l → remove alias
Persistent Alias Config
User-specific: ~/.bashrc
Global: /etc/bashrc
Add: alias l="ls -al" at end of file
Save file
Command History
Location: ~/.bash_history
View: history
Recall specific: !4 → run whoami (4th command in history)
Screen (Terminal Multiplexer)
Multi-terminal sessions in one window
Alt+a | → split vertical
Alt+a Shift+s → split horizontal
Alt+a Tab → switch windows
Alt+a c → create new session
screen -r → reconnect to detached session
screen -r [id] → recover session by ID
TMUX (Terminal Multiplexer)
Ctrl+b Shift+% → split window horizontally
Ctrl+b d → detach session
Ctrl+b Arrow Keys → move between panes
Ctrl+b Shift+" → split window vertically
tmux ls → list sessions
tmux a → resume last session
tmux new -s name → create named session
Ctrl+b c → new window
Ctrl+b n → switch to next window
tmux attach-session -t 0 → attach session ID 0
Ctrl+b , → rename window
tmux kill-session -t 0 → kill session ID 0
TMUX Advanced Commands
tmux new -s name → new named session
Ctrl+b c → new window
Ctrl+b n → switch to next window
tmux attach-session -t 0 → attach session 0
Ctrl+b , → rename window
tmux kill-session -t 0 → kill session 0
chmod u+s xyz.sh → add SetUID (user-level special permission)
chmod g+s xyz.sh → add SetGID (group-level special permission)
chmod u-s xyz.sh → remove SetUID
chmod g-s xyz.sh → remove SetGID
find / -perm /6000 -type f → find all executables with SetUID/SetGID
⚠️ SetUID/SetGID works only for C/C++ compiled binaries, not Bash scripts.
Sticky Bit
Finding System Information
cat /etc/redhat-release → Red Hat version
uname -a → Linux hostname, kernel, architecture
dmidecode → hardware, BIOS, system info
arch → x86_64 or i386/32-bit
Common Keyboard Shortcuts
Ctrl + U → erase command line
Ctrl + C → stop/kill current command
Ctrl + Z → suspend command
Ctrl + D → exit interactive session
Record Terminal Session
Root Password Recovery
Reboot → enter GRUB menu
Press i → edit boot params in grub, go to line with ro
Add rd.break at end of kernel line (after quiet)
Ctrl + X to boot
Mount root with chroot /sysroot
passwd root → change password
touch /.autorelabel → SELinux relabeling on reboot
View Environment Variables
printenv, echo $PATH, echo $SHELL
Set Environment Variables
Global → vi /etc/profile or /etc/bashrc
Disk and Memory Info
df → disk partition info
df -h → human-readable format
du → size of file/directory
free → memory info
cat /proc/cpuinfo → CPU info
cat /proc/meminfo → memory info
System Logs & Diagnostics
dmesg → check kernel logs
iostat → check disk I/O stats
ip route | column -t → check routing table
ss → view open ports/sockets
Log Directory Structure
Logs in /var/log/
boot → startup records
chronyd → NTP info
cron → cron jobs
maillog → mail daemon
secure → login/logout tracking
messages → general trace logs /hard/soft/proc
httpd → web server errors
Log Monitoring
tail -f filename → follow log file in real time
System Shutdown & Boot Control
shutdown → graceful shutdown
init 0-6 → runlevels (0=off, 3=multi-user, 6=reboot)
reboot → reboot system
halt → force shutdown immediately
Hostname Management
cat /etc/hostname → current hostname
hostnamectl set-hostname myhostname → change hostname
Basic System Info Commands
uptime → time now, up since, numbers of users, load average
hostname → ip hostname
uname -a → current OS and kernel info
which command → path to a command
cal → calendar for current month/year
cal 2025 → full year
bc → basic calculator
System Monitoring
systemctl → see system manager
ps → view current processes
top → dynamic view of process usage
Systemctl Usage
systemctl start|stop|status servicename.service → manage service state
systemctl enable servicename.service → start service at boot
systemctl restart|reload servicename → restart or reload service
systemctl list-units --all → list all units
To add a service:
Create a unit file in /etc/systemd/system/servicename.service
Process Management
Killing and Prioritizing
Jobs Monitoring
jobs → list background/foreground job states
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 user
id myuser → check if user exists
groupadd → create group
cat /etc/group → check group
userdel -r myuser → delete user and home directory
groupdel mygroup → delete group
usermod -G mygroup myuser → change user's group
chgrp -R mygroup myuser → change group ownership recursively
passwd myuser → set or update user's password
Password Aging with chage
Edit Password Policies
File: /etc/login.defs
PASS_MAX_DAYS 9999
PASS_MIN_DAYS 0
PASS_MIN_LEN 5
PASS_WARN_AGE 7
Switch User Privileges
User Info and Monitoring Commands
who → see logged in users
last → list last login records
w → who is logged in with more details
finger → show user details
id → show UID, GID and groups
id myuser → check user info
Send Messages to Users
Basic Replace Syntax:
Delete Line Containing String:
sed -i '/SEINFELD/d' filename
Delete Empty Lines:
Delete First Line:
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/S/' filename → replace "seinfeld" with "S" on every line except line 8
Vi Editor Commands
i → insert mode
ESC → escape to command mode
r → replace mode
x → delete character
dd → delete line
yy → copy line
p → paste
v → visual mode
o → open new line below and insert
O → open new line above and insert
a → append after cursor
A → append at end of line
:q! → quit without saving
:wq or ZZ → save and quit
Crontab Basics
crontab -e → edit crontab
crontab -l → list crontab entries
crontab -r → remove crontab entries
systemctl status crond → check crond service status
AT: One-time Scheduled Tasks
Used to schedule jobs only once.
Scheduling Examples:
Managing AT Jobs
atq → list the scheduled at jobs
atrm # → remove a specific at job (use number from atq)
systemctl status atd → check atd daemon status
ps Command
ps → Current shell process status
ps -e → All running processes
ps aux → All in BSD style with details
ps -ef → Running process with details
ps -u root → Processes of specific user
ps -ef | grep ? → Find process with specific id
top Command
top -u username → Show only that user's processes
top then c → Absolute path
top then k → Kill by PID
top then m or then p → Sort by memory or process usage
kill Commands
kill -l → List all signals
kill PID → Default terminate
kill -1 → Restart
kill -2 → Equivalent to Ctrl+C
kill -9 → Force kill
kill -15 → Graceful kill
killall → Kill all processes by name
pkill → Kill by process name
touch one two three → Create 3 files
mkdir folder → Make directory
mv -R / cp -R → Move or copy folder including subfolders
find . -name "george" → Search from current directory
locate → Faster, but relies on a database
updatedb → Update the locate database
Wildcards
Symbol
Meaning
*
Zero or more characters
?
Single character
[]
Range of characters
\
Escape character
^
Beginning of the line
\$
End of the line
File Display Commands
cat → Show entire content
cat -A → Show non-printable characters
more → Paginate output
less → Same as more but allows navigation with arrow keys
head → Show top lines (default: 10)
tail → Show bottom lines (default: 10)
head -2 myfile
tail -2 myfile
Filters / Text Processing Input
cut → Cut input
awk → List by columns
grep & egrep → Search by keyword
sort → Sort in alphabetical order
uniq → Remove duplicate lines
wc → Word count (including lines)
cut Command Examples
cut -c1 filename → First letter of each line
cut -c1,2,4 filename → Characters 1, 2, and 4
cut -c1-3 filename → Range: characters 1 to 3
cut -c1-3,6-8 filename → Ranges: characters 1-3 and 6-8
cut -b1-3 filename → Byte range 1 to 3
cut -d: -f6 /etc/passwd → Field 6 using : delimiter
cut -d: -f6-7 → Fields 6 and 7
ls -l | cut -c2-4 → Extract character range 2 to 4 from ls output
awk Command Examples
Extract fields from a file or an output
awk '{print $1}' file → Print 1st column of file
ls -l | awk '{print $1, $3}' → Print 1st and 3rd columns from ls -l
ls -l | awk '{print $NF}' → Print last column
awk '/jerry/ {print}' file → Search for "jerry" and print matching lines
awk -F: '{print $1}' /etc/passwd → Use : as delimiter, print 1st field
echo "hello tom" | awk '{$2="adam"; print}' → Replace column 2 with "adam"
awk 'length($0) > 15' file → Print lines longer than 15 characters
`awk '{print NF}' → Number of colum
grep Command Examples
grep keyword file → Search for keyword
grep -c keyword file → Count matching lines
grep -i keyword file → Ignore case sensitive
grep -n keyword file → Show line numbers
grep -v keyword file → Invert match (everything except keyword)
grep keyword file | awk '{print $1}' → Pipe grep to awk to extract 1st column
ls -l | grep keyword → Filter ls -l output by keyword
egrep -i "keyword1|keyword2" file → Search for multiple keywords (case-insensitive)
sort Command Examples
sort file → Sort alphabetically
sort -r file → Sort in reverse order
sort -u file → Sort and remove duplicates
sort file | uniq → Same as above with explicit uniq
sort file | uniq -d → Show only duplicate lines
sort file | uniq -c → Count duplicates
sort -k4 -n file → Sort by 4th field (numeric)
ls -l | sort -k4 -n → Sort by size from ls -l
wc Command Examples
wc -c filename → Byte count
wc -w filename → Word count
wc -l filename → Line count
ls -l | wc -l → Count lines from ls -l
wc -l filename → Count number of lines in file
cmp / diff
diff → Compare files line by line
cmp → Compare files byte by byte
tar / gzip
tar cvf export.tar somedir → Compress directory
tar xvf export.tar → Extract tar archive
gzip export.tar → Compress with gzip
gzip -d export.tar.gz → Decompress gzip archive
truncate Command
truncate -s10 filename → Chop file to 10 bytes
truncate -s60 filename → Extend file to 60 bytes
Combining & Splitting Files
cat file1 file2 file3 > fileN → Combine multiple files into one
File Ownership
chown → Change ownership
chgrp → Change group
Access Control List (ACL)
setfacl → Set file ACL
getfacl → Get file ACL
Add Permission to User
setfacl -m u:user:rwx /path/to/file
setfacl -m g:group:rw /path/to/file
Recursive Inheritance from Folder
setfacl -R -m entry /path/to/dir
Remove Specific ACL Entry
setfacl -x u:user /path/to/file
Remove All ACL Entries
setfacl -b /path/to/file
Check ACL
ls -ltr
Example output:
-rw-rw-r--+
Help Commands
whatis command
command --help
man command
Add Text to a File
echo "my text" > myfile # Overwrite
cat myfile # Read the text
echo "hello" >> myfile # Append
Input and Output Redirects
3 Redirect Types
stdin → 0 → < or << → Feeding file content to a command
stdout → 1 → > or >>
stderr → 2 → 2> or 2>> → Write error output to a file
tee Command
echo "test" | tee myfile
tee -a file # Append
Links
Soft Link (Symbolic Link)
ln -s
Link will be removed if the original file is removed or renamed.
Hard Link
ln
Deleting, renaming, or moving the original file will not affect the hard link.
Diagram
INODE ← MYFILE.TXT → MY-SOFT-LINK
↑
MY HARD LINK
Command to check links:
ls -ltri
File Permissions
Permission Types
Symbol
Permission
Example (Mnemonic)
R
Read
Riri (4)
W
Write
Winnie (2)
X
Execute
Xena (1)
Each Permission (R, W, X) Can Be Controlled at Three Levels
U → User
G → Group
O → Others (Everyone)
Permission Strings
Example:
-rwxrwxrwx
| | |
| | └── Others
| └───── Group
└───────── User
To remove write permission from all:
chmod a-w filename
To add read and write permission for user:
chmod u+rw filename
Directory Permissions
Example:
drwxrwxrwx
^ ^ ^
| | └── Others
| └───── Group
└───────── User
Numeric Permission Mapping
Value
Permissions
Symbol
Mnemonic
0
No permission
---
1
Execute
--x
Xena
2
Write
-w-
Winnie
3
Execute + Write
-wx
4
Read
r--
Riri
5
Read + Execute
r-x
6
Read + Write
rw-
7
Read + Write + Exec
rwx
Example to set permissions:
chmod 764 file
Breakdown:
User (7) → rwx
Group (6) → rw-
Others (4) → r--
ls -l → List
pwd → Print working directory
dr-xr-xr-x
|
directories
-rw-r--r--
|
file
Linux File Types
Symbol
Type
-
Regular file
d
Directory
l
Link
c
Special file or device file
s
Socket → Network communication / process data between external processes
p
Named pipe → FIFO → First In First Out, data between internal processes
b
Block device
Inode = Pointer or number of a file on a hard disk.
Directory
Description
/boot
Grub.cfg
/root
home of root
/dev
system device (mouse, keyboard)
/etc
configuration files
/bin → /usr/bin
everyday user commands
/sbin → /usr/sbin
system/filesystem commands
/opt
third party app (not part of os)
/proc
running process (only in memory)
/lib → /usr/lib
C prog lib
/tmp
temporary folder
/home
user dir
/var
system logs
/run
system daemon → store temporary runtime / PID file
/mnt
mount external file system
/media
CDrom
Fold
Fold all
Expand
Expand all
Are you sure you want to delete this link?
Are you sure you want to delete this tag?
The personal, minimalist, super-fast, database free, bookmarking service by the Shaarli community