Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

部分 II. Shell

目錄

22. Bash Shell
22.1. 快捷鍵
22.2. bash - GNU Bourne-Again SHell
22.2.1. -n 檢查腳本是否有語法錯誤
22.2.2. -x 顯示詳細運行過程
22.3. Introduction
22.3.1. chsh - change login shell
22.3.2. 切換身份
22.3.3. I/O 重定向
22.3.3.1. stdout
22.3.3.2. error 重定向
22.3.3.3. 使用塊記錄日誌
22.3.3.4. tee - read from standard input and write to standard output and files
22.3.3.4.1. 重定向到檔案
22.3.3.4.2. nettee - a network "tee" program
22.3.3.5. 創建檔案
22.3.3.6. 快速清空一個檔案的內容
22.3.4. pipes (FIFOs)
22.3.5. mktemp - create a temporary file or directory 臨時目錄與檔案
22.3.6. History 命令歷史記錄
22.3.6.1. .bash_history
22.3.6.1.1. 格式定義
22.3.6.1.2. 設置忽略命令
22.3.6.2. .mysql_history
22.3.7. hash - hash database access method
22.3.8. prompt
22.4. variable
22.4.1. 系統變數
22.4.1.1. 命令行參數傳遞
22.4.1.2. $n $# $0 $?
22.4.1.3. $? 程序運行返回值
22.4.1.4. shift 移位
22.4.2. 表達式
22.4.3. Internal Environment Variables
22.4.3.1. $RANDOM 隨機數
22.4.3.2. 與 history 有關的環境變數
22.4.4. set 設置變數
22.4.5. unset 變數銷毀
22.4.6. 設置變數預設值
22.4.7. export 設置全局變數
22.4.8. declare
22.4.9. Numerical 數值運算
22.4.10. Strings 字元串操作
22.4.10.1. ##/#
22.4.10.2. %%/%
22.4.10.3. 字元串截取
22.4.10.4. #
22.4.10.5. example
22.4.10.6. 計算字元串長度
22.4.10.7. 字元串查找替換
22.4.11. Array 數組
22.4.11.1. for 與 array
22.4.11.2. while 與 array
22.4.11.3. array 與 read
22.4.11.4. 拆分字元串並轉換為數組
22.4.11.5. 數組轉為字元串
22.4.12. read 賦值多個變數
22.4.13. eval
22.4.14. typeset
22.5. conditions if and case
22.5.1. if
22.5.2. case
22.6. Loops for, while and until
22.6.1. for
22.6.2. while
22.6.3. until
22.7. Functions
22.7.1. Local variables
22.8. User interfaces
22.8.1. input
22.9. subshell
22.10. Example
22.10.1. 有趣的Shell
22.10.2. backup
22.10.3. CPU 核心數
22.10.4. Password
22.10.5. processes
22.10.5.1. pid
22.10.5.2. kill
22.10.5.3. pgrep
22.10.6. Shell 技巧
22.10.6.1. 行轉列,再批評
22.10.6.2. for vs while
22.10.6.3. 遍歷字元串
22.10.7. to convert utf-8 from gb2312 code
22.10.8. 使用內存的百分比
22.10.9. 合併apache被cronlog分割的log檔案
22.10.10. Linux 交集 差集 並集
23. Z Shell
23.1. installing Z shell
23.2. Oh My ZSH!
23.3. Starting file
23.3.1. ~/.zshrc
23.4. Prompting
23.5. Aliases
23.6. History
23.7. FAQ
23.7.1. Home/End key
24. Berkeley UNIX C shell (csh)
24.1.
25. KornShell
25.1.
26. Shell command
26.1. Help Commands
26.1.1. man - an interface to the on-line reference manuals
26.1.1.1. manpath.config
26.1.1.2. 查看man手冊位置
26.1.1.3. 指定手冊位置
26.2. getconf - Query system configuration variables
26.3. test 命令
26.3.1. 判斷目錄
26.4. Directory and File System Related
26.4.1. dirname
26.4.2. filename
26.4.2.1. 排除副檔名
26.4.2.2. 取副檔名
26.4.3. test - check file types and compare values
26.4.4. file — determine file type
26.4.5. stat
26.4.6. mkdir - make directories
26.4.7. rename
26.4.8. touch
26.4.9. truncate
26.4.10. ls - list directory contents
26.4.10.1. full-time / time-style 定義日期時間格式
26.4.11. cp - copy files and directories
26.4.11.1. copy directories recursively
26.4.11.2. overwrite an existing file
26.4.11.3. -a, --archive same as -dR --preserve=all
26.4.12. rm - remove files or directories
26.4.12.1. -bash: /bin/rm: Argument list too long
26.4.12.2. zsh: sure you want to delete all the files in /tmp [yn]?
26.4.13. df - report file system disk space usage
26.4.14. du - estimate file space usage
26.4.15. tac - concatenate and print files in reverse
26.4.16. split - split a file into pieces
26.4.16.1. 按行分割檔案
26.4.16.2. 按尺寸分割檔案
26.4.17. find - search for files in a directory hierarchy
26.4.17.1. name
26.4.17.2. regex
26.4.17.3. user
26.4.17.4. perm
26.4.17.5. type
26.4.17.5.1. 分別設置檔案與目錄的權限
26.4.17.6. -delete
26.4.17.7. exec
26.4.17.8. 排除目錄
26.4.17.9. -mmin n File's data was last modified n minutes ago.
26.4.17.10. -ctime
26.4.17.11. -mtime / -mmin
26.4.17.12. --newer
26.4.17.13. -print / -printf
26.4.17.14. -size
26.4.17.15. -path
26.4.17.16. 目錄深度控制
26.4.17.17. -maxdepth
26.4.17.18. xargs
26.5. package / compress and decompress
26.5.1. tar — The GNU version of the tar archiving utility
26.5.1.1. tar examples
26.5.1.2. gunzip
26.5.1.3. b2zip
26.5.1.4. compress
26.5.1.5. .xz 檔案
26.5.1.6. -t, --list
26.5.1.7. tar: Removing leading `/’ from member names
26.5.1.8. -C, --directory=DIR
26.5.1.9. --exclude
26.5.1.10. -T
26.5.1.11. 日期過濾
26.5.1.12. 保留權限
26.5.1.13. -r, --append
26.5.1.14. 遠程傳輸
26.5.1.15. 分卷壓縮
26.5.2. cpio - copy files to and from archives
26.5.3. gzip
26.5.4. zip, zipcloak, zipnote, zipsplit - package and compress (archive) files
26.5.5. bzip2, bunzip2 - a block-sorting file compressor
26.5.6. RAR
26.5.7. 7-Zip
26.5.7.1. 壓縮
26.5.7.2. 瀏覽壓縮包
26.5.7.3. 解壓
26.5.7.4. Creates self extracting archive.
26.5.8. RAR
26.5.9. xz, unxz, xzcat, lzma, unlzma, lzcat - Compress or decompress .xz and .lzma files
26.6. date and time
26.6.1. 日期格式
26.6.1.1. weekday name
26.6.2. -d --date=
26.6.2.1. 日期偏移量
26.6.2.1.1. day
26.6.2.1.2. month
26.6.2.1.3. year
26.6.2.2. 時間偏移
26.6.3. 時間戳
26.6.4. RFC 2822
26.6.5. UTC
26.7. Numeric
26.7.1. 數值運算
26.7.2. seq - print a sequence of numbers
26.7.3. bc - An arbitrary precision calculator language
26.8. Text Processing
26.8.1. iconv - Convert encoding of given files from one encoding to another
26.8.1.1. cconv - A iconv based simplified-traditional chinese conversion tool
26.8.1.2. uconv - convert data from one encoding to another
26.8.2. 字元串處理命令expr
26.8.3. cat - concatenate files and print on the standard output
26.8.3.1. -s, --squeeze-blank suppress repeated empty output lines
26.8.3.2. -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
26.8.4. nl - number lines of files
26.8.5. tr - translate or delete characters
26.8.5.1. 替換字元
26.8.5.2. 英文大小寫轉換
26.8.5.3. [CHAR*] 和 [CHAR*REPEAT]
26.8.5.4. -s, --squeeze-repeats replace each input sequence of a repeated character that is listed in SET1 with a single occurrence of that character
26.8.5.5. -d, --delete delete characters in SET1, do not translate
26.8.6. cut - remove sections from each line of files
26.8.7. printf - format and print data
26.8.8. Free `recode' converts files between various character sets and surfaces.
26.8.9. /dev/urandom 隨機字元串
26.8.10. col - filter reverse line feeds from input
26.8.11. apg - generates several random passwords
26.8.12. head/tail
26.8.13. 反轉字元串或檔案內容
26.8.14. TAB符號與空格處理
26.8.14.1. expand - convert tabs to spaces
26.8.14.2. unexpand - convert spaces to tabs
26.9. grep, egrep, fgrep, rgrep - print lines matching a pattern
26.9.1. 刪除空行
26.9.2. -v, --invert-match
26.9.3. Output control
26.9.3.1. -o, --only-matching show only the part of a line matching PATTERN
26.9.3.1.1. IP 地址
26.9.3.1.2. UUID
26.9.3.1.3. 行列轉換
26.9.3.2. 遞歸操作
26.9.3.3. -c, --count print only a count of matching lines per FILE
26.9.4. Context control
26.9.4.1. -A, --after-context=NUM print NUM lines of trailing context
26.9.4.2. -B, --before-context=NUM print NUM lines of leading context
26.9.4.3. -C, --context=NUM print NUM lines of output context
26.9.4.4. --color
26.9.5. Regexp selection and interpretation
26.9.5.1. .*
26.9.5.2. 2010:(13|14|15|16)
26.9.5.3. []與{}
26.9.5.4. -P, --perl-regexp Perl正則表達式
26.9.6. fgrep
26.9.7. egrep
26.10. sort - sort lines of text files
26.10.1. 對列排序
26.10.2. -s, --stable stabilize sort by disabling last-resort comparison
26.11. uniq
26.12. 表格操作/行列轉換
26.12.1. column - columnate lists
26.12.2. paste - merge lines of files
26.12.3. join
26.13. standard input/output
26.13.1. xargs - build and execute command lines from standard input
26.13.1.1. 格式化
26.13.1.2. standard input
26.13.1.3. -I 替換操作
26.13.1.4. -n, --max-args=MAX-ARGS use at most MAX-ARGS arguments per command line
26.13.1.5. -t, --verbose print commands before executing them
26.13.1.6. -d, --delimiter=CHARACTER items in input stream are separated by CHARACTER, not by whitespace; disables quote and backslash processing and logical EOF processing
26.13.1.7. -0, --null items are separated by a null, not whitespace; disables quote and backslash processing and logical EOF processing
26.13.1.8. -r, --no-run-if-empty if there are no arguments, then do not run COMMAND; if this option is not given, COMMAND will be
26.13.1.9. -p, --interactive prompt before running commands
26.14. flock - manage locks from shell scripts
26.15. 進制轉換 - 16進制 - 8進制 - 二進制
26.15.1. od - dump files in octal and other formats
26.15.1.1. 16進制
26.15.1.2. 使用 od 隨機生成密碼
26.15.2. hexdump, hd -- ASCII, decimal, hexadecimal, octal dump
26.15.3. xxd - make a hexdump or do the reverse.
26.15.3.1. 指定每行的列數
26.15.3.2. 跳過位元組
26.15.4. binutils
26.15.4.1. strings - print the strings of printable characters in files.
26.16. Logging
26.16.1. logger - a shell command interface to the syslog(3) system log module
26.17. Password
26.17.1. Shadow password suite configuration.
26.17.2. newusers - update and create new users in batch
26.17.3. chpasswd - update passwords in batch mode
26.17.4. sshpass - noninteractive ssh password provider
26.18. 信息摘要
26.18.1. cksum, sum -- display file checksums and block counts
26.18.2. md5sum - compute and check MD5 message digest
26.18.3.
26.19. envsubst - substitutes environment variables in shell format strings
28. Utility Programs
28.1. ed, red - text editor
28.2. vim
28.2.1. 查找與替換
28.2.2. 插入檔案
28.2.3. 批處理
28.2.3.1. vi 批處理
28.2.4. line()
28.2.5. set fileformat
28.3. awk
28.3.1. 處理列
28.3.2. printf
28.3.3. Pattern(字元匹配)
28.3.3.1. Pattern, Pattern
28.3.4. Built-in Variables (NR/NF)
28.3.4.1. NR
28.3.4.2. NF
28.3.4.3. 練習
28.3.4.3.1. 使用 ss 命令統計 TCP 狀態
28.3.4.3.2. TCP/IP Status
28.3.4.3.3. 用戶shell統計
28.3.4.3.4. access.log POST與GET統計
28.3.5. Built-in Functions
28.3.5.1. length
28.3.5.2. toupper() 轉為大寫字母
28.3.5.3. tolower() 轉為小寫字母
28.3.5.4. rand() 隨機數生成
28.3.6. 過濾相同的行
28.3.7. 數組演示
28.4. sed
28.4.1. 查找與替換
28.4.1.1. 正則
28.4.1.2. aaa="bbb" 提取bbb
28.4.1.3. 首字母大寫
28.4.2. insert 插入字元
28.4.3. 追加字元
28.4.4. 修改字元
28.4.5. 刪除字元
28.4.5.1. delete
28.4.6. 行操作
28.4.7. 編輯檔案
28.4.8. 正則表達式
28.4.9. 管道操作
28.4.10. 字母大小寫轉換
28.4.11. perl
28.5. CURL - transfer a URL
28.5.1. 基本用法
28.5.2. 提交表單數據
28.5.3. 上傳檔案
28.5.4. connect-timeout
28.5.5. max-time
28.5.6. compressed
28.5.7. vhosts
28.5.8. -w, --write-out <format> 輸出格式定義
28.5.9. -A/--user-agent <agent string>
28.5.10. referer
28.5.11. -v
28.5.12. -o, --output FILE Write output to <file> instead of stdout
28.5.13. -L, --location
28.5.14. -H/--header <line> Custom header to pass to server (H)
28.5.14.1. Last-Modified / If-Modified-Since
28.5.14.2. ETag / If-None-Match
28.5.14.3. Accept-Encoding:gzip,defalte
28.5.14.4. HOST
28.5.14.5. HTTP 認證
28.5.14.6. Accept
28.5.14.7. Content-Type
28.5.15. curl-config
28.5.16. 指定網絡介面或者地址
28.5.17. Cookie 處理
28.5.18. Restful 應用 JSON 數據處理
28.5.18.1. Curl Oauth2
28.5.18.2. Curl + Oauth2 + Jwt
28.5.19. 訪問自簽名證書
28.5.20. HTTP2
28.5.21. FAQ
28.6. expect
28.6.1. 模擬登錄 telnet 獲取Cisco配置
28.6.2. 模擬登錄 ssh
28.6.3. SCP
28.6.4. openssl 例子
28.7. expect-lite - quick and easy command line automation tool
28.8. sshpass - noninteractive ssh password provider
28.9. Klish - Kommand Line Interface Shell (the fork of clish project)
28.9.1. 安裝Klish
28.9.2. 為用戶指定clish作為預設Shell
28.9.3. FAQ
28.9.3.1. clish/shell/shell_expat.c:36:19: fatal error: expat.h: No such file or directory
28.10. Limited command Shell (lshell)
28.11. Wget - The non-interactive network downloader.
28.11.1. Logging and input file
28.11.1.1. -i, --input-file=FILE download URLs found in local or external FILE.
28.11.2. 下載相關參數
28.11.2.1. -O, --output-document=FILE write documents to FILE 保存到檔案
28.11.3. HTTP options (HTTP 選項)
28.11.3.1. --post-data=STRING use the POST method; send STRING as the data.
28.11.3.2. header HTTP頭定義
28.11.4. Recursive download
28.11.4.1. -r, --recursive specify recursive download.
28.11.4.2. -m, --mirror shortcut for -N -r -l inf --no-remove-listing.
28.11.5. --no-passive-ftp disable the "passive" transfer mode.
28.11.6. 下載一組連續的檔案名
28.12. TUI
28.12.1. screen - screen manager with VT100/ANSI terminal emulation
28.12.2. tmux — terminal multiplexer
28.12.3. byobu - wrapper script for seeding a user's byobu configuration and launching a text based window manager (either screen or tmux)
28.12.4. htop - interactive process viewer
28.12.5. elinks
28.12.6. chat
28.13. jq - Command-line JSON processor
28.14. parallel - build and execute shell command lines from standard input in parallel
28.15. multitail
29. Shell Terminal
29.1. terminal
29.1.1. resize - set TERMCAP and terminal settings to current xterm window size
29.1.2. tset, reset - terminal initialization
29.1.3. stty - change and print terminal line settings
29.2. tput
29.2.1. Change the prompt color using tput
29.3. dialog
29.3.1. --inputbox
29.4. whiptail - display dialog boxes from shell scripts
29.4.1. --msgbox
29.4.2. --infobox
29.4.3. --yesno
29.4.4. --inputbox
29.4.5. --passwordbox
29.4.6. --textbox
29.4.7. --checklist
29.4.8. --radiolist
29.4.9. --menu
29.4.10. --gauge