当前位置: 首页 > news >正文

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 )写法方便移植。

相关文章:

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 这两个流行的库来实现深度强化学习算法&#xff…...

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 (网球运动的势头) 注:在网球运动中,"势头"通常指的是比赛中因一系列事件(如连续得分)而形成的动力或趋势,这可能对比赛结果产生重要影响。球…...

Linux链表操作全解析

Linux C语言链表深度解析与实战技巧 一、链表基础概念与内核链表优势1.1 为什么使用链表?1.2 Linux 内核链表与用户态链表的区别 二、内核链表结构与宏解析常用宏/函数 三、内核链表的优点四、用户态链表示例五、双向循环链表在内核中的实现优势5.1 插入效率5.2 安全…...

Prompt Tuning、P-Tuning、Prefix Tuning的区别

一、Prompt Tuning、P-Tuning、Prefix Tuning的区别 1. Prompt Tuning(提示调优) 核心思想:固定预训练模型参数,仅学习额外的连续提示向量(通常是嵌入层的一部分)。实现方式:在输入文本前添加可训练的连续向量(软提示),模型只更新这些提示参数。优势:参数量少(仅提…...

Debian系统简介

目录 Debian系统介绍 Debian版本介绍 Debian软件源介绍 软件包管理工具dpkg dpkg核心指令详解 安装软件包 卸载软件包 查询软件包状态 验证软件包完整性 手动处理依赖关系 dpkg vs apt Debian系统介绍 Debian 和 Ubuntu 都是基于 Debian内核 的 Linux 发行版&#xff…...

关于nvm与node.js

1 安装nvm 安装过程中手动修改 nvm的安装路径, 以及修改 通过nvm安装node后正在使用的node的存放目录【这句话可能难以理解,但接着往下看你就了然了】 2 修改nvm中settings.txt文件配置 nvm安装成功后,通常在该文件中会出现以下配置&…...

大语言模型如何处理长文本?常用文本分割技术详解

为什么需要文本分割? 引言:为什么需要文本分割?一、基础文本分割方法1. 按段落分割(Paragraph Splitting)2. 按句子分割(Sentence Splitting)二、高级文本分割策略3. 重叠分割(Sliding Window)4. 递归分割(Recursive Splitting)三、生产级工具推荐5. 使用LangChain的…...

基于Docker Compose部署Java微服务项目

一. 创建根项目 根项目&#xff08;父项目&#xff09;主要用于依赖管理 一些需要注意的点&#xff1a; 打包方式需要为 pom<modules>里需要注册子模块不要引入maven的打包插件&#xff0c;否则打包时会出问题 <?xml version"1.0" encoding"UTF-8…...

均衡后的SNRSINR

本文主要摘自参考文献中的前两篇&#xff0c;相关文献中经常会出现MIMO检测后的SINR不过一直没有找到相关数学推到过程&#xff0c;其中文献[1]中给出了相关原理在此仅做记录。 1. 系统模型 复信道模型 n t n_t nt​ 根发送天线&#xff0c; n r n_r nr​ 根接收天线的 MIMO 系…...

Java + Spring Boot + Mybatis 实现批量插入

在 Java 中使用 Spring Boot 和 MyBatis 实现批量插入可以通过以下步骤完成。这里提供两种常用方法&#xff1a;使用 MyBatis 的 <foreach> 标签和批处理模式&#xff08;ExecutorType.BATCH&#xff09;。 方法一&#xff1a;使用 XML 的 <foreach> 标签&#xff…...

音视频——I2S 协议详解

I2S 协议详解 I2S (Inter-IC Sound) 协议是一种串行总线协议&#xff0c;专门用于在数字音频设备之间传输数字音频数据。它由飞利浦&#xff08;Philips&#xff09;公司开发&#xff0c;以其简单、高效和广泛的兼容性而闻名。 1. 信号线 I2S 协议通常使用三根或四根信号线&a…...

在Mathematica中实现Newton-Raphson迭代的收敛时间算法(一般三次多项式)

考察一般的三次多项式&#xff0c;以r为参数&#xff1a; p[z_, r_] : z^3 (r - 1) z - r; roots[r_] : z /. Solve[p[z, r] 0, z]&#xff1b; 此多项式的根为&#xff1a; 尽管看起来这个多项式是特殊的&#xff0c;其实一般的三次多项式都是可以通过线性变换化为这个形式…...