@1:在单个命令中创建目录树:
不要逐层创建目录,尽量使用mkdir的-p选项:
~$ mkdir -p one/two/three # 假设目录one不存在
创建复杂的目录树:
~$ mkdir -p ./{a/{c,d/e/{f/h,g/i}},b} # 假设目录a不存在
@2:使用选项 -C 来解压缩 .tar 文件到指定的目录(如tmp/a/b/c)
~$ tar xvf -C tmp/a/b/c filename.tar.gz
@3:NOTE the differences between the following 2 expressions: Be careful of the wildcard.
~$ VAR="tmp/*" ~$ echo $VAR tmp/* ~$ echo "$VAR" tmp/* ~$ echo "${VAR}a" tmp/*a ~$ echo ${VAR}a tmp/a ~$
@4:xargs:
#1:
~$ find ./ -name "*.sh"|xargs grep "string"
#2:
~$ ls|xargs file
@5:time: 执行命令所耗费的时间
~$ time find ./ -name "*.sh"|xargs grep "string" ./dirInfo.sh: #read -p: If there are some ‘Escape Characters‘ in the prompt string, there will be something unexpected. real 0m0.007s user 0m0.004s sys 0m0.000s
@6:grep不需要cat
提倡
~$ time grep "lxw" basicShellScripts.sh Author: lxw real 0m0.003s user 0m0.000s sys 0m0.000s
不提倡:
~$ time cat basicShellScripts.sh|grep "lxw" Author: lxw real 0m0.004s user 0m0.000s sys 0m0.000s
参考文章:
UNIX 高手的 10 个习惯:http://www.admin10000.com/document/3696.html
Tips for Unix/Linux,布布扣,bubuko.com
原文:http://www.cnblogs.com/lxw0109/p/tips_for_unix_linux.html