首页 > 其他 > 详细

Tips for Unix/Linux

时间:2014-03-08 21:40:58      阅读:402      评论:0      收藏:0      [点我收藏+]

@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.

bubuko.com,布布扣
~$ VAR="tmp/*"
~$ echo $VAR
tmp/*
~$ echo "$VAR"
tmp/*
~$ echo "${VAR}a"
tmp/*a
~$ echo ${VAR}a
tmp/a
~$
bubuko.com,布布扣

 

@4:xargs:
#1:

~$ find ./ -name "*.sh"|xargs grep "string"

#2:

~$ ls|xargs file

 

@5:time: 执行命令所耗费的时间 

bubuko.com,布布扣
~$ 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
bubuko.com,布布扣

  

@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

Tips for Unix/Linux

原文:http://www.cnblogs.com/lxw0109/p/tips_for_unix_linux.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!