概述
第四天
文件查找4种方式
whereis 查询范围通过系统环境变量路径搜索文件$PATH,所有的文件
[root@kongd ~]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
[root@kongd ~]# whereis pwd
pwd: /usr/bin/pwd /usr/share/man/man1/pwd.1.gz /usr/share/man/man1p/pwd.1p.gz
which 查询范围通过系统环境变量路径搜索文件$PATH,找的是可执行文件(查找命令文件)
[root@kongd ~]# which locate
/usr/bin/locate
[root@kongd ~]# which whereis
/usr/bin/whereis
locate 全局搜索,但是需要在搜素前将系统文件导入数据库updatedb;查找速度快
[root@kongd ~]# locate whereis
/usr/bin/whereis
/usr/share/bash-completion/completions/whereis
/usr/share/man/man1/whereis.1.gz
*find 全局搜索文件。
参数
|
作用
|
-name
|
匹配名称
|
-perm 644
|
匹配权限(
mode
为完全匹配,
-mode
为包含即可)
|
-user
|
匹配用户
|
-group
|
匹配所有组
|
-mtime -n +n
|
匹配修改内容的时间(
-4
指小于等于
4
天内的文件名;
+4,
大于等于
5
天前的文件
名;
4
指前
4~5
那一天的文件)
|
-atime -n +n
|
匹配访问文件的时间
|
-ctime -n +n
|
匹配修改文件权限的时间
|
-nouser
|
匹配无所有者的文件
|
-nogroup
|
匹配无所有组的文件
|
-newer f1 !f2
|
匹配比文件
f1
新但比
f2
旧的文件
|
-type
b/d/c/p/l/f
|
匹配文件类型(后面的字母参数依次表示块设备、目录、字符设备、管道、链接
文件、文本文件)
|
-size
|
匹配文件的大小(
+50KB
为查找超过
50KB
的文件,而
-50KB
为查找小于
50KB
的文件)
|
prune
|
忽略某个目录
|
-exec ……
{};
|
后面可跟用于进一步处理搜索结果的命令
|
注意事项:
find 查找文件的目录 -path 需要排除的目录 -prune -o -name 需要查询的内容
1)-prune 必须和 -path,-o 一起使用
2)-prune -o 的顺序不 能调换
3)-name等必须放在-prune -o后面才能使用
eg: find . -path ./tmp -prune -o -name "*.txt"
1.按照文件名搜索
[root@localhost ~]# find 搜索路径 [选项] 搜索内容
选项:
-name: 按照文件名搜索
-iname: 按照文件名搜索,不区分文件名大小写
-inum: 按照 inode 号搜索
[root@localhost ~]# find 搜索路径 [选项] 搜索内容
选项:
-size [+|-]大小: 按照指定大小搜索文件 这里的“+”的意思是搜索比指定大小还要大的文件, “-”的意思是搜索比指定大小还要小的文 件
[root@localhost ~]# find 搜索路径 [选项] 搜索内容
选项:
-atime [+|-]时间: 按照文件访问时间搜索
-mtime [+|-]时间: 按照文件数据修改时间搜索
-ctime [+|-]时间: 按照文件状态修改时间搜索
文件压缩解压缩
tar归档命令
选项
|
功能
|
c |
创建
.tar
格式的包文件
|
x |
释放
.tar
格式的包文件
|
t |
查看包中的文件列表
|
v |
表示在命令执行时显示详细的提示信息
|
f
包文
件名
|
用于指定包文件名。当与
-c
选项一起使用时
,
创建的
tar
包文件使用该选项指定的文件名
;
当与
-x
选项一起使用时
,
则释放该选项指定的
tar
包文件
|
p |
打包时保留文件及目录的权限
|
z |
调用
gzip
程序
,
以
gzip
格式压缩或解压缩文件。
|
j |
调用
bzip2
程序
,
以
bzip2
格式压缩或解压缩文件。
|
J |
使用
xz
压缩(
.tar.xz
)。
xz
的压缩率通常比
bzip2
更高。
|
C
目录
路径
名
|
释放包时指定释放的目标的位置。
|
alias 定义命令别名
命令缓存
1.建立命令缓存
执行命令自动在缓存建立
hash -p /usr/bin/touch touch
hash -p /usr/bin/touch chuangjian
2.删除缓存
hash -d chuangjian
hash -r 清空所有缓存
exit终端
缓存特点: 命令缓存---alias--名令文件
[root@162 ~]# hash
hits command
3 /usr/bin/vim
1 /usr/bin/cat
1 /usr/sbin/pidof
2 /usr/bin/su
[root@162 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@162 ~]# which touch
/usr/bin/touch
[root@162 ~]# touch a
[root@162 ~]# hash
hits command
3 /usr/bin/vim
1 /usr/bin/cat
1 /usr/bin/touch
1 /usr/sbin/pidof
2 /usr/bin/su
[root@162 ~]# touch /usr/bin/touch ---=优先通过缓存匹配
[root@162 ~]# hash
hits command
3 /usr/bin/vim
1 /usr/bin/cat
2 /usr/bin/touch
1 /usr/sbin/pidof
2 /usr/bin/su
[root@162 ~]# mv /usr/bin/touch /usr/local/bin
[root@162 ~]# touch b
bash: /usr/bin/touch: No such file or directory
[root@162 ~]# hash -d touch
[root@162 ~]# hash
hits command
3 /usr/bin/vim
1 /usr/bin/cat
1 /usr/sbin/pidof
3 /usr/bin/mv
2 /usr/bin/su
[root@162 ~]# touch b ----不存在缓存以及别名执行环境变量路径下的命令文件
[root@162 ~]# hash -p /usr/bin/tac chakan --别名
history
查看使用频率最高的前三条命令
history | cut -c 7-10 | uniq -c | sort -r | head - 3
最后
以上就是坚强鸭子为你收集整理的RHCSA之路的全部内容,希望文章能够帮你解决RHCSA之路所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复