find排除一个或多个目录的方法

百度就是垃圾,搜索结果千篇一律,错抄错。google一下,总结find排除某个目录的方法:

How to exclude a directory in find . command
Use the -prune switch. For example, if you want to exclude the misc directory just add a -path ./misc -prune -o to your find command:

寻找当前目录,排除misc目录,文件类型txt:

find . -path ./misc -prune -o -name '*.txt' -print

Here is an example with multiple directories:

排除多个目录dir1,dir2,dir3的做法:

find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -print

Here we exclude dir1, dir2 and dir3, since in find expressions it is an action that acts on the criteria -path dir1 -o -path dir2 -o -path dir3 (if dir1 or dir2 or dir3), ANDed with type -d.

最好加上-o print,打印。

Further action is -o print, just print.

下面这种情况没碰到过

If -prune doesn’t work for you, this will:

如果-prune 不好用,试试下面的。

find -name "*.js" -not -path "./directory/*"

其他人的方法都没试过:

find / -name NameOfFile ! -path '*/Directory/*'
find . -name '*.js' -and -not -path directory
find . -type d -name proc -prune -o -name '*.js'
$ find ./ -type f -name "pattern" ! -path "excluded path" ! -path "excluded path"
$ find ./ -type f -name "*" ! -path "./.*" ! -path "./*/.*"
find . -type d \
-not \( -path */objects -prune \) \
-not \( -path */branches -prune \) \
-not \( -path */refs -prune \) \
-not \( -path */logs -prune \) \
-not \( -path */.git -prune \) \
-not \( -path */info -prune \) \
-not \( -path */hooks -prune \)

[转帖]find排除一个或多个目录的方法的更多相关文章

  1. linux下cp目录时排除一个或者多个目录的方法

    说明:/home目录里面有data目录,data目录里面有a.b.c.d.e五个目录,现在要把data目录里面除过e目录之外的所有目录拷贝到/bak目录中 系统运维 www.osyunwei.com ...

  2. Linux 下复制(cp)目录时排除一个或者多个目录的方法

    cp 貌似没有排除目录的功能,可以使用 rsync 命令来实现了,如: [案例] /home/52php目录里面有data目录,data目录里面有 a.b.c.d.e 五个目录,现在要把data目录里 ...

  3. (转)linux下cp目录时排除一个或者多个目录的实现方法

    原文链接:http://www.jb51.net/LINUXjishu/88971.html 说明:/home目录里面有data目录,data目录里面有a.b.c.d.e五个目录,现在要把data目录 ...

  4. Vertica增加一个数据存储的目录

    Vertica增加一个数据存储的目录 操作语法为: ADD_LOCATION ( 'path' , [ 'node' , 'usage', 'location_label' ] ) 各节点添加目录,并 ...

  5. 一个防止误删MSSQL数据库的方法

    一个防止误删MSSQL数据库的方法 环境:Windows2008 R2 .SQL 2012 今天发现一个有趣的现象,之前数据库服务器的其中几个数据库做过镜像,不过现在已经删除了,今天又要在那台服务器上 ...

  6. as关键词还有另外一个用途,那就是修改 方法 的访问控制

    PHP是单继承的语言,在PHP 5.4 Traits出现之前,PHP的类无法同时从两个基类继承属性或方法.php的Traits和Go语言的组合功能类似,通过在类中使用use关键字声明要组合的Trait ...

  7. 重新想象 Windows 8 Store Apps (42) - 多线程之线程池: 延迟执行, 周期执行, 在线程池中找一个线程去执行指定的方法

    [源码下载] 重新想象 Windows 8 Store Apps (42) - 多线程之线程池: 延迟执行, 周期执行, 在线程池中找一个线程去执行指定的方法 作者:webabcd 介绍重新想象 Wi ...

  8. 获取一个 app 的 URL Scheme 的方法:

    获取一个 app 的 URL Scheme 的方法: 上这个网站 URL Schemes 查一下相应的 app 的 URL Scheme 是否有被收录 第一种方法没找到的话,把相应的 app 的 ip ...

  9. 自己写一个与startWith类似的判断方法

    package com.hanqi.lianxi; import java.util.Scanner; public class startWith {        //自己顶一个与startWit ...

  10. YII框架开发一个项目的通用目录结构

    YII框架开发一个项目的通用目录结构: 3 testdrive/ 4 index.php Web 应用入口脚本文件 5 assets/ 包含公开的资源文件 6 css/ 包含 CSS 文件 7 ima ...

随机推荐

  1. k8s源码Client-go中Reflector解析

    摘要:通过本文,可以了解Reflector通过ListWatcher从Kubernetes API中获取对象的流程,以及存储到store中,后续会对DeltaFIFO进行源码研读,通过结合inform ...

  2. pod内部网络实现

    k8s主题系列: 一.k8s网络之设计与实现 二.k8s网络之pod内部网络 三.k8s网络之Flannel网络 四.k8s网络之Calico网络 pod特性 Pod 是 K8S 的最小工作单元.每个 ...

  3. WebSoket 的广泛应用

    目前大多数网站都在使用的传统 HTTP 协议,即由 Web 服务器通过 HTTP 接收并响应来自客户端的消息,整个发起请求与响应的过程类似我们点外卖,由以下 2 部分构成: 下订单(发起请求):用户( ...

  4. EXECL函数

    1 COUNTIF 对比两列数据,有相同的即计为1 找一列空白列,输入=COUNTIF(范围,条件),按回车,然后再点击表格右下角的"+" 就可以拉动持续执行这个函数 2 CONC ...

  5. Go--命名规则

    在Go语言中,项目名和文件名的命名规则有一些建议和惯例.以下是一些常见的规则和最佳实践: 项目名: 项目名应该简短.有意义,并能够清晰地表达项目的目的或功能. 项目名通常使用小写字母,使用连字符或下划 ...

  6. protobuf安装、编译和使用

    protobuf使用简单示例 一.安装 首先下载protobuf的安装包,我这里使用的是protobuf-cpp-3.21.5.tar.gz 解压安装包 tar -xzf protobuf-cpp-3 ...

  7. 获取标准报表CJI3的ALV数据

    1.CJI3 运行标准程序CJI3,获取对象和业务货币值,在其他程序中展示 2.代码展示 CJI3对应程序名rkpep003,最终展示的ALV结构可以再程序中找到. 因为本实例只获取其中两个字段的值, ...

  8. Python使用pandas库读取csv文件,并分组统计的一个例子

    代码: # coding=gbk # 从HostWrites.csv读取数据并分组统计 import pandas import datetime print "\r\n从 HostWrit ...

  9. 一、mysql5.7 rpm 安装(单机)

    一.下载需要的rpm包mysql-community-client-5.7.26-1.el6.x86_64.rpmmysql-community-common-5.7.26-1.el6.x86_64. ...

  10. vscode prettier保存代码时自动格式化

    https://blog.csdn.net/qq_37815596/article/details/109225879