Linux find常用命令
今天研究一下find的一些常用的命令。
find格式:find filepath [-option] [-print|-exec|-ok...]
其中常用的option主要有
-type d|f|s|b|c|p
-perm
-user
-group
-mtime
-depth
-newer
-name
-regex
!
下面我们通过例子来研究,事先准备了这样的一个目录结构
[root@test tmp]# find ./
./
./root2
./root2/sub1
./root2/sub1/sub2
./root
./root/sub1
./root/sub1/sub2
./root/sub1/sub2/sub3
./test.txt
他们的仔细信息如下:
[root@test tmp]# ll -R
.:
total
drwxr-xr-x root root Jul : root
drwxr-xr-x www root Jul : root2
-rw-r--r-- root root Jul : test.txt ./root:
total
drwxrwxrwx root root Jul : sub1 ./root/sub1:
total
drwxr-xr-x root root Jul : sub2 ./root/sub1/sub2:
total
drwxr-xr-x root root Jul : sub3 ./root/sub1/sub2/sub3:
total ./root2:
total
drwxr-xr-x root root Jul : sub1 ./root2/sub1:
total
drwxr-xr-x root root Jul : sub2 ./root2/sub1/sub2:
total
-type: type后面可以接上面说的六种参数,表示查找的类型,其中f d是最常用的,分别表示查找文件和目录。
[root@test tmp]# find ./ -type d
./
./root2
./root2/sub1
./root2/sub1/sub2
./root
./root/sub1
./root/sub1/sub2
./root/sub1/sub2/sub3
[root@test tmp]# find ./ -type f
./test.txt
-perm 权限: perm用于查找某个权限的文件。
[root@test tmp]# find ./ -perm
./root/sub1
[root@test tmp]# find ./ -perm
./
./root2
./root2/sub1
./root2/sub1/sub2
./root
./root/sub1/sub2
./root/sub1/sub2/sub3
-user 用户名: 用于查找特定所有者的文件。
[root@test tmp]# find ./ -user www
./root2
[root@test tmp]# find ./ -user root
./root2/sub1
./root2/sub1/sub2
./root
./root/sub1
./root/sub1/sub2
./root/sub1/sub2/sub3
./test.txt
-group 用户名: 用于查找特定用户组的文件。用法与-user一样。
-mtime -n|+n:-n表示查找n天之内修改过的文件,+n表示查找n天之前修改过的文件。时间轴都以现在的时候为起点。
[root@test tmp]# find ./ -mtime -
.
./root2
./root2/sub1
./root2/sub1/sub2
./root
./root/sub1
./root/sub1/sub2
./root/sub1/sub2/sub3
./test.txt
[root@test tmp]# find ./ -mtime +1
[root@test tmp]#
-newer filepath: 查找比filepath更新的文件
[root@test tmp]# find ./ -newer root2/sub1
./
./test.txt
-depth: 先查找处理目录里的内容,然后再处理目录。
上面的解释可能不太明了,我们来比较下面两个例子:
[root@test tmp]# find root/
root/
root/sub1
root/sub1/sub2
root/sub1/sub2/sub3 [root@test tmp]# find root/ -depth
root/sub1/sub2/sub3
root/sub1/sub2
root/sub1
root/
现在是否明白了,不加-depth时,find先处理当前目录,然后接着处理目录下面的文件/目录。反之,先处理目录下面的内容,再反过来处理目录。
我们再来看上面的例子,加-depth以后,先读取root里的sub1,因为它是目录,于是又先处理了sub1里的sub2,一步一步往下推。等到了sub3以后,因为里面已经没有东西了,所以处理sub3,然后回朔处理sub2,一步一步向上。
-name 文件名: 根据文件名查找。可以使用?代替一个字符,*代替一字串,[]选择一个列表里的字符。
[root@test tmp]# find ./ -name "root?"
./root2
[root@test tmp]# find ./ -name "root*"
./root2
./root
[root@test tmp]# find ./ -name "[rs]*"
./root2
./root2/sub1
./root2/sub1/sub2
./root
./root/sub1
./root/sub1/sub2
./root/sub1/sub2/sub3
[root@test tmp]# find ./ -name "[rst]*"
./root2
./root2/sub1
./root2/sub1/sub2
./root
./root/sub1
./root/sub1/sub2
./root/sub1/sub2/sub3
./test.txt
-regex partern: 这就是牛叉的工具,可以使用正则来匹配文件名。需要注意的是,它要求匹配的是完全的路径。
[root@test tmp]# find ./ -regex 'root'
[root@test tmp]# find ./ -regex './root'
./root
[root@test tmp]# find /tmp/ -regex '/tmp/root'
/tmp/root
[root@test tmp]# find ./ -regex './root.*'
./root2
./root2/sub1
./root2/sub1/sub2
./root
./root/sub1
./root/sub1/sub2
./root/sub1/sub2/sub3
regex使用的正则规则是受-regextype影响的。具体man find看一下吧。
!: 否定前缀。怎么用呢?直接看例子吧
[root@test tmp]# find ./ ! -name sub*
./
./root2
./root
./test.txt [root@test tmp]# find ./ ! -name sub* ! -type d
./test.txt
Linux find常用命令的更多相关文章
- Linux GDB常用命令一栏
Linux GDB 常用命令如下: 1.启动和退出gdb (1)启动:gdb ***:显示一段版权说明: (*** 表示可执行程序名) (2)退出:quit.有的时候输入quit后会出现相关提示:类似 ...
- Linux 下常用命令
linux 下常用命令: 1.删除文件命令为 rm 2.创建目录的命令是:mkdir 3.删除目录的命令是rmdir(空目录) 4.切换到root帐号:su 5.查看所有进程:ps -aux 6.杀死 ...
- linux 服务器常用命令整理
linux 服务器常用命令整理 目录 网络分析 - tcpdump \ telnet \ (netstat \ ss \ lsof) \ nload 网络传输 - scp \ rsync \ (rz ...
- 计算机硬件基本知识及Linux的常用命令
------------------1. 计算机硬件基本知识------------------ CPU - 寄存器 - L1/L2/L3 - 内存 - 硬盘 - 互联网下载/其他存储介质传输 寄存器 ...
- 一、Linux概述 二、Linux的安装 三、Linux的常用命令(重点)
一.Linux概述###<1>操作系统 OS,管理和控制 计算机的 硬件和软件资源的 计算机程序. 最基本的系统软件. 是用户和计算机交互的桥梁,是硬件和软件交互的桥梁. 操作系统:she ...
- Linux帮助——常用命令
Linux帮助——常用命令 摘要:本文主要学习了Linux系统中常用的一些命令. uname命令 uname命令可以显示电脑以及操作系统的相关信息. 基本语法 uname [选项] 选项说明 -a:显 ...
- Linux虚拟机常用命令
参考原文链接:(https://blog.csdn.net/fanyun_01/article/details/51083585) 一.Linux虚拟机常用命令 # virsh list //查看已打 ...
- [转帖]Linux systemd 常用命令
Linux systemd 常用命令 https://www.cnblogs.com/tsdxdx/p/7288490.html systemctl hostnamectl timedatectl l ...
- Linux系统管理常用命令
Linux系统管理常用命令 分类: Linux2011-01-10 18:26 1538人阅读 评论(0) 收藏 举报 linuxcommandservicenginxuserunix 目录(?)[+ ...
- Linux + NodeJS 常用命令
Linux系统常用命令 1.su 由当前用户切换至root用户: 2. su username 切换至某一用户: 3.chmod u+w /etc/sudoers 为/etc/sudoers文件添加写 ...
随机推荐
- D. Winter Is Coming 贪心(好题)
http://codeforces.com/contest/747/problem/D 大概的思路就是找到所有两个负数夹着的线段,优先覆盖最小的长度.使得那时候不用换鞋,是最优的. 但是这里有个坑点, ...
- AJPFX总结在循环中break与continue的区别
相信刚学编程的人很容易被break,continue这两个关键词搞混淆了,两者都有跳出循环的意思,但是他们到底有什么区别呢?其实很简单,break是结束整个循环体,continue是结束当前这一单次循 ...
- opencv4android移植到系统app
最近在尝试使用opencv4android实现投影仪的自动对焦功能,在AndroidStudio后需要将功能移到系统工程编译成系统app,仅以此文记录下移植过程中遇到的问题. 首先去opencv官网下 ...
- 老潘 - ListView分析 - 学以致用篇(一)
ListView分析学以致用篇(1) 在我们查看别人的博客的时候,一个人是一个风格的.先说下我的风格,我喜欢思想类比,然后介绍知识,不太喜欢填鸭式的灌输.如果只是想单纯的从我的博客中直接看到代码,我个 ...
- 洛谷 P1615 西游记公司
题目背景 一道极其无厘头的题目 题目描述 事情是这样的:西游记中的孙沙猪(孙杀猪)三徒弟在西天取经之后开始进入厦门大学经贸系学习经济,在1个小时的学习后,他们用暴力手段毕业了.然后,他们创办了三个公司 ...
- PowerDesigner 操作手册
1.错误信息:Generation aborted due to errors detected during the verification of the model 解决方案: 把检查模型的选项 ...
- Flask框架 之数据库扩展Flask-SQLAlchemy
一.安装扩展 pip install flask-sqlalchemy pip install flask-mysqldb 二.SQLAlchemy 常用的SQLAlchemy字段类型 类型名 pyt ...
- AttributeError: 'dict' object has no attribute 'encode'
首先这是一个很简单的 运行时错误: 错误分析: AttributeError:属性错误,造成这种错误的原因可能有: 你尝试访问一个不存在的属性或方法.检查一下拼写!你可以使用内建函数 dir 来列出存 ...
- CAD设置超链接(网页版)
超链接(Hyperlink)可以看做是一个“热点”,它可以从当前Web页定义的位置跳转到其他位置. 设置对象动态提示事件回调函数. //设置对象动态提示事件回调函数 function DoInputP ...
- must have same number of columns as the referenced primary key
在使用Hibernate实现多对多的测试过程中遇到了这个问题 解决的方法: 将黄色字段的内容添加进去 <set name="customerSet" table=" ...