BobbyTang 发表于 2013-2-4 13:42:55

Shell快速入门及实用命令

1.重定向
 
标准输出和错误输出重定向到all_result
find /home -name lost* > all_result 2>&1
标准输出和错误输出追加到all_result
find /home -name lost* >> all_result 2>&1
不输出错误日志
find /home -name lost* 2> /dev/null
正确错误日志均不显示
find /home -name lost* > /dev/null 2>&1
 
2.打包再解压,优势在不同处于同一个服务器
$ (cd /source/directory && tar cf - . ) | (cd /dest/directory && tar xvfp -)
 http://andrewfraserdba.com/2009/03/05/using-tar-with-compress-or-gzip/
3. 比较命令
 
在比较操作上,整数变量和字符串变量各不相同,详见下表:
 
 
对应的操作
整数操作
字符串操作
相同
-eq
=
不同
-ne
!=
大于
-gt
> 
小于
-lt
< 
大于或等于
-ge
 
小于或等于
-le
 
为空
 
-z
不为空
 
-n
 
 
更细致的文档推荐在字符串比较时尽量不要使用 -n ,而用 ! -z 来代替。(其中符号 "!" 表示求反操作)
4. 文件比较
 
运算符
含义( 满足下面要求时返回 TRUE )
-e file
文件 file 已经存在
-f file
文件 file 是普通文件
-s file
文件 file 大小不为零
-d file
文件 file 是一个目录
-r file
文件 file 对当前用户可以读取
-w file
文件 file 对当前用户可以写入
-x file
文件 file 对当前用户可以执行
-g file
文件 file 的 GID 标志被设置
-u file
文件 file 的 UID 标志被设置
-O file
文件 file 是属于当前用户的
-G file
文件 file 的组 ID 和当前用户相同
file1 -nt file2
文件 file1 比 file2 更新
file1 -ot file2
文件 file1 比 file2 更老
6.
 
参考
http://club.topsage.com/thread-195918-1-1.html
页: [1]
查看完整版本: Shell快速入门及实用命令