Shell count number of lines
|
ps -A|wc -l # count all processes
ps -LA|wc -l # count all threads
ps aux|awk '{print $11}'|grep "^\["|wc -l # count all kernel threads
|
Auto mount SSD at bootup
|
Get the uuid of SSD
sudo blkid
ls -al /dev/disk/by-uuid/
Edit the file /etc/fstab
UUID=b071688a-414a-4665-a45e-102432e06315 /media/thanh/ssd ext4 defaults 0 0
Test the fstab file
|
Virtual Display
|
Create /etc/X11/xorg.conf.d/20-intel.conf
Section "Device"
Identifier "intelgpu0"
Driver "intel"
Option "VirtualHeads" "1"
EndSection
Generate modeline with or cvt
cvt 1920 1080
xrandr --newmode "1920x1080_60.00" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync
xrandr --addmode VIRTUAL1 1920x1080_60.00
Activate virtual display: (Replace HDMI1 with your real display)
xrandr --output VIRTUAL1 --mode 1920x1080_60.00 --right-of HDMI1
|
Edit pushed commits
|
git rebase -i HEAD~N # N là số commit muốn chỉnh sữa tính từ commit gần đây nhât.
Edit commit
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
Force push update
|
Network Manager skip managing device
|
# file: /etc/NetworkManager/NetworkManager.conf
# filter by name
[keyfile]
unmanaged-devices=interface-name:interface_1;interface-name:interface_2
# fileter by mac
[keyfile]
unmanaged-devices=mac:00:11:22:33:44:55;mac:66:77:88:99:00:aa
|
Calculation
|
|
Cleanup Disk
|
# Clear systemd journal logs
sudo journalctl --vacuum-time=3d # clear log older 3 days
# Clean snap
set -eu
snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
snap remove "$snapname" --revision="$revision"
done
# remove old kernel
sudo apt-get remove --purge $(dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d')
|
Set timezone
|
# get timezone name
timedatectl list-timezones | grep "Ho"
# set timezone
timedatectl set-timezone Asia/Ho_Chi_Minh
|
Update hardware clock time
|
# read the Hardware Clock
hwclock -r or hwclock --show or hwclock --show --verbose
or hwclock --show --utc
# set data and time
date -s "Fri Mar 3 04:10:53 PM +07 2023" # giá trị lấy từ date command
# Set the Hardware Clock to the current System Time
hwclock --systohc or hwclock -w
|
Các biến script đặc biệt
|
- $0: tên file script đang chạy
- $#: tổng số tham số truyền vào ( = 0 nếu không truyền tham số nào)
- $*: for val in $*; do echo "val: $val"; done : dồn các biến thành 1 biến
- $@: for val in $@; do echo "val: $val"; done : là array của các biến có thể truy cập bằng index
- ${@:2}: lấy từ index thứ 2 cho đến hết
|
Natural sort
|
apt install python3-natsort
docker ps | awk '{print $NF}' | natsort
|