常用Linux命令汇总

查找 type whereis locate which find grep -v -i 历史 !! !997 !?CF? !ls:s/CF/l fc 打开指定历史(fc987) sort 排序 |xargs 传递 awk ‘{print $2}’ 流编辑,输出第2列 alisa watch whoami 测试 = -eq -ge -gt -le -lt != -ne mkpipe 创建管道命令 mksock 创建套接字 chmod umask 切换 pwd pushd dirs popd cp dd mount …

常用文本处理工具

sort 排序,依照行或自定义字段 SYNOPSIS sort [OPTION]… [FILE]… sort [OPTION]… –files0-from=F DESCRIPTION Write sorted concatenation of all FILE(s) to standard output. With no FILE, or when FILE is -, read standard input. Mandatory arguments to long options are mandatory for short options too. Ordering options: -b, –ignore-leading-blanks ignore leading blanks -d, –dictionary-order …

正则表达式

meta字符 ^ 锚定行或字符串的开始 $ 锚定行或字符串的结束 非换行字符 * 匹配多个先前字符或个数为0 […] 匹配方括号中任一字符或范围[-] \ 打开或关闭后续字符的特殊含义,BRE,ERE支持不同 B  \(\) 标记匹配字符,将\(和\)之间的模式存储在保留空间中,后续使用转义序列引用匹配的模式 B  \n 重复\(与\)内的第n个模式 B=E  x\{m,n\} = x{m,n} x至少出现m次,最多n次 + ? | () 支持正则表达式的工具 grep sed awk  python  perl  Tcl more  page  less ed  vi  emacs vim POSIX BRE和ERE都支持的meta字符(元字符,特殊字符) ^ 匹配字符串开始 $ 匹配字符串结尾 . 匹配非换行字符 * …

循环

for循环 for…in… do … done   for name do case $name in -f)… -d)… esac done   while循环(当条件为真) while condition do statements… done   until循环(直到条件为真) until condition do statements… done   遍历PATH路径 path=$PATH    #变量声明 while [ -n $PATH ]    #当变量不为空时 do ls -ld ${path%%:*}    #以ls -ld列出path第一个目录 path=${path#*:}    #截去第一个目录和冒号 done   …

case语句

case expression in pattern1) statements;; pattern2) statements;; pattern3 | pattern4) statements;; … esac     case $1 in -f) … -d) … esac   case $1 in *.jpg) gpview $1;; *.txt) gvim $1;; *.avi | *.wmv mplayer $1;; *.pdf) acroread $1;; *) echo $1:Don’t know how to read this file;; …

操作符(如果……则为真)

str1 = str2 str1 != str2 str1 < str2 str1 > str2 -n str1   str1为非null(长度大于0) -z str1   str1为非null(长度为0)   常用操作符(为真) -b 块设备文件 -c 字符设备文件 -d 目录 -e 存在 -f 一般文件 -g file file有设置它的setgid位 -h 符号链接 -L 符号链接 -p 管道 -r 可读 -S 套接字 -s 非空 -u file有设置它的setgid位 -w 可写 -x …