Top các alias thường sử dụng trong Linux shell

Hệ thống

Xem nhanh thông tin về bộ nhớ RAM và CPU.

alias cpuinfo='lscpu'
alias meminfo='/usr/bin/free -m -l -t'

Xem thông tin về các process đang chạy.

alias psls='/bin/ps auxf | less'

Các lệnh thao tác trên file & thư mục

Lệnh ls hiển thị màu sắc, luôn hiện thị thư mục lên đầu và ngày tháng theo format YYYY-MM-DD HH:MM.

alias ls='/bin/ls --color=always --group-directories-first --time-style="+%Y-%m-%d %H:%M"'

Một số lệnh rút gọn cho ls.

alias sl='ls'
alias l='ls'
alias ll='ls -l'
alias la='ls -a'
alias lla='ls -la'

Các lệnh thao tác file/thư mục giống trên Windows.

alias cd.='builtin cd .'
alias cd..='builtin cd ..'
alias md='mkdir -i'
alias del='rm -i'
alias ren='mv -i'
alias dir='ls -l'
alias deltree='rm -r'
alias cls='reset'
alias path='echo -e ${PATH//:/\\n}'

Nén và giải nén nhanh với định dạng tar.bz2.

alias jc='tar -Pjcvf'
alias jx='tar -Pjxvf'

Yêu cầu wget tải tiếp nếu file tải về đang còn dang dở do lần download trước đó. N

alias wget='wget -c --show-progress'

Yêu cầu giữ lại thông tin của file nguồn (thời gian, user, group và mode) trên file đích khi copy file bằng cp, download qua scp hoặc đồng bộ bằng rsync.

# Preserves timestamp, ownership and mode from the original file
alias cp='cp -p'
alias scp='scp -p'
alias rsync='rsync -ah --info=progress2'

Network

Kiểm tra các port đang được listen.

alias ports='sudo /bin/netstat -tulanp'

Tạo nhanh một HTTP web server đơn giản và listen tại port 8888, host tại thư mục hiện thời. Ví dụ mình muốn share một file nào đó thì HTTP là giao thức dễ tiếp cận nhất vì chỉ cần mở web browser là đủ. Tuy nhiên lưu ý nhớ cấu hình firewall cho phép incoming traffic tới port 8888.

alias www='python -m SimpleHTTPServer 8888'

Hiện thị WAN IP (Public IP) của modem.

alias myip='curl ipinfo.io/ip'

Dành cho ‘sudoer’

Chạy lại lệnh trước đó với sudo mà không cần gõ lại.

 # run the previous command with 'sudo'
alias fuck='sudo ${BASH} -c "$(builtin history -p !!)"'

Giải phóng bộ nhớ RAM.

 alias drop_caches='sudo ${SHELL} -c "sync; echo 3 > /proc/sys/vm/drop_caches; swapoff -a; swapon -a"'

Tự động thêm sudo vào một số lệnh thường dùng.

# no need to type sudo for the following commands
for cmd in \
    shutdown poweroff halt reboot \
    iptables fdisk apt systemct
do
    eval "alias ${cmd}='sudo $(which ${cmd})'"
done

Chạy ứng dụng dưới quyền root.

# run a GTK application as super user
alias gksudo='/usr/bin/pkexec env DISPLAY=${DISPLAY} XAUTHORITY=${XAUTHORITY} HOME=${HOME}'

Cập nhật hệ thống (Debian)

alias update='sudo ${BASH} -c "for arg in update upgrade dist-upgrade autoremove; do apt \$arg -y || exit 1; done; read -p \"Reboot the system now? [yN]\" -n 1 -r && [[ \$REPLY =~ ^[Yy]\$ ]] && reboot"'

Gỡ cài đặt những package bị lỗi.

# Force purge a broken package
alias dpkg_purge='sudo dpkg --purge --force-depends --force-remove-reinstreq'

Phản hồi về bài viết

Cùng thảo luận chút nhỉ!

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.