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

发布了53 篇原创文章 · 获赞 16 · 访问量 2213

猜你喜欢

转载自blog.csdn.net/m0_37757533/article/details/105350687
今日推荐