编写查找命令

This commit is contained in:
nick 2018-05-02 21:12:58 +08:00
parent bd9d9033ca
commit a9822470b0
2 changed files with 58 additions and 1 deletions

View File

@ -14,7 +14,7 @@
* [file-dir-permissions](file-dir-permissions.md) * [file-dir-permissions](file-dir-permissions.md)
## 查找搜索相关 ## 查找搜索相关
* [find-search](find-search.md) * [find-grep-which-whereis-locate](find-grep-which-whereis-locate.md)
## 查看编辑相关 ## 查看编辑相关
* [cat-less-more-tail-head-vim](cat-less-more-tail-head-vim.md) * [cat-less-more-tail-head-vim](cat-less-more-tail-head-vim.md)

View File

@ -0,0 +1,57 @@
#### find 命令
```
sudo find /usr/local/nginx -name nginx.conf #在 /usr/local/nginx 下查找 nginx.conf 文件
sudo find /usr/local/nginx -iname nginx.conf #在 /usr/local/nginx 下查找 nginx.conf 文件,忽略文件名称大小写
sudo find /home/ ! -name "*.gz" #查找不是 .gz 后缀的文件
sudo find . -type f #查找文件类型为文件
sudo find . -maxdepth 1 -type f #查找文件类型为文件,向下最大深度限制为1
sudo find . -type d #查找文件类型为目录
sudo find . -type f -atime -7 #查找7天之内访问过的文件
sudo find . -type f -atime +7 #查找超过7天的访问文件
sudo find . -type f -atime 7 #查找7天前的访问文件
sudo find . -type f -amin -10 #查找10分钟之内的访问文件
sudo find . -type f -amin 10 #查找超过10分钟的访问文件
sudo find . -type f -amin +10 #查找超过10分钟的访问文件
```
补充:`+` 意思为大于,`-` 意思为小于,没有符合是等于。
- 访问时间(-atime/天,-amin/分钟):用户最近一次访问时间。
- 修改时间(-mtime/天,-mmin/分钟):文件最后一次修改时间。
- 变化时间(-ctime/天,-cmin/分钟):文件数据(包括权限等)最后一次修改时间。
#### grep 命令
```
sudo grep -c '500' fielename.log #查找文件包含500的行数
sudo cat index.html | grep -o 'js' #只输出文件中匹配到的部分
```
#### which 命令
```
which php #查找 php 命令的绝对路径,可用于判断某个系统命令是否存在
```
#### whereis 命令
```
whereis php #查找 php 命令的位置
```
#### locate 命令
```
locate /etc/*.conf #查找 /etc 命令下所有 .conf 后缀的文件,此命令比 find 快
```