每天一个Linux命令(19)find命令_初识
Linux下find命令在目录结构中搜索文件,并执行指定的操作。
(1)用法:
用法: find pathname -option [-print | -exec | -ok]
find 路径名 选项参数 [-print | -exec | -ok]
(2)功能:
功能:用于在文件树种查找文件,并作出相应的处理。
(3)命令参数:
1) pathname: find命令所查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。
2) -print: find命令将匹配的文件输出到标准输出。
3) -exec: find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为'command' { } \;注意{ }和\;之间的空格。
4) -ok: 和-exec的作用相同,只不过以一种更为安全的模式来执行该参数所给出的shell命令,在执行每一个命令之前,都会给出提示,让用户来确定是否执行。
(4)选项参数:
1) -name 按照文件名查找文件。
2) -perm 按照文件权限来查找文件。
3) -prune 使用这一选项可以使find命令不在当前指定的目录中查找,如果同时使用-depth 选项,那么-prune将被find命令忽略。
4) -user 按照文件属主来查找文件。
5) -group 按照文件所属的组来查找文件。
6) -mtime -n +n 按照文件的更改时间来查找文件, - n表示文件更改时间距现在n天以内,+ n表示文件更改时间距现在n天以前。find命令还有-atime和-ctime 选项,但它们都和-m time选项。
7) -nogroup 查找无有效所属组的文件,即该文件所属的组在/etc/groups中不存在。
8) -nouser 查找无有效属主的文件,即该文件的属主在/etc/passwd中不存在。
9) -newer file1 ! file2 查找更改时间比文件file1新但比文件file2旧的文件。
10) -empty 查找长度为0的文件或文件夹
11) -type 查找某一类型的文件,诸如:
b -块设备文件。
d - 目录。
c - 字符设备文件。
p - 管道文件。
l - 符号链接文件。
f - 普通文件。
12) -size n: [c] 查找文件长度为n块的文件,带有c时表示文件长度以字节计。
13) -depth: 在查找文件时,首先查找当前目录中的文件,然后再在其子目录中查找。
14) -fstype: 查找位于某一类型文件系统中的文件,这些文件系统类型通常可以在配置文件/etc/fstab中找到,该配置文件中包含了本系统中有关文件系统的信息。
15) -mount: 在查找文件时不跨越文件系统mount点。
16) -follow: 如果find命令遇到符号链接文件,就跟踪至链接所指向的文件。
17) -cpio: 对匹配的文件使用cpio命令,将这些文件备份到磁带设备中。
18) -regex<范本样式>: 指定字符串作为寻找文件或目录的范本样式
另外,下面三个的区别:
-amin n 查找系统中最后N分钟访问的文件
-atime n 查找系统中最后n*24小时访问的文件
-cmin n 查找系统中最后N分钟被改变文件状态的文件
-ctime n 查找系统中最后n*24小时被改变文件状态的文件
-mmin n 查找系统中最后N分钟被改变文件数据的文件
-mtime n 查找系统中最后n*24小时被改变文件数据的文件
(5)实例:
1)[root@localhost findDir]# find . 列出当前目录及子目录下所有文件和文件夹
[root@localhost Documents]# touch ./findDir/t1.txt //在当前目录的子目录findDir目录下创建t1.txt文本文件
[root@localhost Documents]# cd findDir
[root@localhost findDir]# ll
总用量
-rw-r--r--. root root 5月 : t1.txt
[root@localhost findDir]# find .
.
./t1.txt
[root@localhost findDir]# cd ../
[root@localhost Documents]# find .
.
./less1
./less2
./head_text
./tail_text
./tempory
./newlocate
./uText
./findDir
./findDir/t1.txt
[root@localhost Documents]#
用ls命令列出当前目录及子目录下所有文件和文件夹:
[root@localhost Documents]# ls -Rl
.:
总用量
drwxr-xr-x. root root 5月 : findDir
-rw-r--r--. root root 5月 : head_text
-rw-r--r--. root root 5月 : less1
-rw-r--r--. root root 5月 : less2
-rw-r--r--. root root 5月 : newlocate
-rw-r--r--. root root 5月 : tail_text
-rw-r--r--. root root 5月 : tempory
-rw-r--r--. root root 5月 : uText ./findDir:
总用量
-rw-r--r--. root root 5月 : t1.txt
2)[root@localhost /]# find /home/sunjimeng/Documents -name "*.txt" 在特定目录下找到以.txt结尾的文件
[root@localhost /]# find /home/sunjimeng/Documents -name "*.txt"
/home/sunjimeng/Documents/findDir/t1.txt
3)[root@localhost /]# find /home/sunjimeng/Documents -iname "T*" 在特定目录下找到以T开头的文件或文件夹,但忽略大小写(-i操作)
[root@localhost /]# find /home/sunjimeng/Documents -name "T*" //不忽略
/home/sunjimeng/Documents/findDir/T1.txt
/home/sunjimeng/Documents/findDir/T2.txt
[root@localhost /]# find /home/sunjimeng/Documents -iname "T*" //忽略大小写
/home/sunjimeng/Documents/tail_text
/home/sunjimeng/Documents/tempory
/home/sunjimeng/Documents/findDir/t1.txt
/home/sunjimeng/Documents/findDir/T1.txt
/home/sunjimeng/Documents/findDir/T2.txt
4)[root@localhost /]# find /home/sunjimeng/Documents \( -name "*.txt" -o -name "*.pdf" \) 用两个条件来查询文件
[root@localhost /]# touch /home/sunjimeng/Documents/findDir/{p1.pdf,p2.pdf}
[root@localhost /]# find /home/sunjimeng/Documents \( -name "*.txt" -o -name "*.pdf" \)
/home/sunjimeng/Documents/findDir/t1.txt
/home/sunjimeng/Documents/findDir/T1.txt
/home/sunjimeng/Documents/findDir/T2.txt
/home/sunjimeng/Documents/findDir/p1.pdf
/home/sunjimeng/Documents/findDir/p2.pdf
[root@localhost /]# cd /home/sunjimeng/Documents/findDir
[root@localhost findDir]# find . -name "*.txt" -o -name "*.pdf"
./t1.txt
./T1.txt
./T2.txt
./p1.pdf
./p2.pdf
5)[root@localhost /]# find /home/sunjimeng/Documents ! -name "*.txt" 找寻目录下不是以.txt结尾的文件或目录
[root@localhost /]# find /home/sunjimeng/Documents ! -name "*.txt"
/home/sunjimeng/Documents
/home/sunjimeng/Documents/less1
/home/sunjimeng/Documents/less2
/home/sunjimeng/Documents/head_text
/home/sunjimeng/Documents/tail_text
/home/sunjimeng/Documents/tempory
/home/sunjimeng/Documents/newlocate
/home/sunjimeng/Documents/uText
/home/sunjimeng/Documents/findDir
/home/sunjimeng/Documents/findDir/p1.pdf
/home/sunjimeng/Documents/findDir/p2.pdf
6)[root@localhost sunjimeng]# find /home/ -path "*cume*" 在指定目录下的后代目录中进行路径匹配,匹配完成后列出匹配目录下的所有文件及文件夹及其子目录及文件。
[root@localhost sunjimeng]# find /home/ -path "*cume*" //等价于find /home -path "*cume*"
/home/sunjimeng/Documents
/home/sunjimeng/Documents/less1
/home/sunjimeng/Documents/less2
/home/sunjimeng/Documents/head_text
/home/sunjimeng/Documents/tail_text
/home/sunjimeng/Documents/tempory
/home/sunjimeng/Documents/newlocate
/home/sunjimeng/Documents/uText
/home/sunjimeng/Documents/findDir
/home/sunjimeng/Documents/findDir/t1.txt
/home/sunjimeng/Documents/findDir/T1.txt
/home/sunjimeng/Documents/findDir/T2.txt
/home/sunjimeng/Documents/findDir/p1.pdf
/home/sunjimeng/Documents/findDir/p2.pdf
/home/sunjimeng/Document
/home/sunjimeng/Document/newDir
/home/sunjimeng/Document/newDir/text1
/home/sunjimeng/Document/newDir/text2
/home/sunjimeng/Document/text1
/home/sunjimeng/Document/text1/newDir
/home/sunjimeng/Document/text1/newDir/text1
/home/sunjimeng/Document/text1/newDir/text2
/home/sunjimeng/Document/text2
/home/sunjimeng/Document/text2/newDir
/home/sunjimeng/Document/text2/newDir/text1
/home/sunjimeng/Document/text2/newDir/text2
/home/sunjimeng/Document/text3
/home/sunjimeng/Document/text3/text1
/home/sunjimeng/Document/text3/text2
/home/sunjimeng/Document/text4
/home/sunjimeng/Document/text4/text1
/home/sunjimeng/Document/text4/text2
/home/sunjimeng/Document/mytext
/home/sunjimeng/Document/mytext.txt
7)[root@localhost /]# find /home/sunjimeng -regex ".*\(txt\|pdf\)$" 进行字符串匹配
[root@localhost /]# find /home/sunjimeng -regex ".*\(\.txt\|\.pdf\)$" //原始
[root@localhost /]# find /home/sunjimeng -regex ".*\(.txt\|.pdf\)$" //去掉两个斜杠
[root@localhost /]# find /home/sunjimeng -regex ".*\(txt\|pdf\)$" //把点去了
/home/sunjimeng/.cache/tracker/db-version.txt
/home/sunjimeng/.cache/tracker/db-locale.txt
/home/sunjimeng/.cache/tracker/miner-applications-locale.txt
/home/sunjimeng/.cache/tracker/last-crawl.txt
/home/sunjimeng/.cache/tracker/first-index.txt
/home/sunjimeng/.local/share/Trash/files/test1.txt
/home/sunjimeng/.local/share/Trash/files/test2.txt
/home/sunjimeng/.local/share/Trash/files/test3.txt
/home/sunjimeng/Documents/findDir/t1.txt
/home/sunjimeng/Documents/findDir/T1.txt
/home/sunjimeng/Documents/findDir/T2.txt
/home/sunjimeng/Documents/findDir/p1.pdf
/home/sunjimeng/Documents/findDir/p2.pdf
/home/sunjimeng/Document/mytext.txt
8)[root@localhost /]# find /home/sunjimeng/Documents -type d | p | f | c | l | b 查找特定类型的文件
[root@localhost /]# find /home/sunjimeng/Documents -type d
/home/sunjimeng/Documents
/home/sunjimeng/Documents/findDir
[root@localhost /]# find /home/sunjimeng/Documents -type p
[root@localhost /]# find /home/sunjimeng/Documents -type f
/home/sunjimeng/Documents/less1
/home/sunjimeng/Documents/less2
/home/sunjimeng/Documents/head_text
/home/sunjimeng/Documents/tail_text
/home/sunjimeng/Documents/tempory
/home/sunjimeng/Documents/newlocate
/home/sunjimeng/Documents/uText
/home/sunjimeng/Documents/findDir/t1.txt
/home/sunjimeng/Documents/findDir/T1.txt
/home/sunjimeng/Documents/findDir/T2.txt
/home/sunjimeng/Documents/findDir/p1.pdf
/home/sunjimeng/Documents/findDir/p2.pdf
9)[root@localhost /]# find /home -maxdepth 3 -type f 找指定目录下的普通文件,文件目录深度不超过3
[root@localhost /]# find /home -maxdepth -type f
/home/sunjimeng/.bash_logout
/home/sunjimeng/.bash_profile
/home/sunjimeng/.bashrc
/home/sunjimeng/.config/user-dirs.dirs
/home/sunjimeng/.config/user-dirs.locale
/home/sunjimeng/.config/gnome-initial-setup-done
/home/sunjimeng/.cache/event-sound-cache.tdb.localhost.localdomain.x86_64-redhat-linux-gnu
/home/sunjimeng/.ICEauthority
/home/sunjimeng/.esd_auth
/home/sunjimeng/.bash_history
/home/sunjimeng/Documents/less1
/home/sunjimeng/Documents/less2
/home/sunjimeng/Documents/head_text
/home/sunjimeng/Documents/tail_text
/home/sunjimeng/Documents/tempory
/home/sunjimeng/Documents/newlocate
/home/sunjimeng/Documents/uText
/home/sunjimeng/Document/mytext
/home/sunjimeng/Document/mytext.txt
10)[root@localhost /]# find /home/sunjimeng -mindepth 5 -type d 找指定目录下的普通文件,文件目录深度不低于5
[root@localhost /]# find /home/sunjimeng -mindepth -type d
/home/sunjimeng/.local/share/evolution/addressbook/trash
/home/sunjimeng/.local/share/evolution/addressbook/system
/home/sunjimeng/.local/share/evolution/addressbook/system/photos
/home/sunjimeng/.local/share/evolution/calendar/trash
/home/sunjimeng/.local/share/evolution/calendar/system
/home/sunjimeng/.local/share/evolution/mail/trash
/home/sunjimeng/.local/share/evolution/memos/trash
/home/sunjimeng/.local/share/evolution/tasks/trash
/home/sunjimeng/.local/share/Trash/files/未命名文件夹
11)[root@localhost /]# find /home/sunjimeng/Documents -atime -2 查找指定时间内修改过的文件
[root@localhost /]# find /home/sunjimeng/Documents -atime -2 //两个以内
/home/sunjimeng/Documents
/home/sunjimeng/Documents/newlocate
/home/sunjimeng/Documents/uText
/home/sunjimeng/Documents/findDir
/home/sunjimeng/Documents/findDir/t1.txt
/home/sunjimeng/Documents/findDir/T1.txt
/home/sunjimeng/Documents/findDir/T2.txt
/home/sunjimeng/Documents/findDir/p1.pdf
/home/sunjimeng/Documents/findDir/p2.pdf
[root@localhost /]# find /home/sunjimeng/Documents -atime -1 //一天以内
/home/sunjimeng/Documents
/home/sunjimeng/Documents/findDir
/home/sunjimeng/Documents/findDir/t1.txt
/home/sunjimeng/Documents/findDir/T1.txt
/home/sunjimeng/Documents/findDir/T2.txt
/home/sunjimeng/Documents/findDir/p1.pdf
/home/sunjimeng/Documents/findDir/p2.pdf
12)[root@localhost /]# find . -perm 777 查找权限为777的文件及文件夹
[root@localhost /]# find . -perm
[root@localhost /]# find /usr/libexec/gcc -perm
/usr/libexec/gcc/x86_64-redhat-linux/4.8./liblto_plugin.so
/usr/libexec/gcc/x86_64-redhat-linux/4.8./liblto_plugin.so.
/usr/libexec/gcc/x86_64-redhat-linux/4.8.
(6)其他:
权限:
读取权限 r = 4
写入权限 w = 2
执行权限 x = 1
775这三个数字代表拥有者,组用户,其他用户的权限。
例如: 7 拥有者有 读取,写入,执行权限
7 组用户有 读取,写入,执行权限
5 其他用户有 读取,执行权限(4+1 = 5)
777 与 775的区别是:其他用户有写入权限,而775的没有。
linux下设置777权限和用户权限
设置www目录的所有文件可写777sudo chmod 777 -R www (这里-R是继承)
设置www目录下的所有文件权限为user所有
sudo chown -hR user www
exit
linux下账户的权限是:drwx------ 表示是那些权限?
首先d是代表这个是一个目录文件,rwx是属主权限rw代表可读写x代表可执行,后面三个---是属主同组的权限,如果是---代表没有权限,最后三个是除文件属主组以外所有人的权限,---也是没有权限,所以这个目录只有属主有权限进入,其他人连读的权限也没有,更不用说写入和执行。
每天一个Linux命令(19)find命令_初识的更多相关文章
- Linux环境及基础命令(一)
Linux环境及基础命令 一.认识Linux系统 略 二.配置Linux系统远程登录 2.1虚拟机系统配置 2.11虚拟机配置 统一NAT模式 虚拟机连不上 确定VMnet8网卡的IP地址(每台虚拟机 ...
- 每天一个 Linux 命令(19):find 命令概览
Linux下find命令在目录结构中搜索文件,并执行指定的操作.Linux下find命令提供了相当多的查找条件,功能很强大.由于find具有强大的功能,所以它的选项也很多,其中大部分选项都值得我们花时 ...
- 每天一个linux命令(19):find 命令概览
Linux下find命令在目录结构中搜索文件,并执行指定的操作.Linux下find命令提供了相当多的查找条件,功能很强大.由于find具有强大的功能,所以它的选项也很多,其中大部分选项都值得我们花时 ...
- 每天一个linux命令(19):Linux 目录结构
对于每一个Linux学习者来说,了解Linux文件系统的目录结构,是学好Linux的至关重要的一步.,深入了解linux文件目录结构的标准和每个目录的详细功能,对于我们用好linux系统只管重要,下面 ...
- 每天一个Linux命令(19)--find命令
linux 下 find 命令在目录结构中搜索文件,并执行指定的操作.Linux 下 find 命令提供了相当多的查找条件,功能很强大.由于 find 具有强大的功能,所以它的选项也很多,其中大部分选 ...
- 【转】每天一个linux命令(19):find 命令概览
原文网址:http://www.cnblogs.com/peida/archive/2012/11/13/2767374.html Linux下find命令在目录结构中搜索文件,并执行指定的操作.Li ...
- 每天一个Linux命令:locate(19)
locate locate命令 让使用者可以很快速的搜寻档案系统内是否有指定的档案.其方法是先建立一个包括系统内所有档案名称及路径的数据库,之后当寻找时就只需查询这个数据库,而不必实际深入档案系统之中 ...
- 【每天一个Linux命令】19. 创建文件夹目录命令mkdir
命令用途 mkdir 命令用来创建指定的名称的目录 使用说明 1. 创建目录的用户在当前目录中具有写权限 2. 指定的目录名不能是当前目录中已有的目录. 命令实例 0. 帮助文件 bixiaopen ...
- 每天一个 Linux 命令(21):find命令之xargs
在使用 find命令的-exec选项处理匹配到的文件时, find命令将所有匹配到的文件一起传递给exec执行.但有些系统对能够传递给exec的命令长度有限制,这样在find命令运行几分钟之后,就会出 ...
随机推荐
- 【BIEE】BI Publisher下拉菜单设置
在使用BIEE的过程中,通常会有需要根据下拉菜单所选内容进行数据展示,如下图所示: 设置参数 进入数据模型编辑界面→参数 新增参数,P_DATADATE为示例参数 参数赋值 同时点击"值列表 ...
- mongo 增
mongodb存储的是文档,文档是json格式的对象,我们的增删改查,都要传输json对象 json是一个对象,js里有数组这个概念,只需要把多个对象放到一个数组里,即可 use test //首先选 ...
- 使用lua扩展应用程序
全局变量的操作 void lua_getglobal(lua_State * L ,const char * name) 此函数从lua中取出一个名为name的全局变量并将其压入栈中. 如当lua文件 ...
- javascript继承—prototype最优两种继承(空函数和循环拷贝)
一.利用空函数实现继承 参考了文章javascript继承-prototype属性介绍(2) 中叶小钗的评论,对这篇文章中的方案二利用一个空函数进行修改,可以解决创建子类对象时,父类实例化的过程中特权 ...
- 1 android 人脸识别
1 https://www.google.com.hk/search?newwindow=1&safe=strict&q=android+%E5%9B%BE%E7%89%87%E4%B ...
- tensorflow-gpu 1.13 提示找不到 libcublas.so.10.0 的问题
tensorflow-gpu 使用 1.13.1,cuda-10-0已安装好,但启动时依然报错 ImportError: libcublas.so.10.0: cannot open shared o ...
- JavaFX打包到Android上
让JavaFX执行到移动平台一直是社区努力完毕的事. 当然,眼下已经能够让JavaFX执行到Android和IOS平台了,以下我们来看看怎样打包自己的JavaFX项目到Android平台. 首先下 ...
- 在Vue中使用layer.js弹出层插件
layer.js(mobile)是一个小巧方便的弹出层插件,在之前的apicloud项目中被大量使用,但最近对apicloud的IDE.非常不友好的文档和极低的开发效率深感厌烦,决定弃用然后转向Vue ...
- HTML5 2D平台游戏开发#5攻击
目前为止,角色除了基本的移动外还什么都不能做,于是我打算先实现角色的攻击动画.角色的普通攻击一共可以分为三个阶段: 一段斩 二段斩 三段斩 移动攻击 跳跃攻击 触发方式为角色站立时按下J(攻击)键,角 ...
- Eclipse配置总结
按照公司要求,开发环境使用Eclipse Juno版本,需要安装maven插件和RTC插件. 经过一下午的尝试,总结经验教训: 1.eclipse安装maven的m2ec ...