find学习笔记(2)

 

 

 

  1. 一次处理一个文件

如果文件位于末尾,{}是可选的

但是如果文件在中,还是需要{}

命令的结束 ;

find . -name '*.h' -execdir diff -u '{}' /tmp/master ';'

 

另外{},;在会被shell解析,所以需要引号

 

  1. 一次处理多个文件

{} + 是结尾

a. 只能有个一个{},且是末尾

b. 只有{} + 才是结尾

c. 结果一定返回0

 

只能让文件放在末尾可能对有些命令不方便

可以使用sh -c作为w/a

find startpoint -tests -exec sh -c 'scp "$@" remote:/dest' sh {} +

 

  1. exec于execdir的区别

exec是execdir的不安全的变种

execdir安全规则:

使用-execdir,你必须保证$PATH变量只包含绝对目录名

‘/bin:/usr/bin:’

Insecure; empty path element (at the end)

 

‘:/bin:/usr/bin:/usr/local/bin’

Insecure; empty path element (at the start)

 

‘/bin:/usr/bin::/usr/local/bin’

Insecure; empty path element (two colons in a row)

 

‘/bin:/usr/bin:.:/usr/local/bin’

Insecure; ‘.’ is a path element (. is not an absolute file name)

 

‘/bin:/usr/bin:sbin:/usr/local/bin’

Insecure; ‘sbin’ is not an absolute file name

 

‘/bin:/usr/bin:/sbin:/usr/local/bin’

Secure (if you control the contents of those directories and any access to them)

 

控制PATH,保证command的可控性

 

execdir如果发现不安全,拒绝执行命令

 

posted @ 2021-02-06 10:30  郭复强  阅读(60)  评论(0)    收藏  举报