studyNote-linux-shell-find-examples

前言:本文的例子均来源于man手册第一章节的find,man 1 find查看

e.g.01

手册原文:

find /tmp -name core -type f -print | xargs /bin/rm -fFind files named core in or below the directory /tmp and delete them.  Note that this will work incorrectly if there are any filenames containing newlines, single or double quotes, or spaces.

效果:
删除/tmp路径下面名字为core的普通文件,但是文件不能够有换行符、单引号、双引号和空格符,否则会出错。

e.g.02

手册原文:

find /tmp -name core -type f -print0 | xargs -0 /bin/rm -fFind files named core in or below the directory /tmp and delete them, 
processing filenames in such a way that file or directory names containing single or double quotes, 
spaces or newlines are correctly handled.  
The -name test comes before the -type test in order to avoid having to call stat(2) on every file.

效果:
删除/tmp路径下面名字为core的普通文件,和上面的区别就是文件可以有换行符、单引号、双引号和空格符,因为用字符\0隔开了。

e.g.03

手册原文:

find . -type f -exec file '{}' \;Runs `file' on every file in or below the current directory.
Notice that the braces are enclosed in single quote marks to protect them from interpretation as shell script punctuation.  
The semicolon is similarly protected by the use of a backslash, though single quotes could have been used in that case also.

效果:
对当前目录下每个文件执行file命令。这里的{}在执行命令的时候会被替换成找到的文件名,这里的;是作为exec选项的参数,不然exec命令就不完整了。(注意: ‘{}’ ;加单引号和转移符号都是为了避免shell错误解释)

e.g.04

手册原文:

find / \( -perm -4000 -fprintf /root/suid.txt '%#m %u %p\n' \) , \\( -size +100M -fprintf /root/big.txt '%-10s %p\n' \)Traverse the filesystem just once, 
listing setuid files and directories into /root/suid.txt and large files into /root/big.txt.

效果:
递归查找根目录下具有SUID(Set User ID)权限的文件,并将结果输出到/root/suid.txt文件中;大于100M的文件,将结果输出到/root/big.txt文件中。然后前者的输出格式是这个%#m %u %p\n,后者输出的格式%-10s %p\n是这个。第一行末尾 \只是一行的连接符,别看错了。

e.g.05

手册原文:

find $HOME -mtime 0Search for files in your home directory which have been modified in the last twenty-four hours.  
This command works this way because the time since each file was last modified is divided by 24 hours and any remainder is discarded.  
That means that to match -mtime 0, a file will have to have a modification in the past which is less than 24 hours ago.

效果:
查找用户家目录下所有在24小时内修改过的文件。它是这样算的,-mtime 后面的0是由文件当前修改后的时间/24小时,所以0就代表修改不超过一天,1就代表修改不超过2天,依此类推。

e.g.06

手册原文:

find /sbin /usr/sbin -executable \! -readable -printSearch for files which are executable but not readable.

效果:
查找 /sbin 和 /usr/sbin 目录下所有可执行但不可读的文件(针对文件所有者用户)。

e.g.07

手册原文:

find . -perm 664Search for files which have read and write permission for their owner, and group, but which other users can read but not write to.  
Files which meet these criteria but have other permissions bits set (for example if someone can execute the file) will not be matched.

效果:
查找当前文件夹下面文件权限为664的文件

e.g.08

手册原文:

find . -perm -664Search for files which have read and write permission for their owner and group, and which other users can read, 
without regard to the presence of any extra permission bits (for example the executable bit).  
This will match a file which has mode 0777, for example.

效果:
查找当前文件夹下面文件权限至少为664的文件,比如说你的权限666也可以

e.g.09

手册原文:

find . -perm /222Search for files which are writable by somebody (their owner, or their group, or anybody else).

效果:
查找当前文件夹中至少有一组的写权限是有的 的 文件。

e.g.10

手册原文:

find . -perm /220
find . -perm /u+w,g+w
find . -perm /u=w,g=wAll  three  of  these commands do the same thing, 
but the first one uses the octal representation of the file mode, 
and the other two use the symbolic form.
These commands all search for files which are writable by either their owner or their group. 
The files don't have to be writable by both the owner and group to be matched; either will do.

效果:
查找当前文件夹中至少有一组(对于文件所有者和同组的用户)的写权限是有的 的 文件。

e.g.11

手册原文:

find . -perm -220
find . -perm -g+w,u+wBoth these commands do the same thing; search for files which are writable by both their owner and their group.

效果:
查找当前文件夹中所有者和同组都有写权限的文件。

e.g.12

手册原文:

find . -perm -444 -perm /222 \! -perm /111
find . -perm -a+r -perm /a+w \! -perm /a+xThese two commands both search for files that are readable for everybody ( -perm -444 or -perm -a+r), 
have at least one write bit set ( -perm /222 or -perm /a+w) but are not executable for anybody ( ! -perm /111 and ! -perm /a+x respectively).

效果:
查找文件所有者和同组和其他人都有读权限,并且所有者和同组和其他人中至少有一个有写权限,并且所有者和同组和其他人都没有执行权限。

e.g.13

手册原文:

cd /source-dir
find . -name .snapshot -prune -o \( \! -name '*~' -print0 \)|
cpio -pmd0 /dest-dirThis command copies the contents of /source-dir to /dest-dir, 
but omits files and directories named .snapshot (and anything in them).  
It also omits files or directories whose name ends in ~, 
but not their contents.  
The construct -prune -o \( ... -print0 \) is quite common.  
The idea here is  that the  expression before -prune matches things which are to be pruned.  
However, the -prune action itself returns true, 
so the following -o ensures that the right hand side is evaluated only for those directories which didn't get pruned (the contents of the pruned directories are not even visited, so their contents are irrelevant).  
The expression on the right hand side of the -o is in parentheses only for clarity.  
It emphasises that the -print0 action takes place only for things that didn't have -prune applied to them.  
Because the default `and' condition between tests binds more tightly than 
-o, this is the default anyway, but the parentheses help to show what is going on.

效果:
查找/source-dir目录下文件的时候忽略以这个.snapshot结尾的文件,然后不要输出以~结尾的文件并以\0隔开,然后将这些输出通过管道符号,拷贝到根目录下面的/dest-dir文件夹里面去。

cpio: 是一个用于归档和备份的命令行工具。cpio通常与find命令结合使用,以复制目录结构。
-p: 表示保留文件的原始权限、所有者和时间戳信息。
-m: 表示创建必要的目录结构。
-d0: 表示使用空字符作为分隔符读取输入文件名,与上面匹配。

e.g.14

手册原文:

find repo/ \( -exec test -d '{}'/.svn \; -or \
-exec test -d {}/.git \; -or -exec test -d {}/CVS \; \) \
-print -pruneGiven the following directory of projects and their associated SCM administrative directories, perform an efficient search for the projects' roots:repo/project1/CVS
repo/gnu/project2/.svn
repo/gnu/project3/.svn
repo/gnu/project3/src/.svn
repo/project4/.gitIn this example, -prune prevents unnecessary descent into directories that have already been discovered (for example we do not search project3/src because we already found project3/.svn), 
but ensures sibling directories (project2 and project3) are found.

效果:
这个find命令的作用是在repo/目录及其子目录下查找使用特定版本控制系统(CVS、SVN 或 Git)管理的项目根目录。

  • find repo/: 从repo/目录开始搜索。

  • -exec test -d '{}'/.svn \;: 对于每一个找到的文件或目录,执行test -d命令检查该路径下的.svn目录是否存在。如果存在,则表示该项目使用了Subversion(SVN)作为版本控制系统。

  • -or -exec test -d {}/.git \;: 类似地,检查当前路径下是否包含.git目录,如果存在,则说明该项目使用了Git作为版本控制系统。

  • -or -exec test -d {}/CVS \;: 同样地,检查当前路径下是否包含CVS目录,存在则表示该项目使用了Concurrent Versions System (CVS) 作为版本控制系统。

  • -print: 当满足上述条件之一时,打印出匹配的项目根目录路径。

  • -prune: 如果在当前路径下找到了SCM管理目录(即.svn.gitCVS),那么就不再继续深入到该路径的子目录中进行搜索。这样可以避免对已经找到的项目根目录的子目录重复搜索,提高了搜索效率,并确保了同一层级含有不同版本控制系统管理的项目都能被发现。

对于给出的例子,在执行完此命令后,将输出以下内容:

repo/project1/CVS
repo/gnu/project2/.svn
repo/gnu/project3/.svn
repo/project4/.git

这些路径代表的就是使用对应版本控制系统管理的项目根目录。

e.g.15

手册原文:

find /tmp -type f,d,lSearch for files, directories, and symbolic links in the directory /tmp passing these types as a comma-separated list (GNU extension), 
which is otherwise equivalent to the longer, yet more portable:find /tmp \( -type f -o -type d -o -type l \)

效果:
在/tmp路径下面查找普通文件、目录、链接文件这几个文件类型的文件,find /tmp ( -type f -o -type d -o -type l )写法方便移植。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/659748.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Unity | 资源热更(YooAsset AB)

目录 一、AssetBundle 1. 插件AssetBundle Browser 打AB包 (1)Unity(我用的版本是2020.3.8)导入AssetBundle Browser (2)设置Prefab (3)AssetBundleBrowser面板 2. 代码打AB包…

nodejs历史版本下载

Node.js — Previous Releases下载地址 .msi 是安装包(windows),下载安装包即可

java实现flv转mp4/视频格式转换

引言 今天在开发过程中&#xff0c;突然遇到给前端flv格式视频还播放不了&#xff0c;flv在开发印象中就是跟mp4格式差不多&#xff0c;本地静态视频资源&#xff0c;怎么还就播放不了&#xff0c;为此只能特别做下视频转换。 How to do 1.提前引入包 <!--视频多媒体工具…

关于最小系统板PCB设计后的一些反思

简介 趁着刚刚画完板子寄回来&#xff0c;在这里做一些记录。 板子状况 这里打烊了5块PCB&#xff0c;但是没有进行SMT贴片&#xff0c;后续如果有芯片可以焊接上去进行后续验证。 封装问题 这里可以看到&#xff0c;我这里两侧的排针都是焊盘&#xff0c;不是通孔&#…

Unity_Timeline使用说明

Unity_Timeline使用说明 首先要找到工具吧&#xff1f;Unity2023.1.19f1c1打开如下&#xff1a; &#xff08;团结引擎没找见哪儿打开&#xff0c;可能是引擎问题吧&#xff1f;有知道的同学可以告诉我在哪儿打开&#xff09; Timelime使用流程&#xff1a; 打开之后会提示您…

ClickHouse为什么这么快(二)SSE指令优化

上一篇 ClickHouse为什么这么快&#xff08;一&#xff09;减少数据扫描范围 我们说到了ClickHouse中使用列存储&#xff0c;每个列都单独存储为一个文件&#xff0c;每个文件都是由一个或多个数据块组成&#xff0c;也就是说&#xff1a;每个文件由一个或多个数组组成&#xf…

3分钟阅读100篇文献?GPT可以做到!

摘要和背景 PPMAN-AI 01 在开始深入阅读之前&#xff0c;了解文献的主题和背景是非常重要的。这可以帮助你快速判断该文献是否符合你的研究需求。 prompt&#xff1a; 请简述文献[文献标题]的摘要。 解释文献[文献标题]中提到的研究背景。 文献[文献标题]的主要研究目的是什…

WordPress块编辑器(Gutenberg古腾堡)中如何添加脚注?

WordPress默认自带的块编辑器​&#xff08;Gutenberg古腾堡编辑器&#xff09;本身就自带添加脚注功能&#xff0c;不过经典编辑器不行。如果想要在WordPress中添加更加专业的脚注&#xff0c;建议使用Modern Footnotes插件&#xff0c;具体介绍及使用请参考『WordPress站点如…

【计算机图形】几何(Geometry)和拓扑(Topology)

目录 参考文献三维实体建模内核CSG/BREPParasolid简介Parasolid接口函数Parasolid类的结构 Parasolid数据分类&#xff1a;几何(Geometry)和拓扑(Topology)拓扑(Topology)什么是“拓扑”呢&#xff1f;Principle Geometry- Topology - Construction Geometry案例&#xff1a;拓…

ElementUI Form:Switch 开关

ElementUI安装与使用指南 Switch 开关 点击下载learnelementuispringboot项目源码 效果图 el-switch.vue 页面效果图 项目里el-switch.vue代码 <script> export default {name: el_switch,data() {return {value: true,value1: true,value2: true,value3: 100,value…

「实战应用」如何用DHTMLX Gantt构建类似JIRA式的项目路线图(三)

DHTMLX Gantt是用于跨浏览器和跨平台应用程序的功能齐全的Gantt图表。可满足项目管理应用程序的所有需求&#xff0c;是最完善的甘特图图表库。 在web项目中使用DHTMLX Gantt时&#xff0c;开发人员经常需要满足与UI外观相关的各种需求。因此他们必须确定JavaScript甘特图库的…

经典目标检测YOLO系列(三)YOLOv3的复现(2)正样本的匹配、损失函数的实现

经典目标检测YOLO系列(三)YOLOv3的复现(2)正样本的匹配、损失函数的实现 我们在之前实现YOLOv2的基础上&#xff0c;加入了多级检测及FPN&#xff0c;快速的实现了YOLOv3的网络架构&#xff0c;并且实现了前向推理过程。 经典目标检测YOLO系列(三)YOLOV3的复现(1)总体网络架构…

将应用的log4j换成logback

将应用的log4j换成logback 考虑到log4j很久不更新、性能相对弱&#xff0c;以及一些项目本身的原因&#xff0c;经过较为谨慎的考虑&#xff0c;决定改用logback。迁移还是比较顺利的&#xff0c;花了1个小时左右就搞定了&#xff0c;做个简单的笔记。 (1) 首先去掉所有log4j…

MFC串行化的应用实例

之前写过一篇MFC串行化的博文;下面看一个具体例子; 新建一个单文档应用程序;在最后一步,把View类的基类改为CFormView; 然后在资源面板编辑自己的字段; 然后到doc类的头文件添加对应变量, public:CString name;int age;CString sex;CString dept;CString zhiwu;CStrin…

C#中的装箱和拆箱操作详解

在C#中&#xff0c;“装箱”&#xff08;Boxing&#xff09;和"拆箱"&#xff08;Unboxing&#xff09;是类型转换的过程&#xff0c;特别是在值类型和引用类型之间的转换。 1、 装箱&#xff08;Boxing&#xff09; 装箱是指将一个值类型&#xff08;例如整数、浮…

蓝桥杯2024/1/31----第十届省赛题笔记

题目要求&#xff1a; 1、 基本要求 1.1 使用大赛组委会提供的国信长天单片机竞赛实训平台&#xff0c;完成本试题的程序设计 与调试。 1.2 选手在程序设计与调试过程中&#xff0c;可参考组委会提供的“资源数据包”。 1.3 请注意&#xff1a; 程序编写、调试完成后选手…

JAVA Web 学习(二)ServLet

二、动态web 资源开发技术——Servlet Servlet&#xff08;小服务程序&#xff09;是一个与协议无关的、跨平台的Web组件&#xff0c;由Servlet容器所管理。运行在服务器端&#xff0c;可以动态地扩展服务器的功能&#xff0c;并采用“请求一响应”模式提供Web服务。 Servlet的…

将java对象转换为json字符串的几种常用方法

目录 1.关于json 2.实现方式 1.Gson 2.jackson 3.fastjson 3.与前端的联系 1.关于json JSON是一种轻量级的数据交换格式。它由Douglas Crockford在2001年创造。JSON的全称是JavaScript Object Notation&#xff0c;它是一种文本格式&#xff0c;可以轻松地在各种平台之间传…

一文详解docker compose

文章目录 1、前言2、Compose 简介3、compose的安装和卸载3.1、安装3.2、卸载3.3、使用 4、yml 配置指令参考5、Compose 命令说明5.1、命令对象与格式5.2、命令选项5.3、命令使用详细说明 6、compose使用案例6.1、准备6.2、Dockerfile 文件6.3、docker-compose.yml6.4、使用 Com…

C#学习笔记_类(Class)

类的定义 类的定义是以关键字 class 开始&#xff0c;后跟类的名称。类的主体&#xff0c;包含在一对花括号内。 语法格式如下&#xff1a; 访问标识符 class 类名 {//变量定义访问标识符 数据类型 变量名;访问标识符 数据类型 变量名;访问标识符 数据类型 变量名;......//方…