如何在Shell的递归目录中列出特定类型的文件? [英] How to list specific type of files in recursive directories in shell?

查看:429
本文介绍了如何在Shell的递归目录中列出特定类型的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何找到特定类型的文件,即嵌套目录中存在的doc pdf文件.

How can we find specific type of files i.e. doc pdf files present in nested directories.

命令:

$ ls -R | grep .doc

但是,如果有文件名,例如alok.doc.txt,该命令也会显示该文件名,这显然不是我想要的.我应该改用什么命令?

but if there is a file name like alok.doc.txt the command will display that too which is obviously not what I want. What command should I use instead?

推荐答案

如果您更喜欢"ls"和"grep",则可以使用grep命令中的正则表达式(以'$结尾'字符表示.doc必须在该行的末尾.这将排除"file.doc.txt"):

If you are more confortable with "ls" and "grep", you can do what you want using a regular expression in the grep command (the ending '$' character indicates that .doc must be at the end of the line. That will exclude "file.doc.txt"):

ls -R |grep "\.doc$"

有关在该人中使用带有正则表达式的grep的更多信息.

More information about using grep with regular expressions in the man.

这篇关于如何在Shell的递归目录中列出特定类型的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆