$ rm -i <== 請求確認
$ unalias rm
$ alias update=’sudo apt update’
md () { mkdir -p "$@" && cd "$1"; }
命令編輯及光標移動
$ cd /proc/tty;ls -al光標
$ cd /proc/tty光標;ls -al
歷史命令快速執行
實時查看日志
$ tail -f filename.log
磁盤或內存情況查看
$ df -h /dev/sda14 4.6G 10M 4.4G 1% /tmp /dev/sda11 454M 366M 61M 86% /boot /dev/sda15 55G 18G 35G 35% /home /dev/sda1 256M 31M 226M 12% /boot/efi tmpfs 786M 64K 786M 1% /run/user/1000
$ free -h total used free shared buff/cache available Mem: 7.7G 3.5G 452M 345M 3.7G 3.5G Swap: 7.6G 0B 7.6G
根據名稱查找進程id
1.pgrep hello 2.22692
$ pidof hello 22692
根據名稱殺死進程
$ killall hello
$ pkill hello
查看進程運行時間
$ ps -p 24525 -o lstart,etime STARTED ELAPSED Sat Mar 23 20:52:08 2019 02:45
快速目錄切換
多條命令執行
$ cd /temp/log/;rm -rf *
bash: cd: /temp/log: No such file or directory (突然陷入沉默)
$ cd /temp/log/&&rm -rf *
查看壓縮日志文件
$ zcat test.gz test log
$ zless test.gz test log
清空文件內容
將日志同時記錄文件并打印到控制臺
$ ./test.sh |tee test.log
終止并恢復進程執行
$ cat filename
計算程序運行時間
$ time ./fibo 30 the 30 result is 832040 real 0m0.088s user 0m0.084s sys 0m0.004s
查看內存占用前10的進程
$ ps -aux|sort -k4nr |head -n 10
快速查找你需要的命令
$ man -k "copy files" cp (1) - copy files and directories cpio (1) - copy files to and from archives git-checkout-index (1) - Copy files from the index to the working tree gvfs-copy (1) - Copy files gvfs-move (1) - Copy files install (1) - copy files and set attributes
命令行下的復制粘貼
搜索包含某個字符串的文件
$ grep -rn "test" test2.txt:1:test
屏幕凍結
無編輯器情況下編輯文本文件
$ cat >file.txt some words (ctrl+d)
查看elf文件
$ readelf -h filename
$ nm filename |grep interface
$ eho hello world <== 錯誤的命令 Command 'eho' not found, did you mean: command 'echo' from deb coreutils command 'who' from deb coreutils Try: sudo apt install <deb name> $ ^e^ec^ <== 替換 echo hello world hello world
$ alias butterfly=”ssh -v -l jdoe 192.168.0.11”
$ alias alias butterfly='ssh -v -l jdoe 192.168.0.11' alias c='clear' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l='ls -CF' alias la='ls -A' alias list_repos='grep ^[^#] /etc/apt/sources.list /etc/apt/sources.list.d/*' alias ll='ls -alF' alias ls='ls --color=auto' alias show_dimensions='xdpyinfo | grep '''dimensions:''''
!! <== 復用上一條命令 !ec <== 復用上一條以 “ec” 開頭的命令 !76 <== 復用命令歷史中的 76 號命令


來源 | 公眾號高效程序員
C++學習資料免費獲取方法:關注程序喵大人,后臺回復“程序喵”即可免費獲取40萬字C++進階獨家學習資料。
往期推薦