linux的find命令使用

本文详细介绍了Linux系统中find命令的功能、语法及其常用选项,包括如何通过时间、权限、类型等条件搜索文件,并提供了实际应用场景的示例。
The find command is used to locate files on a Unix or Linux system.  find will search any set of directories you specify for files that match the supplied search criteria.  You can search for files by name, owner, group, type, permissions, date, and other criteria.  The search is recursive in that it will search all subdirectories too.  The syntax looks like this:

find where-to-look criteria what-to-do
All arguments to find are optional, and there are defaults for all parts.  (This may depend on which version of find is used.  Here we discuss the freely available Gnu version of find, which is the version available on YborStudent.)  For example, where-to-look defaults to . (that is, the current working directory), criteria defaults to none (that is, select all files), and what-to-do (known as the find action) defaults to ?print (that is, display the names of found files to standard output).  Technically, the criteria and actions are all known as find primaries.

[root @www ~]# find [PATH] [option] [action]
選項與參數:
1. 與時間有關的選項:共有 -atime, -ctime 與 -mtime ,以 -mtime 說明
   -mtime  n :n 為數字,意義為在 n 天之前的『一天之內』被更動過內容的檔案;
   -mtime +n :列出在 n 天之前(不含 n 天本身)被更動過內容的檔案檔名;
   -mtime -n :列出在 n 天之內(含 n 天本身)被更動過內容的檔案檔名。
   -newer file :file 為一個存在的檔案,列出比 file 還要新的檔案檔名

範例一:將過去系統上面 24 小時內有更動過內容 (mtime) 的檔案列出
[root @www ~]# find / -mtime 0
# 那個 0 是重點!0 代表目前的時間,所以,從現在開始到 24 小時前,
# 有變動過內容的檔案都會被列出來!那如果是三天前的 24 小時內?
# find / -mtime 3 有變動過的檔案都被列出的意思!

範例二:尋找 /etc 底下的檔案,如果檔案日期比 /etc/passwd 新就列出
[root @www ~]# find /etc -newer /etc/passwd
# -newer 用在分辨兩個檔案之間的新舊關係是很有用的!


http://linux.vbird.org/linux_basic/0220filemanager.php#find
http://content.hccfl.edu/pollock/unix/findcmd.htm

转载于:https://my.oschina.net/forrest420/blog/81541

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值