python怎么用找到命令查找文件

  

python怎么用找到命令查找文件?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

<强>壳编程——文件查找之发现命令

<强> 1。语法格式

找到[路劲][选项][操作]

<强>选项参数对照表

 python怎么用找到命令查找文件“> <img src=

<强> 2. -name ,

查找/etc/目录下以。参看结尾的文件

/etc/- name找到“* .conf"

-iname ,不区分大小写

/etc/- iname找到“* .conf"

-user ,,查找当前目录为根用户的文件

找到。/用户根

<强> 3. -type ,

文件的类型

f ,,文件

d ,目录

c ,字符设备文件

b ,块设备文件

l ,,链接文件

p ,管道文件

找到。类型f

找到。类型d

<强> 4.造

文件大小

-n ,小与n的文件

+ n ,大于n的文件

,查找/etc目录下小与100 k的文件

找到/等造-100 k

查找/etc目录下大于1米的文件

找到/等+ 1 m

<强> 5. -mtime

修改时间

-n ,n天以内修改的文件

+ n ,n天以外修改的文件

n ,,正好n天修改的文件

,查找/etc目录下5天之内修改并且以之结尾的文件

找到/etc -mtime 5 - name & # 39; * . conf # 39;

查找/etc目录下10天之前修改并且属主为根的文件

找到/etc -mtime + 10用户根

<强> 6. -mmin

-n ,n分钟以内修改的文件

+ n ,n分钟以外修改的文件

修改/etc目录下30分钟以内修改的目录

找到/etc -mmin -30类型d

<强> 7. -mindepth 

表示从n级子目录开始搜索

找到/etc -mindepth 3类型- f

-madepth n

表示最多搜索到n - 1级子目录

<强> 8。操作-

对搜索的文件常用操作

-print ,打印输出

-exec ,对文件执行特定的操作

-ok ,,,和exec功能意义,只是每次操作都会给用户提示

- exec的格式为

- & # 39;命令# 39;{}\

例子一:

搜索/home/shell_learn/下的文件,文件名以。sh结尾,且修改时间在一个星期之内的,然后将其删除

#打印   时间/home/shell_learn find  -type  f  -name  & # 39; * . sh # 39;安全性-mtime  7,   #复制   时间/home/shell_learn find  -type  f  -name  & # 39; * . sh # 39;, -mtime  7, -exec  cp  {},/home/shell_learn/测试/,\;   #删除   find /home/shell_learn/, -type  f  -name  & # 39; * . sh # 39;, -mtime  7, -exec  rm  -rf  {}, \;

<强> 9.定位命令

定位不同于找到命令是在整块磁盘中搜索,定位命令是在数据库文件中查找

发现是默认全局匹配,定位则是默认部分匹配

更新资料库命令

用户更新/var/lib/mlocate mlocate.db

所使用的配置文件/etc/updatedb.conf

,实例:更新资料库命令把文件更新到数据库(默认是第二天系统才会自动更新到数据库),否则定位查找不到

[root@VM_0_9_centos  shell_learn] #, touch  789.三种   [root@VM_0_9_centos  shell_learn] #,   [root@VM_0_9_centos  shell_learn] #, locate  789.三种   [root@VM_0_9_centos  shell_learn] #,   [root@VM_0_9_centos  shell_learn] #更新资料库   [root@VM_0_9_centos  shell_learn] #,   [root@VM_0_9_centos  shell_learn] #, locate  789.三种/home/shell_learn/789.三种   [root@VM_0_9_centos  shell_learn] #

<强> 10 .whereis命令

 python怎么用找到命令查找文件

实例

[root@VM_0_9_centos  shell_learn] #, whereis  mysql   mysql:/usr/bin/mysql /usr/lib64/mysql /usr/include/mysql /usr/share/mysql /usr/share/男人/男士一/mysql.1.gz   [root@VM_0_9_centos  shell_learn] #,   [root@VM_0_9_centos  shell_learn] #, whereis  -b  mysql   mysql:/usr/bin/mysql /usr/lib64/mysql /usr/include/mysql /usr/share/mysql   [root@VM_0_9_centos  shell_learn] #,   [root@VM_0_9_centos  shell_learn] #, whereis  -m  mysql   mysql:/usr/share/男人/男士一/mysql.1.gz   [root@VM_0_9_centos  shell_learn] #

python怎么用找到命令查找文件