141 lines
3.6 KiB
Markdown
141 lines
3.6 KiB
Markdown
|
---
|
|||
|
id: 文件查找定位
|
|||
|
title: 文件查找定位
|
|||
|
sidebar_position: 4
|
|||
|
data: 2022年2月25日
|
|||
|
---
|
|||
|
|
|||
|
## pwd
|
|||
|
|
|||
|
pwd命令用于显示用户当前所处的工作目录,英文全称为“print working directory”。
|
|||
|
|
|||
|
## cd
|
|||
|
|
|||
|
cd命令用于切换当前的工作路径,英文全称为“change directory”,语法格式:
|
|||
|
|
|||
|
```shell
|
|||
|
cd [参数] [目录]
|
|||
|
```
|
|||
|
|
|||
|
示例:
|
|||
|
|
|||
|
```shell
|
|||
|
# 退回上一步目录
|
|||
|
cd -
|
|||
|
|
|||
|
# 退回上级目录
|
|||
|
cd ..
|
|||
|
|
|||
|
# 进入当前用户目录
|
|||
|
cd ~
|
|||
|
```
|
|||
|
|
|||
|
## ls
|
|||
|
|
|||
|
ls命令用于显示目录中的文件信息,英文全称为“list”,语法格式:
|
|||
|
|
|||
|
```shell
|
|||
|
ls [参数] [文件名称]
|
|||
|
```
|
|||
|
|
|||
|
## tree
|
|||
|
|
|||
|
tree 命令用于以树状图的形式列出目录内容及结构。
|
|||
|
|
|||
|
```shell
|
|||
|
tree
|
|||
|
```
|
|||
|
|
|||
|
## find
|
|||
|
|
|||
|
find命令用于按照指定条件来查找文件所对应的位置,语法格式:
|
|||
|
|
|||
|
```shell
|
|||
|
find [查找范围] 寻找条件
|
|||
|
```
|
|||
|
|
|||
|
find命令中的参数以及作用
|
|||
|
|
|||
|
| 参数 | 作用 |
|
|||
|
| ----------------- | ------------------------------------------------------------ |
|
|||
|
| -name | 匹配名称 |
|
|||
|
| -perm | 匹配权限(mode为完全匹配,-mode为包含即可) |
|
|||
|
| -user | 匹配所有者 |
|
|||
|
| -group | 匹配所有组 |
|
|||
|
| -mtime -n +n | 匹配修改内容的时间(-n指n天以内,+n指n天以前) |
|
|||
|
| -atime -n +n | 匹配访问文件的时间(-n指n天以内,+n指n天以前) |
|
|||
|
| -ctime -n +n | 匹配修改文件权限的时间(-n指n天以内,+n指n天以前) |
|
|||
|
| -nouser | 匹配无所有者的文件 |
|
|||
|
| -nogroup | 匹配无所有组的文件 |
|
|||
|
| -newer f1 !f2 | 匹配比文件f1新但比f2旧的文件 |
|
|||
|
| -type b/d/c/p/l/f | 匹配文件类型(后面的字幕字母依次表示块设备、目录、字符设备、管道、链接文件、文本文件) |
|
|||
|
| -size | 匹配文件的大小(+50KB为查找超过50KB的文件,而-50KB为查找小于50KB的文件) |
|
|||
|
| -prune | 忽略某个目录 |
|
|||
|
| -exec …… {}\; | 后面可跟用于进一步处理搜索结果的命令(下文会有演示) |
|
|||
|
|
|||
|
示例:
|
|||
|
|
|||
|
```shell
|
|||
|
find /etc -name "host*" -print
|
|||
|
# /etc/host.conf
|
|||
|
# /etc/hosts
|
|||
|
# /etc/hosts.allow
|
|||
|
# /etc/hosts.deny
|
|||
|
# /etc/avahi/hosts
|
|||
|
# /etc/hostname
|
|||
|
```
|
|||
|
|
|||
|
## locate
|
|||
|
|
|||
|
locate 命令用于按照名称快速搜索文件所对应的位置,第一次使用 locate 命令之前,记得先执行 updatedb 命令来生成索引数据库,然后再进行查找。
|
|||
|
|
|||
|
语法格式:
|
|||
|
|
|||
|
```shell
|
|||
|
locate 文件名称
|
|||
|
```
|
|||
|
|
|||
|
示例:
|
|||
|
|
|||
|
```shell
|
|||
|
locate whereis
|
|||
|
# /usr/bin/whereis
|
|||
|
# /usr/share/bash-completion/completions/whereis
|
|||
|
# /usr/share/man/man1/whereis.1.gz
|
|||
|
```
|
|||
|
|
|||
|
## whereis
|
|||
|
|
|||
|
whereis 命令用于按照名称快速搜索二进制程序(命令)、源代码以及帮助文件所对应的位置,语法格式:
|
|||
|
|
|||
|
```shell
|
|||
|
whereis 命令名称
|
|||
|
```
|
|||
|
|
|||
|
示例:
|
|||
|
|
|||
|
```shell
|
|||
|
whereis ls
|
|||
|
# ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
|
|||
|
whereis pwd
|
|||
|
# pwd: /usr/bin/pwd /usr/share/man/man1/pwd.1.gz /usr/share/man/man1p/pwd.1p.gz
|
|||
|
```
|
|||
|
|
|||
|
## which
|
|||
|
|
|||
|
which 命令用于按照指定名称快速搜索二进制程序(命令)所对应的位置,语法格式:
|
|||
|
|
|||
|
```shell
|
|||
|
which 命令名称
|
|||
|
```
|
|||
|
|
|||
|
示例:
|
|||
|
|
|||
|
```shell
|
|||
|
which locate
|
|||
|
# /usr/bin/locate
|
|||
|
which whereis
|
|||
|
# /usr/bin/whereis
|
|||
|
```
|
|||
|
|