这个linux脚本函数的作用是什么? [英] What does this line of a linux script function do?

查看:81
本文介绍了这个linux脚本函数的作用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查找$ file_path -mtime +1 -name* log。* - exec rm {} \; -exec echo {}'已被删除'\;



我尝试过:



这很好用,但我需要知道我们如何在这段代码中使用-exec的东西。

find $file_path -mtime +1 -name "*log.*" -exec rm {} \; -exec echo {} 'was deleted' \;

What I have tried:

This works well, but I need to know how we are using that -exec thing in this code.

推荐答案

file_path -mtime +1 - name* log。* - exec rm {} \; -exec echo {}'已被删除'\;



我尝试过:



这很好用,但我需要知道我们在这段代码中如何使用-exec的东西。
file_path -mtime +1 -name "*log.*" -exec rm {} \; -exec echo {} 'was deleted' \;

What I have tried:

This works well, but I need to know how we are using that -exec thing in this code.


find(1) - Linux手册页 [ ^ ]向您解释:

find(1) - Linux man page[^] explains that to you:
Quote:

-exec 命令;

执行命令;如果返回0状态,则返回true。 find 的所有后续参数都被视为命令的参数,直到遇到由';'组成的参数

。字符串'{}'被当前正在处理的当前文件名替换,它出现在命令的参数中,

不仅仅是在单独的参数中,如某些版本的发现的。这两个结构都可能需要转义(使用'\')或引用

保护它们不被shell扩展。有关使用 -exec 选项的示例,请参阅示例部分。对于每个匹配的文件,指定的命令运行一次

。该命令在起始目录中执行。使用 -exec 操作时存在不可避免的安全问题;

您应该使用 -execdir 选项。

-exec 命令 {} +

-exec 的这个变种action在所选文件上运行指定的命令,但命令行是通过在结尾附加每个选定的文件名

来构建的;命令的调用总数将远远少于匹配文件的数量。命令行的构建方式大致相同

xargs 构建命令行。命令中只允许一个{}实例。该命令在起始目录中执行。

-execdir 命令;

-execdir 命令 {} +

-exec 类似,但指定的命令是从包含该命令的子目录运行的匹配的文件,通常不是您开始查找的目录。这是一种更安全的调用命令的方法,因为它可以在解析匹配文件的路径时避免竞争条件。对于带有 -exec 操作的
-execdir 的'+'形式将构建一个命令行来处理多个匹配的文件,但任何给定的

命令的调用只会列出存在于同一子目录中的文件。如果使用此选项,则必须确保

-exec command ;
Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments to the command until an argument
consisting of ';' is encountered. The string '{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command,
not just in arguments where it is alone, as in some versions of find. Both of these constructions might need to be escaped (with a '\') or quoted to
protect them from expansion by the shell. See the EXAMPLES section for examples of the use of the -exec option. The specified command is run once
for each matched file. The command is executed in the starting directory. There are unavoidable security problems surrounding use of the -exec action;
you should use the -execdir option instead.
-exec command {} +
This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name
at the end; the total number of invocations of the command will be much less than the number of matched files. The command line is built in much the same way
that xargs builds its command lines. Only one instance of '{}' is allowed within the command. The command is executed in the starting directory.
-execdir command ;
-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 action, 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 环境变量

不引用'。';否则,攻击者可以通过在您将运行的目录中保留适当命名的文件来运行他们喜欢的任何命令

-execdir 。这同样适用于
PATH environment variable
does not reference '.'; otherwise, an attacker can run any commands they like by leaving an appropriately-named file in a directory in which you will run
-execdir. The same applies to having entries in


这篇关于这个linux脚本函数的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆