find命令、文件名後綴
find命令
whereis
locate:
[root@localhost ~]# yum install -y mlocate
[root@localhost ~]# locate ls //每天淩晨4點自動生成
locate: can not stat () `/var/lib/mlocate/mlocate.db‘: No such file or directory
[root@localhost ~]# locate lsx //會把帶有這個字符的都找出來
/home/lsx
/home/lsx/.bash_logout
/home/lsx/.bash_profile
/home/lsx/.bashrc
/root/lsx
/root/lsx/111
/var/spool/mail/lsx
ctrl+c是強制中斷程序的執行
ctrl+z的是將任務中止(暫停的意思)
ctrl-d表示退出當前shell
[root@localhost ~]# find /tmp/ -name yum.log //只知道名字和路徑搜索
/tmp/yum.log
[root@localhost ~]# find /tmp/ -name y* //名字記不清了
/tmp/yum.log
type類型有:f、d、l、s、c(字符串設備)、b
[root@localhost ~]# find /tmp/ -name y* -type d //搜索目錄(或者文件f)名字不太清的情況
[root@localhost ~]# find /root/ -type l //搜索軟鏈接
/root/lsx/111
/root/1_soft.txt
atime 文件訪問時間、
ctime 改變文件屬性、
mtime 改變文件內容。(改變文件內容ctime一定會變,因為ctime記錄文件時間,大小,大小變了)
[root@localhost ~]# stat 1_hard.txt
File: ‘1_hard.txt‘
Size: 973 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051dInode: 33895969 Links: 2
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:admin_home_t:s0
Access: 2017-10-15 22:41:18.762003887 +0800 //最近訪問
Modify: 2017-10-15 22:41:18.769003887 +0800 //最近更改
Change: 2017-10-21 04:41:41.990537620 +0800 //最近改動
Birth: -
改變文件內容ctime一定會變,因為ctime記錄文件時間,大小,大小變了
[root@localhost ~]# echo "sda">>lsx.txt
[root@localhost ~]# stat lsx.txt
File: ‘lsx.txt‘
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051dInode: 34383610 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2017-10-21 06:53:45.684631141 +0800
Modify: 2017-10-21 06:54:04.602631364 +0800
Change: 2017-10-21 06:54:04.602631364 +0800
Birth: -
-1 一天以內
+1 一天以前
[root@localhost ~]# find /root -type f -mtime -1 //在/root目錄下尋找一天以內內容更改的文件
/root/.bash_history
/root/.lesshst
/root/lsx.txt
[root@localhost ~]# find /root -type f -o -atime -1 -o -name lsx.* //-o或者
/root
/root/.bash_logout
/root/.bash_profile
[root@localhost ~]# ll -i
total 12
33895969 -rwxrwxrwx. 2 root root 973 Oct 15 22:41 1_hard.txt
34383604 lrwxrwxrwx. 1 root root 15 Oct 21 04:41 1_soft.txt -> anaconda-ks.cfg
33895969 -rwxrwxrwx. 2 root root 973 Oct 15 22:41 anaconda-ks.cfg
根據inode查找文件
[root@localhost ~]# find / -type f -inum 33895969
/root/anaconda-ks.cfg
/root/1_hard.txt
一小時以內的改變文件內容的mmin、amin、cmin
[root@localhost ~]# find /root -type f -mmin -60
/root/lsx.txt
[root@localhost ~]# find /root -type f -cmin -60 -exec ls -l {} \;
-rwxrwxrwx. 2 root root 973 Oct 15 22:41 /root/anaconda-ks.cfg
-rwxrwxrwx. 2 root root 973 Oct 15 22:41 /root/1_hard.txt
-rwxrwxrwx. 1 root root 6 Oct 21 06:55 /root/lsx.txt
[root@localhost ~]# find /root/ -type f -mmin -60 -exec mv {} {}.bak \;
[root@localhost ~]# find /root -type f -cmin -60
/root/lsx.txt.bak
文件大小
[root@localhost ~]# find /root/ -size +2k
/root/
/root/.bash_history
[root@localhost ~]# find / -type f -size +10M //文件大小大於10M的
/boot/initramfs-0-rescue-2ba7435fb8a348109570f5a113e9dc5d.img
/proc/kcore
2.26 文件名後綴
Linux後綴不嚴謹、可以自定義文件名。不能代表這個文件的類型。
習慣於相同類型的文件,定義相同類型的後綴名。便於區分
本文出自 “帕多克的癡迷” 博客,請務必保留此出處http://lsxme.blog.51cto.com/12400127/1975891
find命令、文件名後綴