Skip to content

Instantly share code, notes, and snippets.

View ibreathebsb's full-sized avatar
🤠

Isaac Young ibreathebsb

🤠
View GitHub Profile

gzip

gzip 用于压缩解压查看文件

用法: gzip [opitions] file

-v: 显示压缩和解压缩信息

-k: 压缩和解压时保留原来的文件

tar

将多个文件打包为一个文件

命令

tar -c -f archive.tar files/directories 将文件或目录打包为一个文件

tar -[r|u] -f archive.tar newfiles/newdirectoreis 将新的文件添加到当前包中,只对非压缩的archive有效, u与r的不同之处在于,u=update只有目标文件比archive中对应的文件新时才会更新

dump

文件和文件系统备份

dump -W 列出/etc/fstab中的文件系统备份情况

root@debian-gnu-linux-vm:/home/parallels/Playground# dump -W
Last dump(s) done (Dump '>' file systems):

vim

模式

  1. 常规模式
  2. 编辑模式
  3. 指令模式

三者的切换 编辑模式 <->常规模式<->指令模式

变量

  1. 变量命名时不能用=号两边不能有空格
  2. shell脚本中的的单引号和双引号作用不同,单引号会将特殊符号当作普通符号处理,而双引号会将变量替换为其真是内容:
isaac@hp:~/Playground$ echo "lang is $LANG"
lang is en_US.UTF-8
isaac@hp:~/Playground$ echo 'lang is $LANG'
lang is $LANG

alias

alias : 列出所有别名

isaac@hp:~/Notes/linux$ alias
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'

命令搜索顺序

  1. 对与使用绝对路径或相对路径下达的命令例如/bin/ls ./test 直接在路径中查找
  2. 在alias中查找
  3. 在shell的builtin指令中查找
  4. $PATH中查找第一个名称匹配额命令

bash环境变量初始化

login shellnon-login shell : login shell值的是通过账号密码输入登录后的shell,non-login shell指的是没有经过上述登录流程的shell,例如桌面环境下登录后,打开terminal,或者在login shellbash创建的新shell

输入输出重定向

  1. 0 1 2 分别表示标准输入(键盘) 标准输出(屏幕) 标准错误输出
  2. > file 将原本输出到标准输出的内容以覆盖的方式写入到file中,>> file追加的方式写入到file中
  3. 2> file 与上述类似,不过只会处理错误信息
  4. 将正常信息和错误信息分开输出ls -al > ok 2> bad
  5. 将正常信息和错误信息合并到一个文件输出ls -al > ok 2>&1
  6. 忽略所有信息,黑洞/dev/null, ls -al > /dev/null >2&1
  7. 标准输入 用文件内容来代替键盘输入 cat > test < ./file
  8. 自定义输入结束 cat > test << 'STOP', 当输入STOP时会结束输入

pipe |

管线对stderr无效,管线后的命令能够读取stdout

cut

cut用于处理单行数据,如果输入有多行会对每行进行同样的处理,适用于格式比较工整的输入

cut -d'divider' -fbc LIST: d: divider, c: character, b: byte, f: filed

regex

grep -n 'o\{2\}' regular_express.txt: { }需要转义,因为在bash中有特殊含义