设为首页 收藏本站
查看: 431|回复: 0

[经验分享] 如何在Linux下递归查看所有文件或目录?

[复制链接]

尚未签到

发表于 2016-3-28 07:10:39 | 显示全部楼层 |阅读模式

find命令,是个非常nice的命令,如果你还不了解这个命令,可以使用man find命令,来查看具体的介绍,find命令结合grep命令之后是非常强大的:
(1)找出某个目录下所有的文件,并且是csv结尾的:

[search@dnode1 2015-04-10]$ find ./conversions/ -type f | grep "csv$"
./conversions/pv/tmp_search_date_cate_pv/tmp_search_date_cate_pv.csv
./conversions/pv/tmp_search_date_algo_channel_pv/tmp_search_date_algo_channel_pv.csv
./conversions/pv/tmp_search_date_pv/tmp_search_date_pv.csv
./conversions/pv/tmp_search_date_algo_pv/tmp_search_date_algo_pv.csv
./conversions/pv/tmp_search_date_algo_country_pv/tmp_search_date_algo_country_pv.csv
./conversions/pv/tmp_search_date_algo_cate_pv/tmp_search_date_algo_cate_pv.csv
[search@dnode1 2015-04-10]$


(2)同理找出以0结尾的文件:

[search@dnode1 2015-04-10]$ find ./conversions/ -type f | grep "0$"   
./conversions/uv/tmp_search_date_algo_uv/000000_0
./conversions/uv/tmp_search_date_algo_channel_uv/000000_0
./conversions/uv/tmp_search_date_cate_uv/000000_0
./conversions/uv/tmp_search_date_algo_country_uv/000000_0
./conversions/uv/tmp_search_date_country_uv/000000_0
./conversions/uv/tmp_search_date_channel_uv/000000_0
./conversions/uv/tmp_search_date_uv/000000_0
./conversions/uv/tmp_search_date_algo_cate_uv/000000_0
./conversions/keyword/tmp_search_kw_algo_rate/000000_0
./conversions/keyword/tmp_search_kw_rate/000000_0
./conversions/pv/tmp_search_date_cate_pv/000000_0
./conversions/pv/tmp_search_date_algo_channel_pv/000000_0
./conversions/pv/tmp_search_date_pv/000000_0
./conversions/pv/tmp_search_date_algo_pv/000000_0
./conversions/pv/tmp_search_date_algo_country_pv/000000_0
./conversions/pv/tmp_search_date_channel_pv/000000_0
./conversions/pv/tmp_search_date_algo_cate_pv/000000_0
./conversions/pv/tmp_search_date_country_pv/000000_0
[search@dnode1 2015-04-10]$

(3)查看所有的目录:

[search@dnode1 2015-04-10]$ find ./conversions/ -type d              
./conversions/
./conversions/uv
./conversions/uv/tmp_search_date_algo_uv
./conversions/uv/tmp_search_date_algo_channel_uv
./conversions/uv/tmp_search_date_cate_uv
./conversions/uv/tmp_search_date_algo_country_uv
./conversions/uv/tmp_search_date_country_uv
./conversions/uv/tmp_search_date_channel_uv
./conversions/uv/tmp_search_date_uv
./conversions/uv/tmp_search_date_algo_cate_uv
./conversions/keyword
./conversions/keyword/tmp_search_kw_algo_rate
./conversions/keyword/tmp_search_kw_rate
./conversions/pv
./conversions/pv/tmp_search_date_cate_pv
./conversions/pv/tmp_search_date_algo_channel_pv
./conversions/pv/tmp_search_date_pv
./conversions/pv/tmp_search_date_algo_pv
./conversions/pv/tmp_search_date_algo_country_pv
./conversions/pv/tmp_search_date_channel_pv
./conversions/pv/tmp_search_date_algo_cate_pv
./conversions/pv/tmp_search_date_country_pv
[search@dnode1 2015-04-10]$
find命令的说明:
[search@dnode1 2015-04-10]$ man find
FIND(1)                                                                FIND(1)
NAME
find - search for files in a directory hierarchy
SYNOPSIS
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]
DESCRIPTION
This  manual page documents the GNU version of find.  GNU find searches the directory tree rooted at each given file name by evaluating the given expression from left to
right, according to the rules of precedence (see section OPERATORS), until the outcome is known (the left hand side is false for and operations, true for or),  at  which
point find moves on to the next file name.
If  you are using find in an environment where security is important (for example if you are using it to search directories that are writable by other users), you should
read the "Security Considerations" chapter of the findutils documentation, which is called Finding Files and comes with findutils.   That document also  includes  a  lot
more detail and discussion than this manual page, so you may find it a more useful source of information.
OPTIONS
The  -H, -L and -P options control the treatment of symbolic links.  Command-line arguments following these are taken to be names of files or directories to be examined,
up to the first argument that begins with ‘-’, or the argument ‘(’ or ‘!’.  That argument and any following arguments are taken to be the expression describing  what  is
to  be  searched  for.  If no paths are given, the current directory is used.  If no expression is given, the expression -print is used (but you should probably consider
using -print0 instead, anyway).
This manual page talks about ‘options’ within the expression list.  These options control the behaviour of find but are specified immediately after the last  path  name.
The  five  ‘real’  options -H, -L, -P, -D and -O must appear before the first path name, if at all.  A double dash -- can also be used to signal that any remaining argu-
ments are not options (though ensuring that all start points begin with either ‘./’ or ‘/’ is generally safer if you use wildcards in the list of start points).
-P     Never follow symbolic links.  This is the default behaviour.  When find examines or prints information a file, and the file is a symbolic  link,  the  information
used shall be taken from the properties of the symbolic link itself.
-L     Follow  symbolic  links.   When  find examines or prints information about files, the information used shall be taken from the properties of the file to which the
link points, not from the link itself (unless it is a broken symbolic link or find is unable to examine the file to which the link points).  Use  of  this  option
implies -noleaf.  If you later use the -P option, -noleaf will still be in effect.  If -L is in effect and find discovers a symbolic link to a subdirectory during
its search, the subdirectory pointed to by the symbolic link will be searched.
When the -L option is in effect, the -type predicate will always match against the type of the file that a symbolic link points to rather  than  the  link  itself
(unless the symbolic link is broken).  Using -L causes the -lname and -ilname predicates always to return false.
-H     Do  not  follow  symbolic  links,  except while processing the command line arguments.  When find examines or prints information about files, the information used
shall be taken from the properties of the symbolic link itself.   The only exception to this behaviour is when a file specified on the command line is a  symbolic
link,  and  the  link  can  be resolved.  For that situation, the information used is taken from whatever the link points to (that is, the link is followed).  The
information about the link itself is used as a fallback if the file pointed to by the symbolic link cannot be examined.  If -H is in effect and one of  the  paths
specified  on  the  command  line  is  a symbolic link to a directory, the contents of that directory will be examined (though of course -maxdepth 0 would prevent
this).
If more than one of -H, -L and -P is specified, each overrides the others; the last one appearing on the command line takes effect.  Since it  is  the  default,  the  -P
option should be considered to be in effect unless either -H or -L is specified.
GNU find frequently stats files during the processing of the command line itself, before any searching has begun.  These options also affect how those arguments are pro-
cessed.  Specifically, there are a number of tests that compare files listed on the command line against a file we are currently considering.  In  each  case,  the  file
specified  on  the command line will have been examined and some of its properties will have been saved.  If the named file is in fact a symbolic link, and the -P option
is in effect (or if neither -H nor -L were specified), the information used for the comparison will be taken from the properties of the  symbolic  link.   Otherwise,  it
will  be taken from the properties of the file the link points to.  If find cannot follow the link (for example because it has insufficient privileges or the link points
to a nonexistent file) the properties of the link itself will be used.
:

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-196400-1-1.html 上篇帖子: linux 下 使用 iptable 和 nginx 封IP 下篇帖子: linux步步为营(1)--高级
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表