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、.git或CVS),那么就不再继续深入到该路径的子目录中进行搜索。这样可以避免对已经找到的项目根目录的子目录重复搜索,提高了搜索效率,并确保了同一层级含有不同版本控制系统管理的项目都能被发现。
对于给出的例子,在执行完此命令后,将输出以下内容:
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 )写法方便移植。
相关文章:
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 incor…...
使用 Python 进行自然语言处理第 3 部分:使用 Python 进行文本预处理
一、说明 文本预处理涉及许多将文本转换为干净格式的任务,以供进一步处理或与机器学习模型一起使用。预处理文本所需的具体步骤取决于具体数据和您手头的自然语言处理任务。 常见的预处理任务包括: 文本规范化——将文本转换为标准表示形式,…...
Python新春烟花盛宴
写在前面 哈喽小伙伴们,博主在这里提前祝大家新春快乐呀!我用Python绽放了一场新春烟花盛宴,一起来看看吧! 环境需求 python3.11.4及以上PyCharm Community Edition 2023.2.5pyinstaller6.2.0(可选,这个库…...
【QT+QGIS跨平台编译】之二十:【xerces+Qt跨平台编译】(一套代码、一套框架,跨平台编译)
文章目录 一、xerces介绍二、文件下载三、文件分析四、pro文件五、编译实践一、xerces介绍 Xerces是一个开源的XML解析器,由Apache软件基金会维护。它是用Java语言编写的,提供了对XML文档进行解析、验证和操作的功能。Xerces具有高性能和广泛的兼容性,可用于各种Java应用程…...
18.通过telepresence调试部署在Kubernetes上的微服务
Telepresence简介 在微服务架构中,本地开发和调试往往是一项具有挑战性的任务。Telepresence 是一种强大的工具,使得开发者本地机器上开发微服务时能够与运行在 Kubernetes 集群中的其他服务无缝交互。本文将深入探讨 Telepresence 的架构、运行原理,并通过实际的案例演示其…...
QT 范例阅读:系统托盘 The System Tray Icon example
main.cpp QApplication app(argc, argv);//判断系统是否支持 系统托盘功能if (!QSystemTrayIcon::isSystemTrayAvailable()) {QMessageBox::critical(0, QObject::tr("Systray"),QObject::tr("I couldnt detect any system tray ""on this system.&qu…...
OpenAI Gym 高级教程——深度强化学习库的高级用法
Python OpenAI Gym 高级教程:深度强化学习库的高级用法 在本篇博客中,我们将深入探讨 OpenAI Gym 高级教程,重点介绍深度强化学习库的高级用法。我们将使用 TensorFlow 和 Stable Baselines3 这两个流行的库来实现深度强化学习算法ÿ…...
K8sGPT 会彻底改变你对 Kubernetes 的认知
在不断发展的 Kubernetes (K8s) 环境中,AI 驱动技术的引入继续重塑我们管理和优化容器化应用程序的方式。K8sGPT 是一个由人工智能驱动的尖端平台,在这场变革中占据了中心位置。本文探讨了 K8sGPT 在 Kubernetes 编排领域的主要特…...
计组学习笔记2024/2/4
1.计算机的发展历程 2.计算机硬件的基本组成 存储器 -> 就是内存. 3.各个硬件的部件 寄存器 -> 用来存放二进制数据. 各个硬件的工作原理视频留白,听完后边课程之后再来理解理解. 冯诺依曼计算机的特点: 1.计算机由五大部件组成 2.指令和数据以同等地位存于存储器,…...
25种Google的搜索技巧
背景 目前浏览器、搜索引擎,想必各位已经很熟悉了,但不代表想要知道的事情就一定可以通过搜索引擎搜索出来。大部分人的搜索技巧都在小学。所以本文就会系统总结一个 GOOGLE 搜索的一些技巧,来提高搜索效率。 首先呢,本文只保证 GOOGLE 有效,其他搜索引擎自己尝试,因为我…...
769933-15-5,Biotin aniline,可以合成多种有机化合物和聚合物
您好,欢迎来到新研之家 文章关键词:769933-15-5,Biotin aniline,生物素苯胺,生物素-苯胺 一、基本信息 产品简介:Biotin Aniline,一种具有重要生物学功能的化合物,不仅参与了维生…...
回归预测 | Matlab实现POA-CNN-LSTM-Attention鹈鹕算法优化卷积长短期记忆网络注意力多变量回归预测(SE注意力机制)
回归预测 | Matlab实现POA-CNN-LSTM-Attention鹈鹕算法优化卷积长短期记忆网络注意力多变量回归预测(SE注意力机制) 目录 回归预测 | Matlab实现POA-CNN-LSTM-Attention鹈鹕算法优化卷积长短期记忆网络注意力多变量回归预测(SE注意力机制&…...
B站视频在电商中的应用:如何利用item_get_video API提高转化率
在数字媒体时代,视频已成为电商领域中不可或缺的营销工具。B站作为中国最大的弹幕视频网站之一,拥有庞大的用户群体和活跃的社区。将B站与电商结合,利用其独特的视频API(如item_get_video)可以带来诸多商业机会。本文将…...
【Linux】统信服务器操作系统V20 1060a-AMD64 Vmware安装
目录 编辑 一、概述 1.1 简介 1.2 产品特性 1.3 镜像下载 二、虚拟机安装 一、概述 1.1 简介 官网:统信软件 – 打造操作系统创新生态 统信服务器操作系统V20是统信操作系统(UOS)产品家族中面向服务器端运行环境的,是一款…...
c++类继承
一、继承的规则 (1)基类成员在派生类中的访问权限不得高于继承方式中指定的权限。例如,当继承方式为protected时,那么基类成员在派生类中的访问权限最高也为protected,高于protected会降级为protected,但低…...
Git 指令
Git 安装 操作 命令行 简介: Git 是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。 Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。 Git 与常用的版本控制工具 CVS, Subversion …...
JAVA中的多态参数
1.方法定义的参数类型为父类类型,实参类型允许为子类类型 public class Ploy_parameter {public static void main(String[] args) {Manage jack new Manage("jack",12000,3000);Staff tom new Staff("tom",10000);Ploy_parameter ploy_para…...
Ubuntu Linux 下安装和卸载cmake 3.28.2版本
一、安装cmake 1.首先,先从cmake官网下载cmake-3.28.2-linux-x86_64.tar.gz 2.用FinalShell 等文件上传工具,将这个压缩包上传到 虚拟机的某个路径去(自选) 3. cd /usr/local/bin/,然后创建cmake文件夹,…...
【C++】类和对象3:默认成员函数之析构函数
前言 这篇文章我们来学习默认成员函数中的析构函数 概念 析构函数:与构造函数功能相反,析构函数不是完成对对象本身的销毁,局部对象销毁工作是由编译器完成的。而对象在销毁时会自动调用析构函数,完成对象中资源的清理工作。 …...
2024美赛C题完整解题教程及代码 网球运动的势头
2024 MCM Problem C: Momentum in Tennis (网球运动的势头) 注:在网球运动中,"势头"通常指的是比赛中因一系列事件(如连续得分)而形成的动力或趋势,这可能对比赛结果产生重要影响。球…...
vscode里如何用git
打开vs终端执行如下: 1 初始化 Git 仓库(如果尚未初始化) git init 2 添加文件到 Git 仓库 git add . 3 使用 git commit 命令来提交你的更改。确保在提交时加上一个有用的消息。 git commit -m "备注信息" 4 …...
DeepSeek 赋能智慧能源:微电网优化调度的智能革新路径
目录 一、智慧能源微电网优化调度概述1.1 智慧能源微电网概念1.2 优化调度的重要性1.3 目前面临的挑战 二、DeepSeek 技术探秘2.1 DeepSeek 技术原理2.2 DeepSeek 独特优势2.3 DeepSeek 在 AI 领域地位 三、DeepSeek 在微电网优化调度中的应用剖析3.1 数据处理与分析3.2 预测与…...
VB.net复制Ntag213卡写入UID
本示例使用的发卡器:https://item.taobao.com/item.htm?ftt&id615391857885 一、读取旧Ntag卡的UID和数据 Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click轻松读卡技术支持:网站:Dim i, j As IntegerDim cardidhex, …...
电脑插入多块移动硬盘后经常出现卡顿和蓝屏
当电脑在插入多块移动硬盘后频繁出现卡顿和蓝屏问题时,可能涉及硬件资源冲突、驱动兼容性、供电不足或系统设置等多方面原因。以下是逐步排查和解决方案: 1. 检查电源供电问题 问题原因:多块移动硬盘同时运行可能导致USB接口供电不足&#x…...
Qwen3-Embedding-0.6B深度解析:多语言语义检索的轻量级利器
第一章 引言:语义表示的新时代挑战与Qwen3的破局之路 1.1 文本嵌入的核心价值与技术演进 在人工智能领域,文本嵌入技术如同连接自然语言与机器理解的“神经突触”——它将人类语言转化为计算机可计算的语义向量,支撑着搜索引擎、推荐系统、…...
华为OD机试-食堂供餐-二分法
import java.util.Arrays; import java.util.Scanner;public class DemoTest3 {public static void main(String[] args) {Scanner in new Scanner(System.in);// 注意 hasNext 和 hasNextLine 的区别while (in.hasNextLine()) { // 注意 while 处理多个 caseint a in.nextIn…...
【git】把本地更改提交远程新分支feature_g
创建并切换新分支 git checkout -b feature_g 添加并提交更改 git add . git commit -m “实现图片上传功能” 推送到远程 git push -u origin feature_g...
docker 部署发现spring.profiles.active 问题
报错: org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property spring.profiles.active imported from location class path resource [application-test.yml] is invalid in a profile specific resource [origin: class path re…...
安宝特方案丨船舶智造的“AR+AI+作业标准化管理解决方案”(装配)
船舶制造装配管理现状:装配工作依赖人工经验,装配工人凭借长期实践积累的操作技巧完成零部件组装。企业通常制定了装配作业指导书,但在实际执行中,工人对指导书的理解和遵循程度参差不齐。 船舶装配过程中的挑战与需求 挑战 (1…...
Yolov8 目标检测蒸馏学习记录
yolov8系列模型蒸馏基本流程,代码下载:这里本人提交了一个demo:djdll/Yolov8_Distillation: Yolov8轻量化_蒸馏代码实现 在轻量化模型设计中,**知识蒸馏(Knowledge Distillation)**被广泛应用,作为提升模型…...
