find命令 和 文件名後綴

[toc]linux

find命令 和 文件名後綴

快捷鍵:
Ctrl + l  :清屏
Ctrl + d :退出終端(至關於執行了:exit 或logout)
Ctrl + c : 強制中斷
Ctrl + u : 在命令輸入行,刪除光標前的字符串
Ctrl + e :  光標移到末尾
Ctrl + a :  光標移到開始

一 find命令

先介紹在Linux中經常使用的幾個快捷鍵:

Ctrl + l :清屏
Ctrl + d :退出終端(至關於執行了:exit 或logout)
Ctrl + c :強制中斷
Ctrl + u :在命令輸入行,刪除光標前的字符串
Ctrl + e :光標移到末尾
Ctrl + a :光標移到開始

which :搜索命令,查找可執行文件的絕對路徑(從echo $PATH環境變量下的目錄查找)

whereis 命令經過預先生成的一個文件列表庫查找與給出的文件名相關的文件,相似於模糊查找

locate命令相似於whereis,這個命令使用前要安裝mlocate軟件包,安裝命令:yum install -y mlocate )

mark

用來定位指令的二進制程序、源代碼文件和man手冊頁等相關文件的路徑。windows

find :搜索文件,在指定目錄下查找文件

根據文件類型進行搜索 find -type/-name

[root@xavi-001 ~]# yum install -y mlocate
已加載插件:fastestmirror, langpacks
[root@xavi-001 ~]# find /etc/ -name "sshd_config"
/etc/ssh/sshd_config
[root@xavi-001 ~]# find /etc/ -name "sshd*"
/etc/ssh/sshd_config
/etc/systemd/system/multi-user.target.wants/sshd.service
/etc/sysconfig/sshd
/etc/pam.d/sshd

f 普通文件

[root@xavi-001 ~]# find /etc/ -type f -name "sshd*"
/etc/ssh/sshd_config
/etc/sysconfig/sshd
/etc/pam.d/sshd

l 連接文件,軟連接即爲該類型

[root@xavi-001 ~]# find /etc/ -type l

mark

d 目錄

c 字符設備文件,也叫串行端口設備,鼠標,鍵盤,打印機

b 塊設備

[root@xavi-001 ~]# find /dev/ -type b
/dev/sr0
/dev/sda3
/dev/sda2
/dev/sda1
/dev/sda

s socket套接字文件,用於進程之間的通訊,MySQL時會用到

p Fifo

stat 文件 查看信息

mark

mark

mark

cat以後只改變了atime

mark

根據文件時間戳進行搜索- atime +n/-n 天,-amin/分 :用戶最近一次訪問或執行時間。

-mtime +n/-n天,-mmin/分:文件最後一次寫入,修改時間。

- ctime +n/-n 天,-cmin/分 :文件數據(例如權限等)最後一次修改時間。(小於一天,能夠用「+」多少天之前的,「-」表示多少天之內的)

舉例:bash

[root@xavi-001 ~]# find /etc/ -type f -mtime -1
/etc/resolv.conf
/etc/tuned/active_profile

查找f類型文件,1天以內,且文件爲.conf的文件,find /etc/ -type f -ctime -1 -name "*.conf"

[root@xavi-001 ~]# find /etc/ -type f -ctime -1 -name "*.conf"
/etc/resolv.conf

or表示爲o,或者,find /tmp/ -type f -o -mtime -1 -o -name "aliases"

[root@xaviyunserver ~]# find /tmp/ -type f -o -mtime -1 -o -name "aliases"
/tmp/
/tmp/bin
/tmp/11.txt
/tmp/123
/tmp/123/1.txt
  • 用find查找硬連接

mark

  • find縮小查找範圍到分鐘,而後查看文件 mark

exec 加命令 find的擴展用法 find /root/ -type f -mmin -700 -exec mv {} {} ;

mark

find查找大於5k,和小於5k的文件, find /root/ -size +5k

[root@xavi-001 ~]# find /root/ -size +5k
/root/.bash_history
[root@xavi-001 ~]# find /root/ -size -5k
/root/
/root/.bash_logout

find 查找同時驗證其大小 -exec ls -lh {} \

[root@xavi-001 ~]# find /root/ -type f -size -10k -exec ls -lh {} \; 
-rw-r--r--. 1 root root 18 Dec 29  2013 /root/.bash_logout
-rw-r--r--. 1 root root 176 Dec 29  2013 /root/.bash_profile
-rw-r--r--. 1 root root 176 Dec 29  2013 /root/.bashrc
-rw-r--r--. 1 root root 100 Dec 29  2013 /root/.cshrc
-rw-r--r--. 1 root root 129 Dec 29  2013 /root/.tcshrc
-rw-r--r--. 1 root root 1.7K Aug  9 00:17 /root/initial-setup-ks.cfg

二 文件名後綴

Linux下的文件有後綴名,但不表明文件的類型,不像Windows下好比file.txt是文本文檔、file.exe是可執行程序。爲了方便識別,要求使用統一的後綴名

.sh       腳本或批處理文件
.bz2     bzip2的壓縮文件
.gz       gzip的壓縮文件
.tar       tar打包文件
.tbz      tar打包並用bzip壓縮文件
.tgz      tar打包並用gzip壓縮的文件
.conf    配置文件
.lock     LOCK文件(用來判斷一個文件或設備是否被使用)
.rpm     REDHATPackage.Manager文件(套件包或軟件包)
.c         C源程序代碼文件 
.cpp     C++源程序代碼文件
.h         C或C++程序的頭文件
.o         程序目標文件
.pl        perl腳本文件
.so       類庫文件

修改支持顯示中文 zh_CM.UTF-8

[root@xavi-001 ~]# LANG=zh_CN.utf-8
[root@xavi-001 ~]# stat 2.txt
stat: 沒法獲取"2.txt" 的文件狀態(stat): 沒有那個文件或目錄

3、 Linux 和Windows互傳文件

安裝軟件包 lrzsz

[root@xavi-001 ~]# yum install -y lrzsz

sz命令,從linux 傳到 windows

mark

rz命令 ,從windows傳到linux,

mark

mark

相關文章
相關標籤/搜索