Skip to content

Instantly share code, notes, and snippets.

@Pymmdrza
Last active April 25, 2026 14:00
Show Gist options
  • Select an option

  • Save Pymmdrza/d224e58a5659fd702446cd917fb6296f to your computer and use it in GitHub Desktop.

Select an option

Save Pymmdrza/d224e58a5659fd702446cd917fb6296f to your computer and use it in GitHub Desktop.
Bash Aliases
# Owner : Mmdrza.Com <https://mmdrza.com>
# Support : Mmdrza.Support <https://mmdrza.support>
# Github : @Pymmdrza <https://github.com/Pymmdrza>
# Telegram : @Mr1Mmdrza <https://mr1mmdrza.t.me>
# Email : Pymmdrza@gmail.com
# Bitcoin : 1MMDRZAcM6dzmdMUSV8pDdAPDFpwzve9Fc
# -----------------------------------------------------------
#
# DONATIONS:
#
# To directly support the author of this code source and provide encouragement,
# you can send your donations in Bitcoin to the following wallet address;
# this action will strengthen their motivation:
#
# 1MMDRZAcM6dzmdMUSV8pDdAPDFpwzve9Fc
#
# If you do not provide support, using this code is still permitted without any issues,
# provided that you do not make any changes to it and preserve the author's name.
# -----------------------------------------------------------
# ============================================================
# General Bash Aliases and Helper Functions
# ============================================================
# Reload shell configuration
alias reload='source ~/.bashrc'
alias reloadbash='source ~/.bashrc'
# Edit shell files
alias bashrc='nano ~/.bashrc'
alias aliases='nano ~/.bash_aliases'
alias editaliases='nano ~/.bash_aliases'
# Clear terminal
alias c='clear'
alias cls='clear'
# Exit shortcuts
alias q='exit'
alias quit='exit'
# Show this aliases file
alias showaliases='cat ~/.bash_aliases'
# ============================================================
# Safer Defaults
# ============================================================
# Ask before overwrite or delete
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
# Create parent directories automatically
alias mkdir='mkdir -pv'
# Human-readable sizes
alias df='df -h'
alias du='du -h'
# Safer permissions display
alias chmodx='chmod +x'
# ============================================================
# ls Improvements
# ============================================================
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias lla='ls -lah'
alias lh='ls -lh'
alias lt='ls -lah --sort=time'
alias ltr='ls -lah --sort=time --reverse'
alias lsize='ls -lahS'
alias ldir='ls -lah | grep "^d"'
alias lfiles='ls -lah | grep "^-"'
alias lhidden='ls -ld .?* 2>/dev/null'
# ============================================================
# Navigation
# ============================================================
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias home='cd ~'
alias root='cd /'
alias tmp='cd /tmp'
alias opt='cd /opt'
alias var='cd /var'
alias logdir='cd /var/log'
alias www='cd /var/www'
alias etc='cd /etc'
alias back='cd -'
mkcd() {
if [ -z "$1" ]; then
echo "Usage: mkcd <directory>"
return 1
fi
mkdir -p "$1" && cd "$1"
}
# ============================================================
# File Viewing
# ============================================================
alias catn='cat -n'
alias less='less -R'
alias more='less'
alias head20='head -n 20'
alias head50='head -n 50'
alias tail20='tail -n 20'
alias tail50='tail -n 50'
alias tailf='tail -f'
alias tailf100='tail -n 100 -f'
viewn() {
if [ -z "$1" ]; then
echo "Usage: viewn <file>"
return 1
fi
nl -ba "$1" | less -R
}
# ============================================================
# Searching
# ============================================================
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
search() {
if [ -z "$1" ]; then
echo "Usage: search <text> [path]"
return 1
fi
local text="$1"
local path="${2:-.}"
grep -RIn --color=auto "$text" "$path"
}
findname() {
if [ -z "$1" ]; then
echo "Usage: findname <name> [path]"
return 1
fi
local name="$1"
local path="${2:-.}"
find "$path" -iname "*$name*" 2>/dev/null
}
findext() {
if [ -z "$1" ]; then
echo "Usage: findext <extension> [path]"
return 1
fi
local ext="$1"
local path="${2:-.}"
find "$path" -type f -iname "*.${ext}" 2>/dev/null
}
bigfiles() {
local path="${1:-.}"
local size="${2:-100M}"
find "$path" -type f -size +"$size" -exec ls -lh {} \; 2>/dev/null | awk '{ print $9 ": " $5 }'
}
recent() {
local path="${1:-.}"
local days="${2:-1}"
find "$path" -type f -mtime -"${days}" -print 2>/dev/null
}
# ============================================================
# Disk and Directory Usage
# ============================================================
alias disks='lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT,MODEL'
alias mounts='mount | column -t'
alias usage='du -sh ./* 2>/dev/null | sort -h'
alias usageall='du -ah . 2>/dev/null | sort -h'
alias topdirs='du -h --max-depth=1 2>/dev/null | sort -h'
alias freespace='df -hT'
bigdirs() {
local path="${1:-.}"
du -h --max-depth=1 "$path" 2>/dev/null | sort -hr | head -n 20
}
# ============================================================
# Process Management
# ============================================================
alias psg='ps aux | grep -i --color=auto'
alias ports='ss -tulpn'
alias listen='ss -tulpn'
alias processes='ps aux --sort=-%mem | head -n 20'
alias topmem='ps aux --sort=-%mem | head -n 20'
alias topcpu='ps aux --sort=-%cpu | head -n 20'
alias pst='pstree -ap 2>/dev/null || ps axjf'
killname() {
if [ -z "$1" ]; then
echo "Usage: killname <process-name>"
return 1
fi
pkill -i "$1"
}
# ============================================================
# System Information
# ============================================================
alias sysinfo='uname -a && lsb_release -a 2>/dev/null || cat /etc/os-release'
alias osinfo='cat /etc/os-release'
alias kernel='uname -r'
alias uptimeinfo='uptime'
alias meminfo='free -h'
alias cpuinfo='lscpu'
alias ipinfo='ip addr show'
alias routeinfo='ip route show'
alias hostnameinfo='hostnamectl'
status() {
echo "===== System ====="
hostnamectl 2>/dev/null || hostname
echo
echo "===== Uptime ====="
uptime
echo
echo "===== Memory ====="
free -h
echo
echo "===== Disk ====="
df -hT
echo
echo "===== Top Memory Processes ====="
ps aux --sort=-%mem | head -n 10
}
# ============================================================
# Network
# ============================================================
alias myip='curl -fsS https://ifconfig.me && echo'
alias myip2='curl -fsS https://api.ipify.org && echo'
alias localip="hostname -I | awk '{print \$1}'"
alias flushdns='sudo resolvectl flush-caches 2>/dev/null || sudo systemd-resolve --flush-caches 2>/dev/null'
headers() {
if [ -z "$1" ]; then
echo "Usage: headers <url>"
return 1
fi
curl -I -L "$1"
}
httpcode() {
if [ -z "$1" ]; then
echo "Usage: httpcode <url>"
return 1
fi
curl -o /dev/null -s -w "%{http_code}\n" "$1"
}
portcheck() {
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: portcheck <host> <port>"
return 1
fi
timeout 5 bash -c "cat < /dev/null > /dev/tcp/$1/$2" \
&& echo "Open" \
|| echo "Closed or filtered"
}
dns() {
if [ -z "$1" ]; then
echo "Usage: dns <domain>"
return 1
fi
dig "$1"
}
dnsa() {
if [ -z "$1" ]; then
echo "Usage: dnsa <domain>"
return 1
fi
dig +short A "$1"
}
dnscname() {
if [ -z "$1" ]; then
echo "Usage: dnscname <domain>"
return 1
fi
dig +short CNAME "$1"
}
dnstxt() {
if [ -z "$1" ]; then
echo "Usage: dnstxt <domain>"
return 1
fi
dig +short TXT "$1"
}
dnsall() {
if [ -z "$1" ]; then
echo "Usage: dnsall <domain>"
return 1
fi
echo "A:"
dig +short A "$1"
echo
echo "AAAA:"
dig +short AAAA "$1"
echo
echo "CNAME:"
dig +short CNAME "$1"
echo
echo "MX:"
dig +short MX "$1"
echo
echo "TXT:"
dig +short TXT "$1"
echo
echo "NS:"
dig +short NS "$1"
}
# ============================================================
# Logs
# ============================================================
alias logs='cd /var/log && ls -lah'
alias syslog='sudo tail -n 100 -f /var/log/syslog'
alias authlog='sudo tail -n 100 -f /var/log/auth.log'
alias kernlog='sudo tail -n 100 -f /var/log/kern.log'
alias jctl='journalctl -xe'
alias jctlf='journalctl -f'
alias jboot='journalctl -b'
alias jerr='journalctl -p err -b'
slog() {
if [ -z "$1" ]; then
echo "Usage: slog <service>"
return 1
fi
sudo journalctl -u "$1" --no-pager -n 200
}
slogf() {
if [ -z "$1" ]; then
echo "Usage: slogf <service>"
return 1
fi
sudo journalctl -u "$1" -f
}
# ============================================================
# Services / systemd
# ============================================================
alias services='systemctl list-units --type=service --state=running'
alias failed='systemctl --failed'
alias timers='systemctl list-timers --all'
sstatus() {
if [ -z "$1" ]; then
echo "Usage: sstatus <service>"
return 1
fi
systemctl status "$1"
}
sstart() {
if [ -z "$1" ]; then
echo "Usage: sstart <service>"
return 1
fi
sudo systemctl start "$1"
}
sstop() {
if [ -z "$1" ]; then
echo "Usage: sstop <service>"
return 1
fi
sudo systemctl stop "$1"
}
srestart() {
if [ -z "$1" ]; then
echo "Usage: srestart <service>"
return 1
fi
sudo systemctl restart "$1"
}
sreload() {
if [ -z "$1" ]; then
echo "Usage: sreload <service>"
return 1
fi
sudo systemctl reload "$1"
}
senable() {
if [ -z "$1" ]; then
echo "Usage: senable <service>"
return 1
fi
sudo systemctl enable "$1"
}
sdisable() {
if [ -z "$1" ]; then
echo "Usage: sdisable <service>"
return 1
fi
sudo systemctl disable "$1"
}
# ============================================================
# Package Management
# ============================================================
alias aptup='sudo apt update'
alias aptug='sudo apt update && sudo apt upgrade -y'
alias aptin='sudo apt install -y'
alias aptrm='sudo apt remove -y'
alias aptpurge='sudo apt purge -y'
alias aptsearch='apt search'
alias aptshow='apt show'
alias aptclean='sudo apt autoremove -y && sudo apt autoclean'
alias aptfix='sudo apt --fix-broken install'
alias aptmanual='apt-mark showmanual'
installtools() {
sudo apt update
sudo apt install -y \
curl \
wget \
jq \
git \
unzip \
zip \
p7zip-full \
dnsutils \
psmisc \
net-tools \
htop \
tree \
xclip \
ca-certificates \
gnupg \
lsb-release \
openssl
}
# ============================================================
# Permissions and Ownership
# ============================================================
alias perms='stat -c "%A %a %U:%G %n"'
alias own='stat -c "%U:%G %n"'
chownme() {
if [ -z "$1" ]; then
echo "Usage: chownme <path>"
return 1
fi
sudo chown -R "$USER:$USER" "$1"
}
fixdirs755() {
local path="${1:-.}"
find "$path" -type d -exec chmod 755 {} \;
}
fixfiles644() {
local path="${1:-.}"
find "$path" -type f -exec chmod 644 {} \;
}
# ============================================================
# Archives
# ============================================================
extract() {
if [ -z "$1" ]; then
echo "Usage: extract <archive>"
return 1
fi
if [ ! -f "$1" ]; then
echo "File not found: $1"
return 1
fi
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.tar.xz) tar xJf "$1" ;;
*.tar) tar xf "$1" ;;
*.tbz2) tar xjf "$1" ;;
*.tgz) tar xzf "$1" ;;
*.zip) unzip "$1" ;;
*.gz) gunzip "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.xz) unxz "$1" ;;
*.7z) 7z x "$1" ;;
*) echo "Unsupported archive type: $1"; return 1 ;;
esac
}
targz() {
if [ -z "$1" ]; then
echo "Usage: targz <path>"
return 1
fi
tar czf "$1.tar.gz" "$1"
}
zipdir() {
if [ -z "$1" ]; then
echo "Usage: zipdir <directory>"
return 1
fi
zip -r "$1.zip" "$1"
}
# ============================================================
# Git Helpers
# ============================================================
alias g='git'
alias gs='git status'
alias ga='git add'
alias gaa='git add .'
alias gc='git commit'
alias gcm='git commit -m'
alias gp='git push'
alias gl='git pull'
alias gb='git branch'
alias gba='git branch -a'
alias gco='git checkout'
alias gcb='git checkout -b'
alias gd='git diff'
alias gds='git diff --staged'
alias glog='git log --oneline --graph --decorate --all'
alias gstash='git stash'
alias gstashp='git stash pop'
alias groot='git rev-parse --show-toplevel 2>/dev/null'
# ============================================================
# Docker Helpers
# ============================================================
alias dps='docker ps'
alias dpsa='docker ps -a'
alias di='docker images'
alias dlog='docker logs'
alias dlogf='docker logs -f'
alias dexec='docker exec -it'
alias dstopall='docker stop $(docker ps -q)'
alias drmstop='docker container prune -f'
alias dclean='docker system prune -f'
alias dcleanall='docker system prune -a -f --volumes'
dcsh() {
if [ -z "$1" ]; then
echo "Usage: dcsh <container>"
return 1
fi
docker exec -it "$1" sh
}
dcbash() {
if [ -z "$1" ]; then
echo "Usage: dcbash <container>"
return 1
fi
docker exec -it "$1" bash
}
alias dc='docker compose'
alias dcup='docker compose up -d'
alias dcdown='docker compose down'
alias dcrestart='docker compose restart'
alias dclogs='docker compose logs'
alias dclogsf='docker compose logs -f'
alias dcps='docker compose ps'
# ============================================================
# Nginx / Apache Helpers
# ============================================================
alias ngt='sudo nginx -t'
alias ngr='sudo systemctl reload nginx'
alias ngrestart='sudo systemctl restart nginx'
alias ngstatus='systemctl status nginx'
alias nglogs='sudo journalctl -u nginx --no-pager -n 100'
alias nglogsf='sudo journalctl -u nginx -f'
alias ngconf='sudo nginx -T'
alias a2status='systemctl status apache2'
alias a2restart='sudo systemctl restart apache2'
alias a2reload='sudo systemctl reload apache2'
alias a2logs='sudo journalctl -u apache2 --no-pager -n 100'
alias a2logsf='sudo journalctl -u apache2 -f'
alias a2conf='sudo apache2ctl -S'
# ============================================================
# Security and Firewall
# ============================================================
alias ufws='sudo ufw status verbose'
alias ufwa='sudo ufw status numbered'
alias iptableslist='sudo iptables -S'
alias nftlist='sudo nft list ruleset'
alias sshfailed='sudo grep "Failed password" /var/log/auth.log 2>/dev/null | tail -n 50'
alias sshaccepted='sudo grep "Accepted" /var/log/auth.log 2>/dev/null | tail -n 50'
alias lastlogins='last -a | head -n 30'
# ============================================================
# Environment Variables
# ============================================================
alias envs='printenv'
alias path='echo "$PATH" | tr ":" "\n"'
prtenv() {
if [ -z "$1" ]; then
echo "Usage: prtenv <pattern>"
return 1
fi
printenv | grep -E "$1"
}
prtenvs() {
if [ -z "$1" ]; then
echo "Usage: prtenvs <pattern>"
return 1
fi
printenv | grep -E "$1" | sed -E \
-e 's/(TOKEN=).+/\1********/' \
-e 's/(SECRET=).+/\1********/' \
-e 's/(PASSWORD=).+/\1********/' \
-e 's/(PASS=).+/\1********/' \
-e 's/(KEY=).+/\1********/'
}
has() {
if [ -z "$1" ]; then
echo "Usage: has <command>"
return 1
fi
command -v "$1" >/dev/null 2>&1 && echo "yes" || echo "no"
}
cmdpath() {
if [ -z "$1" ]; then
echo "Usage: cmdpath <command>"
return 1
fi
command -v "$1"
}
# ============================================================
# JSON Helpers
# ============================================================
alias jqpretty='jq .'
json() {
if [ -z "$1" ]; then
echo "Usage: json <file>"
return 1
fi
jq . "$1"
}
jsonkeys() {
if [ -z "$1" ]; then
echo "Usage: jsonkeys <file>"
return 1
fi
jq 'keys' "$1"
}
# ============================================================
# Date and Time
# ============================================================
alias now='date "+%Y-%m-%d %H:%M:%S"'
alias nowutc='date -u "+%Y-%m-%dT%H:%M:%SZ"'
alias timestamp='date +%s'
alias today='date "+%Y-%m-%d"'
fromts() {
if [ -z "$1" ]; then
echo "Usage: fromts <timestamp>"
return 1
fi
date -d "@$1"
}
# ============================================================
# History
# ============================================================
alias h='history'
alias hg='history | grep -i'
alias hclear='history -c && history -w'
histg() {
if [ -z "$1" ]; then
echo "Usage: histg <pattern>"
return 1
fi
history | grep -i "$1"
}
# ============================================================
# Text Utilities
# ============================================================
alias lines='wc -l'
alias countdups='sort | uniq -c | sort -nr'
alias noblank='grep -v "^$"'
trimspace() {
if [ -z "$1" ]; then
echo "Usage: trimspace <file>"
return 1
fi
sed -i 's/[[:space:]]*$//' "$1"
}
# ============================================================
# File Safety Helpers
# ============================================================
bak() {
if [ -z "$1" ]; then
echo "Usage: bak <file-or-directory>"
return 1
fi
if [ ! -e "$1" ]; then
echo "Path not found: $1"
return 1
fi
cp -a "$1" "$1.bak.$(date +%Y%m%d_%H%M%S)"
}
randpass() {
local length="${1:-32}"
openssl rand -base64 "$length" | tr -d '\n'
echo
}
randhex() {
local bytes="${1:-32}"
openssl rand -hex "$bytes"
}
# ============================================================
# Python / Node Helpers
# ============================================================
alias py='python3'
alias pip='python3 -m pip'
alias venv='python3 -m venv .venv'
alias activate='source .venv/bin/activate'
alias ni='npm install'
alias nr='npm run'
alias ns='npm start'
alias nt='npm test'
# ============================================================
# Convenience
# ============================================================
alias pwdc='pwd | tr -d "\n"'
alias copypwd='pwd | xclip -selection clipboard 2>/dev/null || pwd'
alias aliaseslist='alias'
alias functionslist='declare -F'
alias tree1='tree -L 1'
alias tree2='tree -L 2'
alias tree3='tree -L 3'
# ============================================================
# Checks
# ============================================================
nettoolscheck() {
echo "curl: $(command -v curl >/dev/null 2>&1 && echo yes || echo no)"
echo "wget: $(command -v wget >/dev/null 2>&1 && echo yes || echo no)"
echo "jq: $(command -v jq >/dev/null 2>&1 && echo yes || echo no)"
echo "dig: $(command -v dig >/dev/null 2>&1 && echo yes || echo no)"
echo "git: $(command -v git >/dev/null 2>&1 && echo yes || echo no)"
echo "docker: $(command -v docker >/dev/null 2>&1 && echo yes || echo no)"
echo "tree: $(command -v tree >/dev/null 2>&1 && echo yes || echo no)"
echo "xclip: $(command -v xclip >/dev/null 2>&1 && echo yes || echo no)"
echo "pstree: $(command -v pstree >/dev/null 2>&1 && echo yes || echo no)"
echo "zip: $(command -v zip >/dev/null 2>&1 && echo yes || echo no)"
echo "unzip: $(command -v unzip >/dev/null 2>&1 && echo yes || echo no)"
echo "7z: $(command -v 7z >/dev/null 2>&1 && echo yes || echo no)"
}
# ============================================================
# Built-in Help
# ============================================================
aliaseshelp() {
cat <<'EOF'
Available commands:
Reload:
reload
reloadbash
Edit:
bashrc
aliases
editaliases
Clear and exit:
c
cls
q
quit
Listing:
l
la
ll
lla
lh
lt
ltr
lsize
ldir
lfiles
lhidden
Navigation:
..
...
....
.....
home
root
tmp
opt
var
logdir
www
etc
back
mkcd <directory>
Viewing:
catn <file>
head20 <file>
head50 <file>
tail20 <file>
tail50 <file>
tailf <file>
tailf100 <file>
viewn <file>
Search:
search <text> [path]
findname <name> [path]
findext <extension> [path]
bigfiles [path] [size]
recent [path] [days]
Disk:
disks
mounts
usage
usageall
topdirs
freespace
bigdirs [path]
Processes:
psg <name>
ports
listen
processes
topmem
topcpu
killname <name>
pst
System:
sysinfo
osinfo
kernel
uptimeinfo
meminfo
cpuinfo
ipinfo
routeinfo
hostnameinfo
status
Network:
myip
myip2
localip
flushdns
headers <url>
httpcode <url>
portcheck <host> <port>
dns <domain>
dnsa <domain>
dnscname <domain>
dnstxt <domain>
dnsall <domain>
Logs:
logs
syslog
authlog
kernlog
jctl
jctlf
jboot
jerr
slog <service>
slogf <service>
Services:
services
failed
timers
sstatus <service>
sstart <service>
sstop <service>
srestart <service>
sreload <service>
senable <service>
sdisable <service>
APT:
aptup
aptug
aptin <package>
aptrm <package>
aptpurge <package>
aptsearch <package>
aptshow <package>
aptclean
aptfix
aptmanual
installtools
Permissions:
perms <path>
own <path>
chownme <path>
fixdirs755 [path]
fixfiles644 [path]
Archives:
extract <archive>
targz <path>
zipdir <directory>
Git:
g
gs
ga
gaa
gc
gcm
gp
gl
gb
gba
gco
gcb
gd
gds
glog
gstash
gstashp
groot
Docker:
dps
dpsa
di
dlog <container>
dlogf <container>
dexec <container> <command>
dcsh <container>
dcbash <container>
dstopall
drmstop
dclean
dcleanall
dc
dcup
dcdown
dcrestart
dclogs
dclogsf
dcps
Nginx:
ngt
ngr
ngrestart
ngstatus
nglogs
nglogsf
ngconf
Apache:
a2status
a2restart
a2reload
a2logs
a2logsf
a2conf
Security:
ufws
ufwa
iptableslist
nftlist
sshfailed
sshaccepted
lastlogins
Environment:
envs
path
prtenv <pattern>
prtenvs <pattern>
has <command>
cmdpath <command>
JSON:
jqpretty
json <file>
jsonkeys <file>
Date:
now
nowutc
timestamp
today
fromts <timestamp>
History:
h
hg <pattern>
hclear
histg <pattern>
Text:
lines <file>
countdups
noblank
trimspace <file>
Safety:
bak <path>
randpass [length]
randhex [bytes]
Python:
py
pip
venv
activate
Node:
ni
nr
ns
nt
Convenience:
pwdc
copypwd
aliaseslist
functionslist
tree1
tree2
tree3
nettoolscheck
showaliases
aliaseshelp
EOF
}
# ============================================================
# End of file
# ============================================================

Bash Aliases Usage Reference

This Guide Lists the Available Commands From the ~/.bash_aliases File, with Short Usage Examples.

Latest Bash Aliases : Source v1.1


Table of Contents

  1. Reload and Edit Shell Configuration
  2. Clear and Exit
  3. Safer File Operations
  4. Disk Usage
  5. ls Shortcuts
  6. Navigation
  7. File Viewing
  8. Search and Find
  9. Disk and Directory Usage Helpers
  10. Process Management
  11. System Information
  12. Network
  13. Logs
  14. systemd Services
  15. Package Management
  16. Permissions and Ownership
  17. Archives
  18. Git Helpers
  19. Docker Helpers
  20. Nginx Helpers
  21. Apache Helpers
  22. Security and Firewall
  23. Environment Variables
  24. JSON Helpers
  25. Date and Time
  26. History
  27. Text Utilities
  28. File Safety Helpers
  29. Python Helpers
  30. Node.js Helpers
  31. Convenience
  32. Checks
  33. Built-in Help
  34. Common Practical Examples
  35. Donations

1. Reload and Edit Shell Configuration

Reload the current Bash configuration.

source ~/.bashrc

Reload Bash configuration using the short alias.

reload

Reload Bash configuration using the alternative alias.

reloadbash

Open .bashrc for editing.

bashrc

Open .bash_aliases for editing.

aliases

Open .bash_aliases for editing using the alternative alias.

editaliases

Show the current .bash_aliases file.

showaliases

2. Clear and Exit

Clear the terminal screen.

c

Clear the terminal screen using the alternative alias.

cls

Exit the current shell session.

q

Exit the current shell session using the alternative alias.

quit

3. Safer File Operations

Copy a file with confirmation before overwrite.

cp source.txt target.txt

Move or rename a file with confirmation before overwrite.

mv oldname.txt newname.txt

Remove a file with confirmation before deletion.

rm file.txt

Run the original cp command without the alias.

\cp source.txt target.txt

Run the original mv command without the alias.

\mv oldname.txt newname.txt

Run the original rm command without the alias.

\rm file.txt

Create a directory and show what was created.

mkdir new-directory

Create nested directories and show what was created.

mkdir nested/path/example

Make a script executable.

chmodx script.sh

4. Disk Usage

Show disk usage in human-readable format.

df

Show file or directory size in human-readable format.

du file-or-directory

Show total size of a directory.

du -sh directory-name

Show size of all items in the current directory.

du -sh ./*

5. ls Shortcuts

List files in compact format.

l

List all files except . and ...

la

List files with details and type indicators.

ll

List all files with human-readable sizes.

lla

List files with human-readable sizes.

lh

List files sorted by modification time.

lt

List files sorted by modification time in reverse order.

ltr

List files sorted by size.

lsize

List directories only.

ldir

List regular files only.

lfiles

List hidden files only.

lhidden

6. Navigation

Go up one directory.

..

Go up two directories.

...

Go up three directories.

....

Go up four directories.

.....

Go to the home directory.

home

Go to the root directory.

root

Go to /tmp.

tmp

Go to /opt.

opt

Go to /var.

var

Go to /var/log.

logdir

Go to /var/www.

www

Go to /etc.

etc

Go back to the previous directory.

back

Create a directory and enter it.

mkcd new-directory

Create a nested directory and enter it.

mkcd nested/path/example

7. File Viewing

Show a file with line numbers.

catn file.txt

View a file with less.

less file.txt

View a file using the more alias.

more file.txt

Show the first 20 lines of a file.

head20 file.txt

Show the first 50 lines of a file.

head50 file.txt

Show the last 20 lines of a file.

tail20 file.txt

Show the last 50 lines of a file.

tail50 file.txt

Follow a log file in real time.

tailf file.log

Follow a log file in real time and show the last 100 lines first.

tailf100 file.log

View a file with numbered lines through less.

viewn file.txt

8. Search and Find

Search inside a file with colored output.

grep "text" file.txt

Search recursively from the current directory.

grep -R "text" .

Search with extended regular expressions.

egrep "pattern" file.txt

Search for a fixed literal string.

fgrep "literal-text" file.txt

Search recursively for text in the current directory.

search "text"

Search recursively for text in a specific path.

search "text" /path/to/search

Find files or directories by name in the current directory.

findname "filename"

Find files or directories by name in a specific path.

findname "filename" /path/to/search

Find files by extension in the current directory.

findext "log"

Find files by extension in a specific path.

findext "php" /var/www

Find files larger than 100 MB in the current directory.

bigfiles

Find files larger than 100 MB in a specific path.

bigfiles /var/log

Find files larger than a custom size.

bigfiles /var/www 50M

Find very large files under root.

bigfiles / 500M

Find files modified in the last 1 day.

recent

Find files modified in the last 1 day in a specific path.

recent /var/www

Find files modified in the last 7 days in a specific path.

recent /var/www 7

9. Disk and Directory Usage Helpers

Show block devices with size, filesystem, mountpoint, and model.

disks

Show mounted filesystems in table format.

mounts

Show size of items in the current directory.

usage

Show size of all files and directories recursively.

usageall

Show top-level directory sizes.

topdirs

Show free disk space and filesystem type.

freespace

Show largest directories in the current path.

bigdirs

Show largest directories in a specific path.

bigdirs /var

Show largest directories under a website path.

bigdirs /var/www

10. Process Management

Search running processes by name.

psg nginx

Search running PHP processes.

psg php

Search running SSH processes.

psg ssh

Show listening ports and related processes.

ports

Show listening ports using the alternative alias.

listen

Show top processes by memory usage.

processes

Show top memory-consuming processes.

topmem

Show top CPU-consuming processes.

topcpu

Kill processes by name.

killname process-name

Kill nginx processes by name.

killname nginx

Kill PHP processes by name.

killname php

Show process tree.

pst

11. System Information

Show general system information.

sysinfo

Show operating system information.

osinfo

Show kernel version.

kernel

Show uptime.

uptimeinfo

Show memory usage.

meminfo

Show CPU information.

cpuinfo

Show IP addresses.

ipinfo

Show routing table.

routeinfo

Show hostname and system identity information.

hostnameinfo

Show a quick system status overview.

status

12. Network

Show public IP address.

myip

Show public IP address using an alternative service.

myip2

Show the first local IP address.

localip

Flush DNS resolver cache when supported.

flushdns

Show HTTP headers for a URL.

headers https://example.com

Show HTTP headers for a URL path.

headers https://example.com/path

Show only the HTTP status code for a URL.

httpcode https://example.com

Show only the HTTP status code for a URL path.

httpcode https://example.com/path

Check if a TCP port is open.

portcheck example.com 80

Check if HTTPS port is open.

portcheck example.com 443

Check if local SSH port is open.

portcheck 127.0.0.1 22

Run a full DNS lookup.

dns example.com

Show A records.

dnsa example.com

Show CNAME records.

dnscname www.example.com

Show TXT records.

dnstxt example.com

Show common DNS records together.

dnsall example.com

13. Logs

Go to /var/log and list log files.

logs

Follow syslog.

syslog

Follow authentication log.

authlog

Follow kernel log.

kernlog

Show recent systemd journal errors and context.

jctl

Follow systemd journal in real time.

jctlf

Show logs from the current boot.

jboot

Show errors from the current boot.

jerr

Show recent logs for a service.

slog nginx

Show recent logs for Apache.

slog apache2

Show recent logs for SSH.

slog ssh

Show recent logs for Docker.

slog docker

Follow logs for a service.

slogf nginx

Follow Apache logs.

slogf apache2

Follow SSH logs.

slogf ssh

Follow Docker logs.

slogf docker

14. systemd Services

List running services.

services

Show failed services.

failed

Show all systemd timers.

timers

Show status of a service.

sstatus nginx

Show status of Apache.

sstatus apache2

Show status of SSH.

sstatus ssh

Show status of Docker.

sstatus docker

Start a service.

sstart nginx

Start Apache.

sstart apache2

Start SSH.

sstart ssh

Start Docker.

sstart docker

Stop a service.

sstop nginx

Stop Apache.

sstop apache2

Stop SSH.

sstop ssh

Stop Docker.

sstop docker

Restart a service.

srestart nginx

Restart Apache.

srestart apache2

Restart SSH.

srestart ssh

Restart Docker.

srestart docker

Reload a service without full restart when supported.

sreload nginx

Reload Apache.

sreload apache2

Enable a service at boot.

senable nginx

Enable Apache at boot.

senable apache2

Enable SSH at boot.

senable ssh

Enable Docker at boot.

senable docker

Disable a service at boot.

sdisable nginx

Disable Apache at boot.

sdisable apache2

Disable Docker at boot.

sdisable docker

15. Package Management

Update package indexes.

aptup

Update package indexes and upgrade packages.

aptug

Install one package.

aptin package-name

Install multiple packages.

aptin curl jq git unzip

Remove a package.

aptrm package-name

Purge a package and its configuration.

aptpurge package-name

Search for a package.

aptsearch package-name

Show package details.

aptshow package-name

Remove unused packages and clean package cache.

aptclean

Fix broken package dependencies.

aptfix

Show manually installed packages.

aptmanual

Install common useful terminal tools.

installtools

16. Permissions and Ownership

Show permissions, numeric mode, owner, group, and filename.

perms file.txt

Show permissions for a directory.

perms directory-name

Show owner and group of a file.

own file.txt

Show owner and group of a directory.

own directory-name

Change ownership of a file or directory to the current user.

chownme file-or-directory

Change ownership of a project directory to the current user.

chownme ./project

Set directories to 755 under the current path.

fixdirs755

Set directories to 755 under a specific path.

fixdirs755 /path/to/directory

Set files to 644 under the current path.

fixfiles644

Set files to 644 under a specific path.

fixfiles644 /path/to/directory

17. Archives

Extract a tar.gz archive.

extract archive.tar.gz

Extract a tar.bz2 archive.

extract archive.tar.bz2

Extract a tar.xz archive.

extract archive.tar.xz

Extract a tar archive.

extract archive.tar

Extract a zip archive.

extract archive.zip

Extract a gz file.

extract archive.gz

Extract a bz2 file.

extract archive.bz2

Extract an xz file.

extract archive.xz

Extract a 7z archive.

extract archive.7z

Create a tar.gz archive from a directory.

targz directory-name

Create a tar.gz archive from a file.

targz file-name

Create a zip archive from a directory.

zipdir directory-name

18. Git Helpers

Run git directly through the short alias.

g status

Show Git status.

gs

Add one file to staging.

ga file.txt

Add all changes to staging.

gaa

Create a commit interactively.

gc

Create a commit with a message.

gcm "commit message"

Push commits.

gp

Pull latest changes.

gl

List local branches.

gb

List all branches.

gba

Checkout a branch.

gco branch-name

Create and checkout a new branch.

gcb new-branch-name

Show unstaged diff.

gd

Show staged diff.

gds

Show compact Git log graph.

glog

Stash current changes.

gstash

Apply the latest stash and remove it from stash list.

gstashp

Show Git repository root.

groot

19. Docker Helpers

Show running containers.

dps

Show all containers.

dpsa

Show Docker images.

di

Show logs for a container.

dlog container-name

Follow logs for a container.

dlogf container-name

Execute sh inside a container.

dexec container-name sh

Execute bash inside a container.

dexec container-name bash

Open sh inside a container.

dcsh container-name

Open bash inside a container.

dcbash container-name

Stop all running containers.

dstopall

Remove stopped containers.

drmstop

Prune unused Docker data.

dclean

Prune unused Docker data, images, and volumes.

dcleanall

Run docker compose directly through the short alias.

dc

Show docker compose containers.

dc ps

Show docker compose logs.

dc logs

Start docker compose stack in detached mode.

dcup

Stop docker compose stack.

dcdown

Restart docker compose stack.

dcrestart

Show docker compose logs.

dclogs

Follow docker compose logs.

dclogsf

Show docker compose service status.

dcps

20. Nginx Helpers

Test Nginx configuration.

ngt

Reload Nginx.

ngr

Restart Nginx.

ngrestart

Show Nginx service status.

ngstatus

Show recent Nginx logs.

nglogs

Follow Nginx logs.

nglogsf

Print full Nginx configuration.

ngconf

21. Apache Helpers

Show Apache service status.

a2status

Restart Apache.

a2restart

Reload Apache.

a2reload

Show recent Apache logs.

a2logs

Follow Apache logs.

a2logsf

Show Apache virtual host configuration.

a2conf

22. Security and Firewall

Show UFW status with details.

ufws

Show UFW numbered rules.

ufwa

Show iptables rules.

iptableslist

Show nftables ruleset.

nftlist

Show recent failed SSH login attempts.

sshfailed

Show recent successful SSH logins.

sshaccepted

Show recent login history.

lastlogins

23. Environment Variables

Show all environment variables.

envs

Show PATH entries line by line.

path

Print environment variables matching a pattern.

prtenv PATH

Print HOME environment variable.

prtenv HOME

Print USER environment variable.

prtenv USER

Print environment variables matching sensitive names.

prtenv "TOKEN|SECRET|PASSWORD|KEY"

Print environment variables matching sensitive names with values hidden.

prtenvs "TOKEN|SECRET|PASSWORD|KEY"

Print broader sensitive environment matches with values hidden.

prtenvs "API|TOKEN|SECRET|PASSWORD|PASS|KEY"

Check if a command exists.

has curl

Check if jq exists.

has jq

Check if git exists.

has git

Check if docker exists.

has docker

Check if nginx exists.

has nginx

Show command path.

cmdpath curl

Show jq command path.

cmdpath jq

Show git command path.

cmdpath git

Show docker command path.

cmdpath docker

Show nginx command path.

cmdpath nginx

24. JSON Helpers

Pretty-print JSON from stdin.

jqpretty < file.json

Pretty-print a JSON file.

json file.json

Show top-level JSON keys.

jsonkeys file.json

Pretty-print JSON using a pipe.

cat file.json | jqpretty

25. Date and Time

Show current local date and time.

now

Show current UTC date and time.

nowutc

Show current Unix timestamp.

timestamp

Show today's date.

today

Convert Unix timestamp to readable date.

fromts 1710000000

26. History

Show command history.

h

Search command history.

hg ssh

Search Docker commands in history.

hg docker

Search Nginx commands in history.

hg nginx

Search apt commands in history.

hg apt

Clear shell history.

hclear

Search history using a function.

histg ssh

Search Docker history using a function.

histg docker

Search Nginx history using a function.

histg nginx

Search apt history using a function.

histg apt

27. Text Utilities

Count lines in a file.

lines file.txt

Sort lines and count duplicates.

cat file.txt | countdups

Remove blank lines from output.

cat file.txt | noblank

Trim trailing whitespace from a file.

trimspace file.txt

28. File Safety Helpers

Create a timestamped backup of a file.

bak file.txt

Create a timestamped backup of a directory.

bak directory-name

Generate a random password.

randpass

Generate a random password with custom length.

randpass 32

Generate a longer random password.

randpass 64

Generate a random hex string.

randhex

Generate a random hex string with custom byte length.

randhex 16

Generate a longer random hex string.

randhex 32

29. Python Helpers

Show Python version.

py --version

Run a Python script.

py script.py

Show pip version.

pip --version

Install a Python package.

pip install package-name

Install Python requirements.

pip install -r requirements.txt

Create a Python virtual environment in .venv.

venv

Activate the .venv virtual environment.

activate

30. Node.js Helpers

Install Node.js dependencies.

ni

Install a Node.js package.

ni package-name

Run an npm script.

nr script-name

Run npm build script.

nr build

Run npm dev script.

nr dev

Run npm start script.

nr start

Start a Node.js project.

ns

Run Node.js tests.

nt

31. Convenience

Print current path without a trailing newline.

pwdc

Copy current path to clipboard if xclip exists.

copypwd

Show all aliases.

aliaseslist

Show all shell functions.

functionslist

Show directory tree with depth 1.

tree1

Show directory tree with depth 2.

tree2

Show directory tree with depth 3.

tree3

32. Checks

Check whether common terminal tools are installed.

nettoolscheck

33. Built-in Help

Show built-in help for all aliases and functions.

aliaseshelp

Show the current .bash_aliases file.

showaliases

34. Common Practical Examples

Show quick system overview.

status

Show listening ports.

ports

Show top memory processes.

topmem

Show top CPU processes.

topcpu

Show largest directories under root.

bigdirs /

Show files larger than 500 MB under root.

bigfiles / 500M

Show files modified in /var/log during the last 2 days.

recent /var/log 2

Search for error text in /var/log.

search "error" /var/log

Show Nginx service status.

sstatus nginx

Show recent Nginx logs.

slog nginx

Follow Nginx logs.

slogf nginx

Show HTTP headers for a website.

headers https://example.com

Show HTTP status code for a website.

httpcode https://example.com

Show common DNS records for a domain.

dnsall example.com

Backup Nginx main configuration.

bak /etc/nginx/nginx.conf

Test Nginx configuration.

ngt

Reload Nginx after a successful test.

ngr

Show UFW firewall status.

ufws

Show failed SSH login attempts.

sshfailed

Show recent login history.

lastlogins

Show sensitive environment variable names with hidden values.

prtenvs "TOKEN|SECRET|PASSWORD|PASS|KEY"

Install common useful terminal tools.

installtools

Check whether useful terminal tools are installed.

nettoolscheck

Show the aliases help menu.

aliaseshelp

DONATIONS

To directly support the author of this code source and provide encouragement, you can send your donations in Bitcoin to the following wallet address; this action will strengthen their motivation:

Bitcoin Wallet:

1MMDRZAcM6dzmdMUSV8pDdAPDFpwzve9Fc

If you do not provide support, using this code is still permitted without any issues, provided that you do not make any changes to it and preserve the author's name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment