在Linux下搜索文件

在Linux下搜索文件
=============================

1,which 查找可执行文件的绝对路径

[root@aminglinux ~]# which cat

/bin/cat

[root@aminglinux ~]# which passwd

/bin/passwd

2,whereis 查找文件 //很少用
[root@aminglinux ~]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

3,locate 查找文件 //也不常用

4,使用 find搜索文件
NAME
find - search for files in a directory hierarchy(搜索目录层次结构中的文件)

常用用法:
find 目录 -mtime +n/-n 文件
find 目录 -name 文件名称
find 目录 -type 文件类型 {f,d,b,c,l,s}
find 目录 -mmin -分钟数
find 目录 -inum inode号
find 目录 -size +大小/-大小 {k,M(不能用m)}

[root@aminglinux ~]# ll -i 1.txt
33588044 -rw-r--rwx 2 alice jerry 5 6月 25 01:24 1.txt
[root@aminglinux ~]# ll -i 1.txt.hard
33588044 -rw-r--rwx 2 alice jerry 5 6月 25 01:24 1.txt.hard
[root@aminglinux ~]# find -inum 33588044
./1.txt
./1.txt.hard

[root@aminglinux ~]# find /root -type f -mmin -120
/root/.lesshst
/root/1.txt
/root/dir6/1.txt
/root/dir6/2.txt
/root/dir6/3.txt
/root/1.txt.hard
[root@aminglinux ~]# find /root -type f -mmin -120 -exec ls -l {} \;
-rw------- 1 root root 84 6月 25 02:03 /root/.lesshst
-rw-r--rwx 2 alice jerry 5 6月 25 01:24 /root/1.txt
-rw-r--r-- 1 root root 0 6月 25 01:24 /root/dir6/1.txt
-rw-r--r-- 1 root hr 0 6月 25 01:26 /root/dir6/2.txt
-rw-r--r-- 1 root root 0 6月 25 01:30 /root/dir6/3.txt
-rw-r--rwx 2 alice jerry 5 6月 25 01:24 /root/1.txt.hard


[root@aminglinux ~]# find /root -type f -mmin -90 -exec mv {} {}.bak \;

寻找root下面修改时间少于90分钟的文件,并备份。

[root@aminglinux ~]# find /root -type f -size +1k
寻找root下面大于1K的文件

猜你喜欢

转载自www.cnblogs.com/sambo510/p/9251791.html
今日推荐