Linux Cheat Sheet
Contents
command cheatsheet
| |
shell
for loop
| |
time
| |
set timezone
| |
| |
use RTC in UTC
| |
System clock synchronized
| |
copy to clipboard
| |
sort
options
| -k [n, m] | 选择区间 |
| -t | g分隔符 |
| -M | 排序月份 |
| -n | 以数值型进行排序 |
| -h | 可读的数字(带单位) |
| -f | 忽略大小写 |
example
path
get script path
| |
get invocation path
| |
background
start a bg process and kill it
| |
sed
replace
| |
-i- Edit a file and don't write the output to stdout.s- The substitute command.///- Delimiter character. It can be any character but usually the slash (/) character is used.g- Global replacement flag. All occurrences are replaced ifgprovided.
awk
- NOTE use '' instead of "" !
| |
tmux
config
| |
options
- start
tmux new -s *SESSION_NAME* - attach
tmux a -t *SESSION_NAME* - detach
send-prefix d - create window
send-prefix c - show sessions
tmux list-sessions
jobs
list background process
jobs
environment
condition
中括号
单中括号 [ ]
[ ]两个符号左右都要有空格分隔- 内部操作符与操作变量之间要有空格:如 [ "a" = "b" ]
- 字符串比较中,> < 需要写成> \< 进行转义
[ ]中字符串或者${}变量尽量使用""双引号扩住,以避免值未定义引用而出错[ ]中可以使用 –a –o 进行逻辑运算[ ]是 shell 内置命令
双中括号
[[ ]]两个符号左右都要有空格分隔[[ ]]内部操作符与操作变量之间要有空格:如[[ "a" = "b" ]][[ ]]字符串比较中,可以直接使用 > < 无需转义[[ ]]中字符串或者${}变量尽量使用"" 双引号扩住,如未使用""会进行模式和元字符匹配[[ ]]内部可以使用 && || 进行逻辑运算[[ ]]是 bash keyword
example
| |
| |
exist
environment variable
- check if a environment variable is set
| |
command
- check if a command exists
| |
文件夹或文件
文件夹
| |
文件
| |
find files
| |
xargs
多行转单行输入, 默认分隔符为换行
| |
placeholder
| |
stream
| symbol | meanings |
| 0 | stdin |
| 1 | stdout |
| 2 | stderr |
| 2>&1 | stderr to stdout |
| 1> | stdout redirect |
| 2> | stderr redirect |
| 1>/dev/null | write to void |
uniq
仅输出 unique 行
| |
grep & rg
grep
no ignore
| |
zip
zip
compress
- -q 不显示命令
- -r 递归
- -y 不解析 symbol link
| |
decompress
| |
list
| |
tar
compress
| |
decompress
| |
git disable zsh status
| |
zsh keybind
^Fctrl-F^[Falt-F
list
| |
kernel
dependencies
| |
build
| |
get current kernel config
| |
kernel boot command
| |
network
iw
- 格式
| |
- 搜索
| |
- 显示设备
| |
- 显示设备信息
| |
- 显示连接信息
| |
- 连接
| |
iwd
connect
| |
Network Manager
- 扫描
| |
- 显示
| |
- 连接
| |
- connection up/down
| |
ubcsecure
| |
iwd configuration
| |
ss
- ss is the alternative of netstat
| |
High DPI
Netease Music
| |
ghidra
| |
| |
user management
add user
| |
create home directory
| |
add sudo access
| |
groups
list groups
| |
add user to a group
| |
sudo
list user's privilege
| |
show login sessions
| |
show login history
| |
| |
set password
| |
ssh pem
- 生成密钥
| |
- 修改权限
| |
- 拷贝密钥
| |
remove user
| |
change shell
| |
ssh
sshd
| |
ssh client
| |
execute command
| |
Xorg
names
xprop
wmctrl
| |
touchpad
change scroll speed
| |
Archlinux
pacman
- refresh pgp
sudo pacman-key --refresh-keys
auto remove
- sudo pacman -R $(pacman -Qdtq)
install deb
| |
install image
| |
makepkg
install
-s, --syncdepsinstall dependencies-i, --installinstall package
| |
yay
| option | description |
| -S | install |
| -Ss | search the package |
| –mflags –skipinteg | skip validaty check |
| -R | remove |
| -Rs | Remove dependencies not required by other packages |
| -Sc | remove all cache |
| –overwrite <glob> | Bypass file conflict checks and overwrite conflicting files |
| –editmenu | edit pkgbuild before install |
| -Ql | show package contents |
| -Qo | show file owner |
| -Qi | show package info |
Bluetooth
install
| |
pair
$ bluetoothctl # power on # default-agent # scan on [NEW] Device 00:12:34:56:78:90 Air Pods # pair 00:12:34:56:78:90 # connect 00:12:34:56:78:90
airpods
| |
module
show loaded
| |
install/load
| |
remove
| |
nouveau
blacklist
| |
Remove kms from the HOOKS array in /etc/mkinitcpio.conf
regenerate the initramfs
| |
keyboard layout
xmodmap
caps_lock -> control
| |
setxkbmap -option caps:ctrl_modifier
| |
gpg
migrate
list keys
| |
export
| |
import
| |
restart gpg-agent
| |
restart
disk
format usb
| |
install ISO
dd if=/archlinux-x86_64.iso of=/dev/sda bs=4M status=progress && sync
swap file
| |
misc
disable tab bell
| |
open terminal here
| |
font
utf-8 & locale
check
| |
set
| |
or
| |
show fonts
| |
systemd daemon
user
| |
system
| |
journalctl
kernel log
| |
per service log
| |
recent first / reverse
| |
CRLF
CR - Carriage Return
- \r, 0x0D in hexadecimal, 13 in decimal
- moves the cursor to the beginning of the line without advancing to the next line
LF - Line Feed
- \n, 0x0A in hexadecimal, 10 in decimal
- moves the cursor down to the next line without returning to the beginning of the line
Trouble Shooting
Read-only file system
- check permission
mount | grep ' / ' - remount
mount -o remount,rw /