9月18日任務node
2.23/2.24/2.25 find命令數據庫
2.26 文件名後綴express
which 搜索可執行文件,必須在PATH環境變量目錄中!!不然沒法搜到!vim
[root@centos7 ~]# which ls alias ls='ls --color=auto' /usr/bin/ls
用來查找一個命令相關的文件(二進制文件、源文件和manual文件)centos
[root@centos7 ~]# whereis ls ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
默認系統未安裝 使用 yum install -y mlocate 安裝;locate會搜索包含命令後續所給參數的全部文件!!bash
初次完裝須要初始化數據庫:updatedbui
[root@centos7 ~]# yum install -y mlocate [root@centos7 ~]# updatedb [root@centos7 ~]# locate ls /boot/grub2/i386-pc/blscfg.mod /boot/grub2/i386-pc/cbls.mod /boot/grub2/i386-pc/command.lst /boot/grub2/i386-pc/crypto.lst ...
默認在天天凌晨4點會自動執行數據庫的更新;centos7
注意:在更新後新建立的文件、目錄,使用locate命令將沒法搜索到,這時手動執行 updatedb 後才能搜索到!spa
ctrl + d 暫停執行的命令3d
ctrl + c 中止執行的命令
ctrl + u 刪除光標前至開頭的輸入
ctrl + a 移動光標至行首
ctrl + e 移動光標至行尾
stat命令能夠顯示文件、目錄的三個時間
atime 訪問時間
mtime 更改時間(改的是內容)
ctime 改動時間(權限、名稱、inode號)
修改了內容,其mtime會變,同時ctime也會變(inode會隨內容變化而變化),但atime不變。
cat命令只會更新atime
vim命令修改文件但不保存不更新三個time
vim命令修改文件並保存,三個time都更新
chmod修改權限更新ctime
touch命令三個time都更新(很特殊)
使用echo追加數據至文件,不改變atime!由於文件未被查看,也沒被打開,可是文件的內容、inode都變了,所以mtime和ctime變了!
!!但凡更改了mtime,ctime會隨之更改;但反過來更改ctime,mtime卻不必定改變。(touch命令狀況除外)
對文件內容進行修改,文件的inode號隨之更改,所以ctime會改變;
而改變了文件的權限,文件的ctime會改變,可是只要文件的內容不變,mtime不會改變(touch除外)
一個功能強大的搜索命令
使用方法:find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
-name 按文件名來查找(-iname 忽略大小寫)
-type 按文件類型來查找
-size 按文件大小來查找
-inum 按inode號來查找
-depth 大類
按目錄深度來查找(具體有-maxdepth/-mindepth)
-time 大類 按時間來查找(具體有-amin/cmin/mmin,atime/ctime/mtime)
-executable 按是否可執行(有x權限)
-newer 按是否比參考文件更新(修改時間裏如今更近),對應的有-older參數
-user/group 按文件的全部者/所屬組來查找
-perm MODE 按文件權限(數字形式)
-uid/gid 按文件的uid/gid來查找
-delete 對查找的內容進行刪除操做
# 配置-name使用,刪除找到的文件/目錄 [root@centos7 test]# find /test/ -name "*.txt" -delete
# 將大於100M的文件建立備份 # 注意命令最後的「\;」 [root@centos7 test]# find / -type f -size +100M -exec cp {} {}.bak \;
# -print0打印時會將換行符也取消,顯示內容的一部分會出如今下一個提示符行首 [root@centos7 test]# find /test -type d -print0 /test/test/dir1[root@centos7 test]# [root@centos7 test]# find /test -type d -print /test /test/dir1
配合管道和xargs
它會將目錄的子目錄下的文件也都顯示出來!! [root@centos7 test]# find /test -type f | xargs ls -l -rw-r--r--. 2 root root 8 ... /test/1.txt -rw-r--r--. 2 root root 8 ... /test/2.txt -rw-r--r--. 1 root root 0 ... /test/dir1/test.txt
-a 同時知足多個條件
# 多個條件限定查找 [root@centos7 test]# find /root -type d -a -name "test" | xargs ls -ld drwxr-xr-x. 3 root root 162 ... /root/test
[root@centos7 test]# find /root -name "tmp" -o -name "test" | xargs ls -ld drwxr-xr-x. 3 root root 162 ... /root/test drwxr-xr-x. 2 root root 73 ... /root/tmp
Linux下的文件後綴沒有什麼實際意義,給文件添加後綴的目的是爲了方便區分!!
使用stat命令能夠查看文件類型!