Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

部分 II. Shell

目录

19. Shell
19.1. 快捷键
19.1.1. 命令行编辑命令
19.1.2. 重新执行命令快捷键
19.1.3. 终端控制快捷键
19.1.4. Bang (!) 命令
19.2. chsh - change login shell
19.3. 执行程序返回值
20. Bash Shell
20.1. bash - GNU Bourne-Again SHell
20.1.1. -n 检查脚本是否有语法错误
20.1.2. -x 显示详细运行过程
20.2. 切换身份
20.3. I/O 重定向
20.3.1. stdout
20.3.2. error 重定向
20.3.3. 使用块记录日志
20.3.4. tee - read from standard input and write to standard output and files
20.3.5. 创建文件
20.3.6. 快速清空一个文件的内容
20.4. pipes (FIFOs)
20.5. mktemp - create a temporary file or directory 临时目录与文件
20.6. History 命令历史记录
20.6.1. .bash_history
20.6.2. 清理历史记录
20.6.3. .mysql_history
20.7. hash - hash database access method
20.8. prompt
20.9. 变量 variable
20.9.1. 系统变量
20.9.2. 表达式
20.9.3. Internal Environment Variables
20.9.4. set 设置变量
20.9.5. unset 变量销毁
20.9.6. 设置变量默认值
20.9.7. export 设置全局变量
20.9.8. declare
20.9.9. Numerical 数值运算
20.9.10. Strings 字符串操作
20.9.11. Array 数组
20.9.12. read 赋值多个变量
20.9.13. eval
20.9.14. typeset
20.9.15. envsubst - substitutes environment variables in shell format strings
20.10. conditions if and case
20.10.1. if
20.10.2. case
20.11. Loops for, while and until
20.11.1. for
20.11.2. while
20.11.3. until
20.12. Functions
20.12.1. Local variables
20.13. User interfaces
20.13.1. input
20.14. subshell
20.15. Example
20.15.1. 有趣的Shell
20.15.2. backup
20.15.3. CPU 核心数
20.15.4. Password
20.15.5. processes
20.15.6. Shell 技巧
20.15.7. to convert utf-8 from gb2312 code
20.15.8. 使用内存的百分比
20.15.9. 合并apache被cronlog分割的log文件
20.15.10. Linux 交集 差集 并集
21. 小众 Shell
21.1. fish shell
21.1.1. 安装 fish shell
21.1.2. 配置 fish
21.1.3. 环境变量
21.2. Z Shell
21.2.1. installing Z shell
21.2.2. Oh My ZSH!
21.2.3. Starting file
21.2.4. Prompting
21.2.5. Aliases
21.2.6. History
21.2.7. FAQ
21.3. Berkeley UNIX C shell (csh)
21.3.1.
21.4. KornShell
21.4.1.
22. Shell 命令
22.1. Help Commands
22.1.1. man - an interface to the on-line reference manuals
22.2. getconf - Query system configuration variables
22.3. test 命令
22.3.1. 判断目录
22.4. 目录和文件
22.4.1. dirname
22.4.2. filename
22.4.3. test - check file types and compare values
22.4.4. file — determine file type
22.4.5. stat
22.4.6. mkdir - make directories
22.4.7. rename
22.4.8. touch
22.4.9. truncate
22.4.10. ls - list directory contents
22.4.11. cp - copy files and directories
22.4.12. rm - remove files or directories
22.4.13. df - report file system disk space usage
22.4.14. du - estimate file space usage
22.4.15. tac - concatenate and print files in reverse
22.4.16. split - split a file into pieces
22.4.17. find - search for files in a directory hierarchy
22.5. package / compress and decompress
22.5.1. tar — The GNU version of the tar archiving utility
22.5.2. cpio - copy files to and from archives
22.5.3. gzip
22.5.4. zip, zipcloak, zipnote, zipsplit - package and compress (archive) files
22.5.5. bzip2, bunzip2 - a block-sorting file compressor
22.5.6. RAR
22.5.7. 7-Zip
22.5.8. RAR
22.5.9. xz, unxz, xzcat, lzma, unlzma, lzcat - Compress or decompress .xz and .lzma files
22.6. 日期和时间
22.6.1. 日期格式
22.6.2. -d --date=
22.6.3. 时间戳
22.6.4. RFC 2822
22.6.5. UTC
22.6.6. 字符串转日期
22.7. 数值与运算
22.7.1. 数值运算
22.7.2. seq - print a sequence of numbers
22.7.3. bc - An arbitrary precision calculator language
22.8. 文本处理
22.8.1. iconv - Convert encoding of given files from one encoding to another
22.8.2. 字符串处理命令expr
22.8.3. cat - concatenate files and print on the standard output
22.8.4. nl - number lines of files
22.8.5. tr - translate or delete characters
22.8.6. cut - remove sections from each line of files
22.8.7. printf - format and print data
22.8.8. Free `recode' converts files between various character sets and surfaces.
22.8.9. /dev/urandom 随机字符串
22.8.10. col - filter reverse line feeds from input
22.8.11. apg - generates several random passwords
22.8.12. head/tail
22.8.13. 反转字符串或文件内容
22.8.14. TAB符号与空格处理
22.8.15. grep, egrep, fgrep, rgrep - print lines matching a pattern
22.8.16. sort - sort lines of text files
22.8.17. uniq
22.8.18. awk
22.8.19. sed
22.9. 表格操作/行列转换
22.9.1. column - columnate lists
22.9.2. paste - merge lines of files
22.9.3. join
22.10. standard input/output
22.10.1. xargs - build and execute command lines from standard input
22.11. flock - manage locks from shell scripts
22.12. 进制转换 - 16进制 - 8进制 - 二进制
22.12.1. od - dump files in octal and other formats
22.12.2. hexdump, hd -- ASCII, decimal, hexadecimal, octal dump
22.12.3. xxd - make a hexdump or do the reverse.
22.12.4. binutils
22.13. 文件比较
22.13.1. diff
22.13.2. sdiff
22.13.3. diff3
22.14. ed, red - text editor
22.15. vim
22.15.1. vim 初始化
22.15.2. 查找与替换
22.15.3. 删除操作
22.15.4. 插入文件
22.15.5. 批处理
22.15.6. line()
22.15.7. set fileformat
22.15.8. 空格与TAB转换
22.16. Wget - The non-interactive network downloader.
22.16.1. Logging and input file
22.16.2. 下载相关参数
22.16.3. HTTP options (HTTP 选项)
22.16.4. Recursive download
22.16.5. --no-passive-ftp disable the "passive" transfer mode.
22.16.6. 下载一组连续的文件名
22.17. CURL - transfer a URL
22.17.1. 基本用法
22.17.2. 提交表单数据
22.17.3. 上传文件
22.17.4. connect-timeout
22.17.5. max-time
22.17.6. compressed
22.17.7. 代理服务器
22.17.8. -w, --write-out <format> 输出格式定义
22.17.9. -A/--user-agent <agent string>
22.17.10. referer
22.17.11. -v
22.17.12. -o, --output FILE Write output to <file> instead of stdout
22.17.13. -L, --location
22.17.14. -H/--header <line> Custom header to pass to server (H)
22.17.15. curl-config
22.17.16. 指定网络接口或者地址
22.17.17. Cookie 处理
22.17.18. Restful 应用 JSON 数据处理
22.17.19. 访问自签名证书
22.17.20. HTTP2
22.17.21. FAQ
22.18. expect
22.18.1. 模拟登录 telnet 获取Cisco配置
22.18.2. 模拟登录 ssh
22.18.3. SCP
22.18.4. openssl 例子
22.19. expect-lite - quick and easy command line automation tool
22.20. sshpass - noninteractive ssh password provider
22.21. Klish - Kommand Line Interface Shell (the fork of clish project)
22.21.1. 安装Klish
22.21.2. 为用户指定clish作为默认Shell
22.21.3. FAQ
22.22. Limited command Shell (lshell)
22.23. TUI
22.23.1. screen - screen manager with VT100/ANSI terminal emulation
22.23.2. tmux — terminal multiplexer
22.23.3. byobu - wrapper script for seeding a user's byobu configuration and launching a text based window manager (either screen or tmux)
22.23.4. htop - interactive process viewer
22.23.5. elinks
22.23.6. chat
22.24. jq - Command-line JSON processor
22.24.1. --raw-output
22.25. asciinema 终端录屏
22.26. parallel - build and execute shell command lines from standard input in parallel
22.27. multitail
22.28. Logging
22.28.1. logger - a shell command interface to the syslog(3) system log module
22.29. Password
22.29.1. Shadow password suite configuration.
22.29.2. newusers - update and create new users in batch
22.29.3. chpasswd - update passwords in batch mode
22.29.4. sshpass - noninteractive ssh password provider
22.30. 信息摘要
22.30.1. cksum, sum -- display file checksums and block counts
22.30.2. md5sum - compute and check MD5 message digest
22.30.3.
22.31. envsubst - substitutes environment variables in shell format strings
24. Shell Terminal
24.1. terminal
24.1.1. resize - set TERMCAP and terminal settings to current xterm window size
24.1.2. tset, reset - terminal initialization
24.1.3. stty - change and print terminal line settings
24.2. tput
24.2.1. Change the prompt color using tput
24.3. dialog
24.3.1. --inputbox
24.4. whiptail - display dialog boxes from shell scripts
24.4.1. --msgbox
24.4.2. --infobox
24.4.3. --yesno
24.4.4. --inputbox
24.4.5. --passwordbox
24.4.6. --textbox
24.4.7. --checklist
24.4.8. --radiolist
24.4.9. --menu
24.4.10. --gauge

1. 有趣的 Shell 应用

1.1. Ascii 星球大战电影

         
neo@MacBook-Pro-M2 ~>  nc towel.blinkenlights.nl 23        
        
        

1.2. 天气预报

         
neo@MacBook-Pro-M2 ~> curl http://wttr.in/
Weather report: Shenzhen, China

        \  /       Partly cloudy
    _ /"".-.     18 °C          
        \_(   ).   ↘ 26 km/h      
        /(___(__)  10 km          
                0.0 mm         
                                                        ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Mon 09 Jan ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│               Overcast       │               Overcast       │               Overcast       │               Overcast       │
│      .--.     17 °C          │      .--.     21 °C          │      .--.     19 °C          │      .--.     18 °C          │
│   .-(    ).   ↓ 7-9 km/h     │   .-(    ).   ↙ 7-8 km/h     │   .-(    ).   ↙ 7-10 km/h    │   .-(    ).   ↙ 7-10 km/h    │
│  (___.__)__)  10 km          │  (___.__)__)  10 km          │  (___.__)__)  10 km          │  (___.__)__)  10 km          │
│               0.0 mm | 0%    │               0.0 mm | 0%    │               0.0 mm | 0%    │               0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
                                                        ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Tue 10 Jan ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│  _`/"".-.     Patchy rain po…│  _`/"".-.     Patchy rain po…│      .-.      Light drizzle  │               Overcast       │
│   ,\_(   ).   17 °C          │   ,\_(   ).   18 °C          │     (   ).    17 °C          │      .--.     16 °C          │
│    /(___(__)  ↙ 6-9 km/h     │    /(___(__)  ↙ 8-9 km/h     │    (___(__)   ↙ 9-13 km/h    │   .-(    ).   ↙ 7-10 km/h    │
│      ‘ ‘ ‘ ‘  10 km          │      ‘ ‘ ‘ ‘  10 km          │     ‘ ‘ ‘ ‘   2 km           │  (___.__)__)  10 km          │
│     ‘ ‘ ‘ ‘   0.1 mm | 61%   │     ‘ ‘ ‘ ‘   0.1 mm | 81%   │    ‘ ‘ ‘ ‘    0.7 mm | 83%   │               0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
                                                        ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Wed 11 Jan ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│  _`/"".-.     Patchy rain po…│  _`/"".-.     Patchy rain po…│    \  /       Partly cloudy  │    \  /       Partly cloudy  │
│   ,\_(   ).   16 °C          │   ,\_(   ).   17 °C          │  _ /"".-.     18 °C          │  _ /"".-.     17 °C          │
│    /(___(__)  ↙ 5-7 km/h     │    /(___(__)  ↙ 5-6 km/h     │    \_(   ).   ↙ 7-9 km/h     │    \_(   ).   ← 7-11 km/h    │
│      ‘ ‘ ‘ ‘  10 km          │      ‘ ‘ ‘ ‘  10 km          │    /(___(__)  10 km          │    /(___(__)  10 km          │
│     ‘ ‘ ‘ ‘   0.1 mm | 87%   │     ‘ ‘ ‘ ‘   0.1 mm | 84%   │               0.0 mm | 0%    │               0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘

Follow @igor_chubin for wttr.in updates