linux find

ROOT=$(readlink -fn $(dirname $0)/.. )
find $ROOT -not -wholename \*.tox/\* -and \( -name \*.sh -or -name \*rc -or -name functions\* \) -print0 | xargs -0 bashate -v

这个find命令写得比较复杂,来分析一下

 -not 是相反的意思

-wholename pattern
              See -path.  This alternative is less portable than -path.
-path pattern
              File name matches shell pattern pattern.  The metacharacters do not treat `/‘ or `.‘ specially; so, for example,
                        find . -path "./sr*sc"
              will  print  an  entry for a directory called `./src/misc‘ (if one exists).  To ignore a whole directory tree, use -prune rather than checking every file in the tree.  For
              example, to skip the directory `src/emacs‘ and all files and directories under it, and print the names of the other files found, do something like this:
                        find . -path ./src/emacs -prune -o -print
              Note that the pattern match test applies to the whole file name, starting from one of the start points named on the command line.  It would only make sense to use an abso‐
              lute path name here if the relevant start point is also an absolute path.  This means that this command will never match anything:
                        find bar -path /foo/bar/myfile -print
              Find  compares  the  -path argument with the concatenation of a directory name and the base name of the file it‘s examining.  Since the concatenation will never end with a
              slash, -path arguments ending in a slash will match nothing (except perhaps a start point specified on the command line).  The predicate -path is also supported  by  HP-UX
              find and is part of the POSIX 2008 standard.

expr1 -and expr2
              Same as expr1 expr2, but not POSIX compliant.


expr1 -o expr2
              Or; expr2 is not evaluated if expr1 is true.

expr1 -or expr2
              Same as expr1 -o expr2, but not POSIX compliant.

-print0, -fprint0
              Always print the exact filename, unchanged, even if the output is going to a terminal.

xargs - build and execute command lines from standard input

    -0, --null
              Input items are terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every character is taken literally).   Disables  the
              end of file string, which is treated like any other argument.  Useful when input items might contain white space, quote marks, or backslashes.  The GNU find -print0 option
              produces input suitable for this mode.

xargs 是给命令传递参数的一个过滤器,也是组合多个命令的一个工具。

xargs 可以将管道或标准输入(stdin)数据转换成命令行参数,也能够从文件的输出中读取数据。

xargs 也可以将单行或多行文本输入转换为其他格式,例如多行变单行,单行变多行。

xargs 默认的命令是 echo,这意味着通过管道传递给 xargs 的输入将会包含换行和空白,不过通过 xargs 的处理,换行和空白将被空格取代。

xargs 是一个强有力的命令,它能够捕获一个命令的输出,然后传递给另外一个命令。

之所以能用到这个命令,关键是由于很多命令不支持|管道来传递参数,而日常工作中有有这个必要,所以就有了 xargs 命令,例如:

find /sbin -perm +700 |ls -l       #这个命令是错误的
find /sbin -perm +700 |xargs ls -l   #这样才是正确的

https://www.runoob.com/linux/linux-comm-xargs.html

bashate

A pep8 equivalent for bash scripts

This program attempts to be an automated style checker for bash scripts to fill the same part of code review that pep8 does in most OpenStack projects. It started from humble beginnings in the DevStack project, and will continue to evolve over time.

https://pypi.org/project/bashate/

相关推荐