[求助]find的-exec -execdir ; +用法
发表于 : 2008-03-09 11:32
1.书上说 +比;好,man 里面也说;是对找到的每个文件都应用一次-exec后的命令,而+是把找到的命令放到一行来处理. 但我用+老是提示出问题:
find . -name '*.txt' -exec cp {} /tmp \+
就提示
find: 遗漏“-exec”的参数
换成find . -name '*.txt' -exec cp {} /tmp \;
find . -name '*.txt' -exec ls {} \+ 都没问题啊 到底哪儿遗漏参数呢?
一直没搞明白
2.对于 工作目录和其子目录下都有一个1.txt, -exec不可同时改名,-execdir就没问题:
find . -name 1.txt -execdir mv {} 2.txt \;
下面两段看了好些遍还不是太了解,哪位可以简单解释下
-exec command ;
The command is executed in the starting directory.
There are unavoidable security problems surrounding use of the -exec option; you should use the -execdir option instead.
-execdir command {} +
Like -exec, but the specified command is run from the subdirectory containing the matched file, which is not normally the directory in which you started find. This a much more secure method for invoking commands, as it avoids race conditions during resolution of the paths to the matched files. As with the -exec option, the ’+’ form of -execdir will build a command line to process more than one matched file, but any given invocation of command will only list files that exist in the same subdirectory. If you use this option, you must ensure that your $PATH environment variable does not reference the current directory; otherwise, an attacker can run any commands they like by leaving an appropriately-named file in a directory in which you will run -execdir.
find . -name '*.txt' -exec cp {} /tmp \+
就提示
find: 遗漏“-exec”的参数
换成find . -name '*.txt' -exec cp {} /tmp \;
find . -name '*.txt' -exec ls {} \+ 都没问题啊 到底哪儿遗漏参数呢?
一直没搞明白
2.对于 工作目录和其子目录下都有一个1.txt, -exec不可同时改名,-execdir就没问题:
find . -name 1.txt -execdir mv {} 2.txt \;
下面两段看了好些遍还不是太了解,哪位可以简单解释下
-exec command ;
The command is executed in the starting directory.
There are unavoidable security problems surrounding use of the -exec option; you should use the -execdir option instead.
-execdir command {} +
Like -exec, but the specified command is run from the subdirectory containing the matched file, which is not normally the directory in which you started find. This a much more secure method for invoking commands, as it avoids race conditions during resolution of the paths to the matched files. As with the -exec option, the ’+’ form of -execdir will build a command line to process more than one matched file, but any given invocation of command will only list files that exist in the same subdirectory. If you use this option, you must ensure that your $PATH environment variable does not reference the current directory; otherwise, an attacker can run any commands they like by leaving an appropriately-named file in a directory in which you will run -execdir.