shell必备知识

来源:互联网 发布:淘宝客服名 编辑:程序博客网 时间:2024/06/05 17:08

一、在shell中经常需要测试一些变量的状态,以下是部分测试条件

Comparisons:-eqequal to-nenot equal to-ltless than-leless than or equal to-gtgreater than-gegreater than or equal to
File Operations:-sfile exists and is not empty-ffile exists and is not a directory-ddirectory exists-xfile is executable-wfile is writable-rfile is readable

二、stdin, stdout, stderr分别等于几?

The Unix / Linux standard I/O streams with numbers:

HandleNameDescription0stdinStandard input1stdoutStandard output2stderrStandard error

三、shell 脚本中, $#、 $?、 #0分别代表什么?

$#:传递个脚本的参数个数

$?:最后运行命令的结束代码;

$0:shell本身的文件名

$$:shell本身的PID

$!:shell最后运行的后台进程的PID

$- :使用Set命令设定的Flag一览 
$* :所有参数列表。如"$*"用「"」括起来的情况、以"$1 $2 … $n"的形式输出所有参数。 
$@ :所有参数列表。如"$@"用「"」括起来的情况、以"$1" "$2" … "$n" 的形式输出所有参数。

$1~$n :添加到Shell的各参数值。$1是第1参数、$2是第2参数…。 


find 搜索文件/ 搜索文件夹

搜索文件: find ./ -type f | xargs grep "key_word"

搜索文件夹: find ./ -type d | grep "key_word"


0 0
原创粉丝点击