我需要搜索以某些特定名称开头的文件。可以有多个以特定模式开头的文件,我想列出目录中存在的所有此类文件。
要完成现有答案,请执行以下操作:
ls
默认目录列表实用程序ls
可以与Shell的通配符结合使用。要搜索所有带有pattern的文件abc
:
ls -d abc* # list all files starting with abc---
ls -d *abc* # list all files containing --abc--
ls -d *abc # list all files ending with --abc
请注意,文件扩展名也与搜索结果相关。
tree
如果我们需要在目录树中列出文件,我们还可以发出命令tree
来搜索给定的模式,例如:
tree -P 'abc*' # list directory tree of file starting with abc---
tree -l 'def*' # exclude files starting with def---
在这种情况下,tree
它本身支持通配符。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句