使用 ls 和 grep 列出具有某些扩展名的文件 [英] List files with certain extensions with ls and grep
本文介绍了使用 ls 和 grep 列出具有某些扩展名的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想从当前目录获取文件,只输出 .mp4 .mp3 .exe 文件,别无其他.所以我想我可以这样做:
I just want to get the files from the current dir and only output .mp4 .mp3 .exe files nothing else. So I thought I could just do this:
ls | grep .mp4$ | grep .mp3$ | grep .exe$
但是不会,因为第一个 grep 将只输出 mp4,因此不会使用其他 2 个 grep.
But no, as the first grep will output just mp4's therefor the other 2 grep's won't be used.
有什么想法吗?PS,在Slow Leopard上运行这个脚本.
Any ideas? PS, Running this script on Slow Leopard.
推荐答案
为什么不:
ls *.{mp3,exe,mp4}
我不确定我是从哪里学到的 - 但我一直在使用它.
I'm not sure where I learned it - but I've been using this.
这篇关于使用 ls 和 grep 列出具有某些扩展名的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文