linux命令之find基础

Find命令

目的:查找符合条件的文件/目录
1)在哪些目录中查找
2)查找的内容

格式:
find 目录名 选项 查找条件

举个实际的例子吧:
首先有一台电脑,主机和显示器/键盘必须的,鼠标有了更好,好开始…
1)find /home/book/linux/dira/ -name “test1.txt”
解析命令含义:
a) /home/book/linux/dira/ 指明了查找的路径
b) -name表明以名字来查找文件
c) “test1.txt”,就指明查找名为test1.txt的文件。

book@www.100ask.org:~/linux/dira$ find /home/book/linux/dira/ -name "test1.txt"
/home/book/linux/dira/test1.txt
/home/book/linux/dira/dirb/test1.txt

同理:
1>
find /home/book/linux/dira/ -name “*.txt”
查找指定目录下面所有以 “.txt”结尾的文件,其中星号是通配符。

book@www.100ask.org:~/linux/dira$ find /home/book/linux/dira/ -name "*.txt"
/home/book/linux/dira/test1.txt
/home/book/linux/dira/test2.txt
/home/book/linux/dira/dirb/test1.txt
/home/book/linux/dira/dirb/test2.txt

2> 查找目录
 find /home/book/linux/ -name "dira"
 查找指定目录下面是否存在dira这个目录,“dira”是目录名。
book@www.100ask.org:~/linux/dira$ find /home/book/linux/ -name "dira"
/home/book/linux/dira

注意:
1)如果没有指定查找目录,则为当前目录。
find . -name “.txt”
其中 “ . ”代表当前路径
find -name “
.txt”
和上面是同样的功能,如果指定目录的地方缺省,默认是当前目录。

book@www.100ask.org:~/linux/dira$ find . -name "*.txt"
./test1.txt
./test2.txt
./dirb/test1.txt
./dirb/test2.txt
book@www.100ask.org:~/linux/dira$ find -name "*.txt"
./test1.txt
./test2.txt
./dirb/test1.txt
./dirb/test2.txt

2)find还有一些高级的用法,如查找最近几天(或几个小时)之内(或之前)有变动的文件。
find /home -mtime -2
查找/home目录下两天内有变动的文件

book@www.100ask.org:~/linux/dira$ find /home/ -mtime -2
/home/book
/home/book/.cache/upstart
/home/book/.cache/upstart/unity7.log
/home/book/.cache/upstart/unity-panel-service.log
/home/book/.cache/upstart/gpg-agent.log
/home/book/.bash_history
/home/book/.Xauthority
/home/book/.xsession-errors
/home/book/python
/home/book/python/L9
/home/book/python/L9/aliens.py
/home/book/python/L9/favorite_languages.py
/home/book/python/L9/many_users.py
/home/book/python/L9/pizza.py
/home/book/python/L9/new peopel.py
/home/book/python/L8
/home/book/python/L8/favorite_languages.py
/home/book/python/L8/user.py
/home/book/python/L8/alien.py
/home/book/python/L8/new peopel.py
/home/book/linux
/home/book/linux/dira
/home/book/linux/dira/test1.txt
/home/book/linux/dira/test2.txt
/home/book/linux/dira/dirb
/home/book/linux/dira/dirb/test1.txt
/home/book/linux/dira/dirb/test2.txt
/home/book/.gnupg
/home/book/.gconf

说了这么多,到底如何区搜索一个文件或者目录呢?请往下看
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值