1. 程式人生 > >Linux CentOS7 VMware find命令、文件名後綴

Linux CentOS7 VMware find命令、文件名後綴

ron -name hang 系統 找文件 使用 選項 rsa UNC

一、find命令

Linux系統中的 find 命令在查找文件時非常有用而且方便。它可以根據不同的條件來查找文件,例如權限、擁有者、修改日期/時間、文件大小等等。在這篇文章中,我們將學習如何使用 find 命令以及它所提供的選項來查找文件。

列出當前目錄和子目錄下的所有文件

[root@davery ~]# find
.
./.bash_logout
./.bash_profile
./.bashrc
./.cshrc
./.tcshrc
./.ssh

搜索所有文件、目錄:find /etc/ -name "xxx*"

root@davery ~]# find /etc/ -name "ssh*"
/etc/ssh
/etc/ssh/sshd_config
/etc/ssh/ssh_config
/etc/ssh/ssh_host_rsa_key
/etc/ssh/ssh_host_rsa_key.pub
/etc/ssh/ssh_host_ecdsa_key
/etc/ssh/ssh_host_ecdsa_key.pub
[root@davery ~]#

搜索目錄,例子:find /etc/ -type d -name "xxx"

[root@davery ~]# find /etc/ -type d -name "ssh"
/etc/ssh
/etc/selinux/targeted/active/modules/100/ssh
[root@davery ~]#

搜索文件,例子:find /etc/ -type f -name "xxx"

[root@davery ~]# find -type f -name "*"
./.bash_logout
./.bash_profile
./.bashrc
./.cshrc
./.tcshrc
./.ssh/known_hosts
./.bash_history
./anaconda-ks.cfg.01
./anaconda-ks.cfg.1

根據文件類型搜索文件

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

[root@davery ~]# find /etc/ -type d

[root@davery ~]# find /etc/ -type b

[root@davery ~]# find /etc/ -type c

查看文件具體信息,stat 1.txt

[root@davery ~]# ls
1.txt anaconda-ks.cfg.01 anaconda-ks.cfg.1 davery make uear1 user1
[root@davery ~]#
[root@davery ~]#
[root@davery ~]# stat 1.txt
文件:"1.txt"
大小:6 塊:0 IO 塊:4096 目錄
設備:803h/2051d Inode:652696 硬鏈接:2
權限:(0755/drwxr-xr-x) Uid:( 0/ root) Gid:( 0/ root)
環境:unconfined_u:object_r:admin_home_t:s0
最近訪問:2018-03-30 21:57:22.470173086 +0800 Access: -atime


最近更改:2018-03-29 00:12:37.656441521 +0800 Modify: -mtime
最近改動:2018-03-29 00:17:05.797933042 +0800 Change:-ctime
創建時間:- Birth
[root@davery ~]#

查看/etc裏面1天內更改的信息

[root@davery ~]# find /etc/ type f -mtime -1
/etc/
/etc/resolv.conf
/etc/cron.daily
/etc/group
/etc/gshadow
[root@davery ~]#

查看/etc裏面60分鐘內更改的信息

[root@davery ~]# find /etc/ -type f -mmin -60
/etc/resolv.conf
/etc/group
/etc/gshadow
[root@davery ~]#

查找大於1000k文件

[root@davery ~]# [root@davery ~]# find /etc/ -type f -size +1000k
/etc/udev/hwdb.bin
/etc/selinux/targeted/active/policy.kern
/etc/selinux/targeted/contexts/files/file_contexts.bin
/etc/selinux/targeted/policy/policy.30
[root@davery ~]#

查找大於1000k文件並顯示大小

[root@davery ~]# find /etc/ -type f -size +1000k -exec ls -lh {} \;
-r--r--r--. 1 root root 7.2M 3月 23 06:09 /etc/udev/hwdb.bin
-rw-r--r--. 1 root root 3.6M 8月 6 2017 /etc/selinux/targeted/active/policy.kern
-rw-r--r--. 1 root root 1.4M 8月 6 2017 /etc/selinux/targeted/contexts/files/file_contexts.bin
-rw-r--r--. 1 root root 3.6M 8月 6 2017 /etc/selinux/targeted/policy/policy.30
[root@davery ~]#

二、文件名後綴

需要區分大小寫

[root@davery ~]# ls
1.txt anaconda-ks.cfg.01 anaconda-ks.cfg.1 davery make uear1 user1
[root@davery ~]#
[root@davery ~]# Ls
-bash: Ls: 未找到命令
[root@davery ~]#

Linux CentOS7 VMware find命令、文件名後綴