Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

Netkiller Shell 手札

Unix, Linux, FreeBSD & Mac Shell

Mr. Neo Chan, 陈景峰(BG7NYT)



中国广东省深圳市望海路半岛城邦三期
518067
+86 13113668890


2009-11-15

电子书最近一次更新于 2026-08-05 11:51:30

版权声明

转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。

http://www.netkiller.cn
http://netkiller.github.io
http://netkiller.sourceforge.net
微信公众号: netkiller
微信:13113668890 请注明“读者”
QQ:13721218 请注明“读者”
QQ群:128659835 请注明“读者”
知乎专栏

内容摘要

Netkiller 系列手札 已经被 Github 收录,并备份保存在北极地下250米深的代码库中,备份会保留1000年。

Preserving open source software for future generations

The world is powered by open source software. It is a hidden cornerstone of modern civilization, and the shared heritage of all humanity.

The GitHub Arctic Code Vault is a data repository preserved in the Arctic World Archive (AWA), a very-long-term archival facility 250 meters deep in the permafrost of an Arctic mountain.

We are collaborating with the Bodleian Library in Oxford, the Bibliotheca Alexandrina in Egypt, and Stanford Libraries in California to store copies of 17,000 of GitHub’s most popular and most-depended-upon projects—open source’s “greatest hits”—in their archives, in museum-quality cases, to preserve them for future generations.

我们正在与牛津的博德利安图书馆、埃及的亚历山大图书馆和加利福尼亚州的斯坦福图书馆合作,将 GitHub 最受欢迎和最依赖的项目 17,000 份副本保存在他们的档案中,在博物馆质量的案例中,为子孙后代保存这些作品。

https://archiveprogram.github.com/arctic-vault/

我的系列文档:

Netkiller Linux 手札 Netkiller FreeBSD 手札 Netkiller Shell 手札 Netkiller Security 手札
Netkiller Web 手札 Netkiller Monitoring 手札 Netkiller Storage 手札 Netkiller Mail 手札
Netkiller Virtualization 手札 Netkiller Cryptography 手札   

以下文档停止更新合并到 《Netkiller Linux 手札》

Netkiller Debian 手札 Netkiller CentOS 手札 Netkiller Multimedia 手札    

致读者

Netkiller 系列手札 已经被 Github 收录,并备份保存在北极地下250米深的代码库中,备份会保留1000年。

Preserving open source software for future generations

The world is powered by open source software. It is a hidden cornerstone of modern civilization, and the shared heritage of all humanity.

The GitHub Arctic Code Vault is a data repository preserved in the Arctic World Archive (AWA), a very-long-term archival facility 250 meters deep in the permafrost of an Arctic mountain.

We are collaborating with the Bodleian Library in Oxford, the Bibliotheca Alexandrina in Egypt, and Stanford Libraries in California to store copies of 17,000 of GitHub’s most popular and most-depended-upon projects—open source’s “greatest hits”—in their archives, in museum-quality cases, to preserve them for future generations.

https://archiveprogram.github.com/arctic-vault/

目录

1. 自述
1.1. 写给读者
1.2. 作者简介
1.3. 如何获得文档
1.4. 打赏(Donations)
1.5. 联系方式
1. Bash Shell
1.1. bash - GNU Bourne-Again SHell
1.1.1. -n 检查脚本是否有语法错误
1.1.2. -x 显示详细运行过程
1.2. 切换身份
1.3. test 命令
1.3.1. 判断目录
1.4. I/O 重定向
1.4.1. stdout
1.4.2. error 重定向
1.4.3. 使用块记录日志
1.4.4. tee - read from standard input and write to standard output and files
1.4.5. 创建文件
1.4.6. 快速清空一个文件的内容
1.5. pipes (FIFOs)
1.6. mktemp - create a temporary file or directory 临时目录与文件
1.7. History 命令历史记录
1.7.1. .bash_history
1.7.2. 清理历史记录
1.7.3. .mysql_history
1.8. hash - hash database access method
1.9. prompt
1.10. 变量 variable
1.10.1. 系统变量
1.10.2. 表达式
1.10.3. Internal Environment Variables
1.10.4. set 设置变量
1.10.5. unset 变量销毁
1.10.6. 设置变量默认值
1.10.7. export 设置全局变量
1.10.8. declare
1.10.9. Numerical 数值运算
1.10.10. Strings 字符串操作
1.10.11. Array 数组
1.10.12. read 赋值多个变量
1.10.13. eval
1.10.14. typeset
1.10.15. envsubst - substitutes environment variables in shell format strings
1.11. conditions if and case
1.11.1. if
1.11.2. case
1.12. Loops for, while and until
1.12.1. for
1.12.2. while
1.12.3. until
1.13. Functions
1.13.1. Local variables
1.14. User interfaces
1.14.1. input
1.15. subshell
1.16. Example
1.16.1. 有趣的Shell
1.16.2. backup
1.16.3. CPU 核心数
1.16.4. Password
1.16.5. processes
1.16.6. Shell 技巧
1.16.7. to convert utf-8 from gb2312 code
1.16.8. 使用内存的百分比
1.16.9. 合并apache被cronlog分割的log文件
1.16.10. Linux 交集 差集 并集
2. Shell
2.1. Help Commands
2.1.1. man - an interface to the on-line reference manuals
2.2. getconf - Query system configuration variables
2.3. 快捷键
2.3.1. 命令行编辑命令
2.3.2. 重新执行命令快捷键
2.3.3. 终端控制快捷键
2.3.4. Bang (!) 命令
2.4. chsh - change login shell
2.5. 执行程序返回值
2.6. Z Shell
2.6.1. installing Z shell
2.6.2. Oh My ZSH!
2.6.3. Starting file
2.6.4. Prompting
2.6.5. Aliases
2.6.6. History
2.6.7. FAQ
2.7. Berkeley UNIX C shell (csh)
2.7.1.
2.8. KornShell
2.8.1.
2.9. fish shell
2.9.1. 安装 fish shell
2.9.2. 配置 fish
2.9.3. 环境变量
2.10. 有趣的 Shell 应用
2.10.1. Ascii 星球大战电影
2.10.2. 天气预报
2.10.3. htop - interactive process viewer
2.10.4. elinks
2.10.5. chat
3. 目录和文件
3.1. dirname
3.2. filename
3.2.1. 排除扩展名
3.2.2. 取扩展名
3.3. test - check file types and compare values
3.4. file — determine file type
3.5. stat
3.6. file – determine file type
3.7. mkdir - make directories
3.8. rename
3.9. touch
3.10. truncate
3.11. ls - list directory contents
3.11.1. full-time / time-style 定义日期时间格式
3.12. cp - copy files and directories
3.12.1. copy directories recursively
3.12.2. 覆盖已存在的文件
3.12.3. -a, --archive same as -dR --preserve=all
3.13. rm - remove files or directories
3.13.1. -bash: /bin/rm: Argument list too long
3.13.2. zsh: sure you want to delete all the files in /tmp [yn]?
3.14. df - report file system disk space usage
3.15. du - estimate file space usage
3.16. tac - concatenate and print files in reverse
3.17. split - split a file into pieces
3.17.1. 按行分割文件
3.17.2. 按尺寸分割文件
3.18. find - search for files in a directory hierarchy
3.18.1. 多目录匹配
3.18.2. name
3.18.3. regex
3.18.4. user
3.18.5. perm
3.18.6. type
3.18.7. -delete
3.18.8. exec
3.18.9. 排除目录
3.18.10. -mmin n File's data was last modified n minutes ago.
3.18.11. -ctime
3.18.12. -mtime / -mmin
3.18.13. --newer
3.18.14. -print / -printf
3.18.15. -size
3.18.16. -path
3.18.17. 目录深度控制
3.18.18. xargs
3.18.19. 查看空文件
4. 包管理 / 压缩 / 解压
4.1. tar — The GNU version of the tar archiving utility
4.1.1. tar examples
4.1.2. gunzip
4.1.3. b2zip
4.1.4. compress
4.1.5. .xz 文件
4.1.6. -t, --list
4.1.7. tar: Removing leading `/’ from member names
4.1.8. -C, --directory=DIR
4.1.9. --exclude
4.1.10. -T
4.1.11. 日期过滤
4.1.12. 保留权限
4.1.13. -r, --append
4.1.14. 远程传输
4.1.15. 分卷压缩
4.2. cpio - copy files to and from archives
4.3. gzip
4.4. zip, zipcloak, zipnote, zipsplit - package and compress (archive) files
4.5. bzip2, bunzip2 - a block-sorting file compressor
4.6. RAR
4.7. 7-Zip
4.7.1. 压缩
4.7.2. 浏览压缩包
4.7.3. 解压
4.7.4. Creates self extracting archive.
4.8. RAR
4.9. xz, unxz, xzcat, lzma, unlzma, lzcat - Compress or decompress .xz and .lzma files
5. 日期和时间
5.1. 日期格式
5.1.1. weekday name
5.2. -d --date=
5.2.1. 日期偏移量
5.2.2. 时间偏移
5.3. 时间戳
5.4. RFC 2822
5.5. UTC
5.6. 字符串转日期
6. 数值与运算
6.1. 数值运算
6.2. seq - print a sequence of numbers
6.3. bc - An arbitrary precision calculator language
7. 文本处理
7.1. iconv - Convert encoding of given files from one encoding to another
7.1.1. cconv - A iconv based simplified-traditional chinese conversion tool
7.1.2. uconv - convert data from one encoding to another
7.2. 字符串处理命令expr
7.3. cat - concatenate files and print on the standard output
7.3.1. -s, --squeeze-blank suppress repeated empty output lines
7.3.2. -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
7.3.3. 与管道配合使用
7.4. nl - number lines of files
7.5. tr - translate or delete characters
7.5.1. 替换字符
7.5.2. 英文大小写转换
7.5.3. [CHAR*] 和 [CHAR*REPEAT]
7.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
7.5.5. -d, --delete delete characters in SET1, do not translate
7.6. cut - remove sections from each line of files
7.6.1. 字符操作
7.6.2. 列操作
7.7. printf - format and print data
7.8. Free `recode' converts files between various character sets and surfaces.
7.9. /dev/urandom 随机字符串
7.10. col - filter reverse line feeds from input
7.11. apg - generates several random passwords
7.12. head/tail
7.12.1. 彩色输出
7.12.2. 跳过 n 行,输出后面内容
7.12.3. 尾部剪掉 n 行
7.13. 反转字符串或文件内容
7.14. TAB符号与空格处理
7.14.1. expand - convert tabs to spaces
7.14.2. unexpand - convert spaces to tabs
7.15. grep, egrep, fgrep, rgrep - print lines matching a pattern
7.15.1. 删除空行
7.15.2. -v, --invert-match
7.15.3. 输出控制(Output control)
7.15.4. Context control
7.15.5. Regexp selection and interpretation
7.15.6. fgrep
7.15.7. egrep
7.16. sort - sort lines of text files
7.16.1. 对列排序
7.16.2. -s, --stable stabilize sort by disabling last-resort comparison
7.17. uniq
7.18. awk
7.18.1. 处理列
7.18.2. printf
7.18.3. Pattern(字符匹配)
7.18.4. Built-in Variables (NR/NF)
7.18.5. Built-in Functions
7.18.6. 过滤相同的行
7.18.7. 数组演示
7.19. sed
7.19.1. 查找与替换
7.19.2. insert 插入字符
7.19.3. 追加字符
7.19.4. 修改字符
7.19.5. 删除字符
7.19.6. 行操作
7.19.7. 编辑文件
7.19.8. 正则表达式
7.19.9. 管道操作
7.19.10. 字母大小写转换
7.19.11. perl
7.19.12. 案例
7.20. ed, red - text editor
7.21. vim
7.21.1. vim 初始化
7.21.2. 查找与替换
7.21.3. 删除操作
7.21.4. 插入文件
7.21.5. 批处理
7.21.6. line()
7.21.7. set fileformat
7.21.8. 空格与TAB转换
7.22. XML 工具
7.22.1. xmllint - command line XML tool
7.22.2. xmlstarlet - command line XML/XSLT toolkit
7.23. jq - Command-line JSON processor
7.23.1. --raw-output
8. 表格操作/行列转换
8.1. column - columnate lists
8.2. paste - merge lines of files
8.3. join
9. standard input/output
9.1. standard input/output
9.1.1. xargs - build and execute command lines from standard input
9.2. flock - manage locks from shell scripts
10. 进制转换 - 16进制 - 8进制 - 二进制
10.1. od - dump files in octal and other formats
10.1.1. 16进制
10.1.2. 使用 od 随机生成密码
10.2. hexdump, hd -- ASCII, decimal, hexadecimal, octal dump
10.3. xxd - make a hexdump or do the reverse.
10.3.1. 指定每行的列数
10.3.2. 跳过字节
10.4. binutils
10.4.1. strings - print the strings of printable characters in files.
11. 文件比较
11.1. diff
11.2. sdiff
11.3. diff3
12. Wget - The non-interactive network downloader.
12.1. Logging and input file
12.1.1. -i, --input-file=FILE download URLs found in local or external FILE.
12.2. 下载相关参数
12.2.1. -O, --output-document=FILE write documents to FILE 保存到文件
12.3. HTTP options (HTTP 选项)
12.3.1. --post-data=STRING use the POST method; send STRING as the data.
12.3.2. header HTTP头定义
12.4. Recursive download
12.4.1. -r, --recursive specify recursive download.
12.4.2. -m, --mirror shortcut for -N -r -l inf --no-remove-listing.
12.5. --no-passive-ftp disable the "passive" transfer mode.
12.6. 下载一组连续的文件名
13. CURL - transfer a URL
13.1. 基本用法
13.2. 提交表单数据
13.3. 上传文件
13.4. connect-timeout
13.5. max-time
13.6. compressed
13.7. 代理服务器
13.8. -w, --write-out <format> 输出格式定义
13.9. -A/--user-agent <agent string>
13.10. referer
13.11. -v
13.12. -o, --output FILE Write output to <file> instead of stdout
13.13. -L, --location
13.14. -H/--header <line> Custom header to pass to server (H)
13.14.1. Last-Modified / If-Modified-Since
13.14.2. ETag / If-None-Match
13.14.3. Accept-Encoding:gzip,defalte
13.14.4. HOST
13.14.5. HTTP 认证
13.14.6. Accept
13.14.7. Content-Type
13.15. curl-config
13.16. 指定网络接口或者地址
13.17. Cookie 处理
13.18. Restful 应用 JSON 数据处理
13.18.1. Curl Oauth2
13.18.2. Curl + Oauth2 + Jwt
13.19. 访问自签名证书
13.20. HTTP2
13.21. FAQ
14. 信息摘要
14.1. cksum, sum -- display file checksums and block counts
14.2. md5sum - compute and check MD5 message digest
14.3.
15. envsubst - substitutes environment variables in shell format strings
15.1. envsubst - substitutes environment variables in shell format strings
15.2. parallel - build and execute shell command lines from standard input in parallel
15.3. multitail
15.4. Logging
15.4.1. logger - a shell command interface to the syslog(3) system log module
15.5. Password
15.5.1. Shadow password suite configuration.
15.5.2. newusers - update and create new users in batch
15.5.3. chpasswd - update passwords in batch mode
15.5.4. sshpass - noninteractive ssh password provider
16. 常用命令
16.1. 获取IP地址
16.2. 有趣的 Shell 应用
16.2.1. Ascii 星球大战电影
16.2.2. 天气预报
16.2.3. htop - interactive process viewer
16.2.4. elinks
16.2.5. chat
1. 附录
1.1. 参考文献

表格清单

1. Netkiller 系列免费电子书
1.1. 文件目录表达式
1.2. 字符串表达式
1.3. 组合表达式

范例清单

1.1. A "Power User" Prompt
1.2. A Prompt the Width of Your Term
1.3. The Elegant Useless Clock Prompt
1.4. Basic conditional example if .. then
1.5. Conditionals with variables
1.6. case
1.7. Functions with parameters sample
1.8. Using select to make simple menus
1.9. Using the command line
1.10. Reading user input with read
1.11. read
1.12. random password
3.1. backup(find + tar)
15.1. parallel - build and execute shell command lines from standard input in parallel