Day10 find命令、文件名後綴

stat 命令

  • 用於查看文件的具體信息

示例:node

[root@centos001 ~]# ls
111  22.txt  2.txt  aling       anaconda-ks.cfg.1  ls2  //隨便選擇一個文件
123  234     3.txt  aminglinux  dir3               yum.log
[root@centos001 ~]# stat 2.txt             //用stat列出其文件屬性
  文件:"2.txt"
  大小:0         	塊:0          IO 塊:4096   普通空文件
設備:fd00h/64768d	Inode:33575023    硬連接:1
權限:(0664/-rw-rw-r--)  Uid:(    0/    root)   Gid:(    0/    root)
環境:unconfined_u:object_r:admin_home_t:s0
最近訪問:2018-06-8 10:18:17.839439736 +0800         //這裏能夠看到文件的信息   atime
最近更改:2018-06-8 09:58:25.036568990 +0800       //ctime
最近改動:2018-06-8 10:17:57.282645569 +0800      //mtime
建立時間:-

find命令

  • 用來搜索的其餘命令:which 、whereis、locate(須要yum安裝並用updatedb生成)
  • 幾個經常使用快捷鍵
CTRL+C //結束(終止)當前命令
CTRL+D //退出當前終端
CTRL+Z  //暫停當前進程
CTRL+L  //清屏
CTRL+A //移動光標到最前
CTRL+E //移動光標到最後
CTRL+U //刪除光標前的字符

經常使用find命令

  • -name filename:直接查找該文件名的文件linux

    示例:centos

[root@centos001 ~]# find /etc/ -name "sshd_config"   //在etc目錄下搜索一個已知名字的文件
/etc/ssh/sshd_config
[root@centos001 ~]# find /etc/ -name "sshd*"        //模糊搜索 用「*」代替不知道的名稱
/etc/ssh/sshd_config
/etc/systemd/system/multi-user.target.wants/sshd.service
/etc/sysconfig/sshd
/etc/pam.d/sshd
  • -type filetype:經過文件類型(如:f.b.c.d.l.s等)查找文件ssh

    示例:code

[root@centos001 ~]# find /etc/ -type l       //查找一個軟連接文件
[root@centos001 ~]# ls -l /etc/rc1.d/      //選擇一個路徑查看其文件類型
總用量 0
lrwxrwxrwx. 1 root root 20 4月  29 18:55 K50netconsole -> ../init.d/netconsole
lrwxrwxrwx. 1 root root 17 4月  29 18:55 K90network -> ../init.d/network
  • -atime +n/-n:查找訪問或執行時間大於或小於n的文件
  • -ctime +n/-n:查找寫入或更改inode屬性的時間大於或小於n的文件

示例:進程

[root@centos001 ~]# find /etc/ -type f -ctime -1  //查找一個在一天內更改過inode屬性的文件
/etc/resolv.conf
/etc/sysconfig/network-scripts/.ifcfg-en.swp
/etc/sysconfig/network-scripts/ifcfg-ens33
/etc/tuned/active_profile
  • -mtime +n/-n:查找寫入時間大於或小於n的文件

示例:ip

[root@centos001 ~]# find /etc/ -type f -mtime -1 //在目錄etc下查找寫入時間在一天內的文件  切時間前只能用用加減號
/etc/resolv.conf                                                         
/etc/sysconfig/network-scripts/.ifcfg-en.swp
/etc/sysconfig/network-scripts/ifcfg-ens33
/etc/tuned/active_profile
  • -o:或者選項 有二者其中之一

示例:get

[root@centos001 ~]# find /etc/ -type f -o -mtime -1 -o -name 「*.conf」  //查找一個 etc目錄下一天之內或者叫有conf結尾的文件
  • -inum:查找一個文件的inode號

示例:it

[root@centos001 ~]# ln ls2  /tmp/5.txt.bak   //建立一個文件ls2的硬連接
[root@centos001 ~]# ls -l ls2                            //查看文件屬性
-rw-r--r--. 2 root root 0 5月 25 02:55 ls2    //用戶前面的2表示 硬連接已經建立成功
[root@centos001 ~]# ls -i ls2              //查看文件的inode號
33574978 ls2
[root@centos001 ~]# find / -inum 33574978          //查詢有這個inode號的文件 。就能找到一個文件的硬連接位置
/root/ls2
/tmp/5.txt.bak
  • -mmin+n/-n:查找大於或小於n分鐘的文件

示例:console

[root@centos001 ~]# find /etc/ -type f -mmin -300        //查找5小時內的文件
/etc/resolv.conf
  • -exec: 在查找文件時列出文件 **語法:-exec ls -l {} ;**必定要寫正確好比:斜槓前面有空格

示例:

[root@centos001 ~]# find /etc/ -type f -mmin -300 -exec ls -l {} \;    //查找一個小於300分鐘內的文件並列出
-rw-r--r--. 1 root root 84 5月 27 22:03 /etc/resolv.conf
  • -size+n/-n: 查找一個文件大於或小於n的文件 需指定文件類型,n後面必需要加單位如:k .m

示例:

[root@centos001 ~]# find /root/ -type f -size +10k -exec ls -l {} \;    //查找一個大於10k的文件並列出
-rw-r--r--. 1 root root 12288 5月  31 14:02 /root/.ssh/.authorized_keys.swp

文件名後綴

  • linux中文件名後綴,不表明一個文件的類型。只是爲了方便人們區分
  • 當區分不清中文名時,能夠把語言切換至英文加以區分 :

示例:

[root@centos001 ~]# LANG=en  //將系統語言改爲英語
[root@centos001 ~]# echo $LANG    //查看系統語言
en
[root@centos001 ~]# stat 2.txt 
  File: '2.txt'
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: fd00h/64768d	Inode: 33575023    Links: 1
Access: (0664/-rw-rw-r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2018-05-26 10:18:17.839439736 +0800          //先在就比中文更好區分了
Modify: 2018-05-26 09:58:25.036568990 +0800
Change: 2018-05-26 10:17:57.282645569 +0800
 Birth: -
相關文章
相關標籤/搜索