• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > 应该在find命令中使用-execdir代替-exec

应该在find命令中使用-execdir代替-exec

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了find exec,linux find exec,find name exec,shell find exec,linux exec命令等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

应该在find命令中使用-execdir代替-exec


没事的时候读读 Linux 的 man 文档能学到不少新东西,注意到以前没注意过的细节。

比如刚才在看 find 命令的文档时就发现了下面这 2 段话:

-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 processedeverywhere 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 con‐
structions 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.


-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 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 $PATH which are empty or which are not absolute directory names.


注意看红字。

第 1 段话的意思是可以在 -exec 参数后接上花括号 {} 来表示每一个被找到的对象并执行操作,但每次执行操作的调用都是你执行 find 命令的目录,这可能导致竞态(find命令正在解析的路径和执行操作的命令使用的路径相同)的发生所以存在安全风险。因此应该使用 -execdir 参数替代 -exec。

第 2 段话的意思是 -execdir 参数的作用和 -exec 相同,区别在于前者每次对被找到的对象执行操作时都是在这些对象所在的目录下执行的,因此可以避免竞态。

同样的,也应该使用 -okdir 参数替代 -ok 参数使用。


分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 应该在find命令中使用-execdir代替-exec

相关文章

  • 2017-05-26android studio下百度地图sdk的初体验
  • 2017-07-23WKWebView与js交互之完美解决方案
  • 2017-05-26安卓开源项目周报0405,安卓开源项目0405
  • 2017-05-26Android中的沉浸式状态栏效果,android沉浸状态栏
  • 2017-05-26Android动态加载Activity原理
  • 2017-05-26Android开发学习——打电话应用,android开发打电话
  • 2017-05-26浅谈Android应用保护(一):Android应用逆向的基本方法,浅谈android
  • 2017-05-26FlatBuffers初探,flatbuffers
  • 2017-05-26MVP模式在Android开发中的最佳实践
  • 2017-05-26Volley的基本使用,Volley使用

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 快速自动更新Android Studio版本
    • java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INSTANCE,apachemessagequeue
    • Android Support 包知识,androidsupport
    • Android 代码动态改变View的属性
    • Android保持屏幕常亮,android屏幕常亮
    • Android开发代码规范,android开发代码
    • AsyncTask注意事项,面试技巧和注意事项
    • Android热补丁动态修复实践
    • android动画详解一 概述
    • Android中AsyncTask基本用法与源码剖析(API 23)

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有