文件/目录操作(6)——which、whereis、locate、find命令
来源:互联网 发布:宁波江东行知小学校服 编辑:程序博客网 时间:2024/06/04 18:22
1,Linux命令的分类?
(1)系统命令: /bin 和 /sbin下的(管理员命令)
应用程序命令:/usr/bin 和 /usr/sbin下的
(2) 内部命令:打开了新的shell时会自动加载的
外部命令:通过安装软件包有的
2,关于$PATH这个变量?
$PATH 是命令搜索路径[root@vm_hosts test]# echo $PATH /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
which命令
(1)在PATH变量指定的路径中,查询命令存放的路径;(2)返回第一个搜索结果且不再继续寻找;
(3)alias别名优先于PATH查找;(使用的时候也是优先别名的)
(4)找的对象必须具有可执行权限,且只能查找外部命令
[root@vm_hosts ~]# which cpalias cp='cp -i' /bin/cp
[root@vm_hosts ~]# which alias //which alias 发现找不到,说明alias是内部命令/usr/bin/which: no alias in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
whereis命令
(1)在PATH变量指定的路径中,查询命令存放的路径、帮助文件路径;
(2)返回所有搜索到的结果;
[root@localhost ~]# whereis cpcp: /bin/cp /usr/share/man/man1/cp.1.gz /usr/share/man/man1p/cp.1p.gz
locate命令
(1)locate string 可以查看包含string字样的所有的文件路径;
(2)locate命令使用时,会遍历locate专用的一个数据库文件 /var/lib/(整个linux目录树结构形成的),从中查找;
(3)updatedb命令可更新这个数据库 //新建与删除后都要更新才能locate出效果。
find命令
一、按各种方式查找
(1)-name:按文件名称查找
(2)-size:按文件大小查找(单位K、M、G)
“+n”表示大于这个值
“-n”表示小于这个值
“n” 表示等于这个值
(3)-type:按对象类型查找(目录d,普通文件f,链接文件l,字符设备文件c,块设备文件b,管道文件p)
(4)-mtime:按对象内容修改时间查找(天数)
-atime:按对象被访问的时间查找(天数)
-ctime:按对象状态被修改的时间去查找(天数)
-mmin/-amin/-cmin:(分钟数)
“+ n” n天/分钟前的
“- n” n天/分钟内的
(5)-user:按文件属主查找
(6)-perm:按文件权限查找
二、常配合exec和xargs使用
(1)-exec 表示执行后面的命令;“{}”表示存放find命令查找的结果 ;“\;”表示结束标志。
(2)xargs 表示将前面命令的输出做为参数送给后面的命令使用。
[root@teacher ~]# find /boot -name "vmlinuz*" | xargs ls -l-rwxr-xr-x. 1 root root 4044560 Jan 30 2013 /boot/vmlinuz-2.6.32-358.el6.x86_64[root@teacher ~]# find /boot -name "vmlinuz*" -exec ls -l {} \; -rwxr-xr-x. 1 root root 4044560 Jan 30 2013 /boot/vmlinuz-2.6.32-358.el6.x86_64
三、逻辑运算及一些特殊选项
(1)-a 且
(2)-o 或
(3)!/ -not 非
(4)-ok 提醒你是否要执行后面的删除命令
[root@teacher lianxi]# find / -name zhongguohehuoren -ok rm -rf {} \; < rm ... /bin/zhongguohehuoren > ? y< rm ... /lianxi/zhongguohehuoren > ? y< rm ... /zhongguohehuoren > ? y</span>(5)-maxdepth 后面跟数字num,表示在当前目录下往下num层深度查找(默认为1层)
四,应用实例
find /boot -size +1024k -o -name "vmlinuz*" |xargs ls -lfind /boot -size +1M -a -name "vmlinuz*" -a -type f|xargs ls -lfind /boot -type d -name "grub*"|xargs ls -dlhfind /boot -size +1M ! -size +4M -exec ls -lh {} \;find /boot -size +1M -size -4M -exec ls -lh {} \; //语法没有问题,但结果并未完全显示find /etc/ -maxdepth 1 -name "p*" | grep passwd </span>
0 0
- 文件/目录操作(6)——which、whereis、locate、find命令
- 文件查找命令find,locate,whereis,which
- 文件查找命令-which,whereis,locate,find
- 文件搜索命令 locate、find、whereis、which
- Linux 文件路径查询命令(find、locate、which、whereis)
- linux命令:文件搜索(locate、whereis、which、find、grep)
- 【Linux】文件查找——which、whereis、locate、find...
- Linux基本功——五个查找文件的命令find,locate,whereis,which,type
- 一天一linux命令(12) which whereis locate find 查找文件和目录
- linux中Find、whereis、locate、which查找文件命令总结
- linux中Find、whereis、locate、which查找文件命令总结
- 查找文件命令---find, locate, whereis, which, type
- linux中Find、whereis、locate、which查找文件命令详解
- Linux下which、whereis、locate、find 命令查找文件
- Linux下which、whereis、locate、find 命令查找文件
- Linux下which、whereis、locate、find 命令查找文件
- Linux下which、whereis、locate、find 命令查找文件
- Linux文件查找命令详解-which whereis find locate
- Java环境变量配置
- C++学习笔记18——指向函数的指针
- hihoCoder 1237 Farthest Point
- LeetCode 11 Container With Most Water(最大水容器)
- nyoj 士兵杀敌(二) 116 (线段树模板)
- 文件/目录操作(6)——which、whereis、locate、find命令
- this指针的小结
- PHP 数组常用的几个方法
- 书写第一个jsp程序
- 查看DB2常用数据库字典
- 贝叶斯网格
- android画文本
- HDOJ 1598 find the most comfortable road(并查集+枚举,贪心)
- 游戏系统开发笔记(五)——服务端系统分层