Skip to content

Instantly share code, notes, and snippets.

@Chunlin-Li
Last active May 18, 2016 11:58
Show Gist options
  • Save Chunlin-Li/b59a61bc13e66588f35e to your computer and use it in GitHub Desktop.
Save Chunlin-Li/b59a61bc13e66588f35e to your computer and use it in GitHub Desktop.
linux / bash shell 中的命令

sort

排序

split

文件分割程序.

# 将 MyFile.txt 拆成每 100 行一个文件的小块. 文件命名前缀: MyFile.part- , 后缀自动生成, 使用字母排序.
split -l 100 MyFile.txt MyFile.part-

-l : 按行拆分
-b : 按字节拆分
-C : 按字节拆分, 但不会将一行拆开(非精确). 可以使用 K M 等表示单位
-n : 将文件平均拆成 n 份

seq

生成数字序列

seq 0 1 10   #  0 1 2 3 4 5 6 7 8 9 10
seq 1 2 10   #  1 3 5 7 9

printf

类似与C语言中的格式化输出

printf "%.2d\n" 3   # 03

printf Bash Hackers


在管道中对字符串进行截取: bash shell sub substring substr slice

# 截取前四个字符.
echo 1234567 | xargs -n1 -I{} expr substr 1 4 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment