Results 1 to 9 of 9
need to list all files and in all sub-directories that have a particular extension like *.mpg
from a newbie looking at the man pages it would go something like
ls ...
- 06-17-2010 #1Just Joined!
- Join Date
- Jun 2010
- Posts
- 2
LS command line bash help please!
need to list all files and in all sub-directories that have a particular extension like *.mpg
from a newbie looking at the man pages it would go something like
ls *.mpg -R but no joy there...
thanks!!
- 06-17-2010 #2
Welcome to the forums!
`ls` does a lot, but in these cases you probably want to use `find`.
Something like:
Code:find /path/to/files -name \*.mpg -print
Can't tell an OS by it's GUI
- 06-17-2010 #3Just Joined!
- Join Date
- Jun 2010
- Posts
- 2
Thanks Freston,
any way to expand on your example to exclude certain directories? I guess I have a ton in my $RECYCLE.BIN which is making it difficult to find what I want...
rg
- 06-17-2010 #4
Experimented with my own thing - nothing distasteful - and it responded well to
'find' is an unfriendly bugger. And they seem to have changed it, at least its 'info'. The best thing about it in the past was its extensive 'info'.Code:find ~/* -name '*\.mp3' -print
- 06-17-2010 #5Easiest way is to pipe through `grep -v`, something like this:
Originally Posted by greener
Code:find /path/to/files -name \*.mpg -print | grep -v "trash"
Can't tell an OS by it's GUI
- 06-17-2010 #6
- 06-18-2010 #7
Find is indeed not easy to use, but it is a very powerful tool.
If you want to learn about find read this tutorial:
Beginners Linux Guide; Using the find commandFedora 13, GNOME
HP Compaq NC6000, Intel Pentium M Processor 725, ATI Mobility Radeon 9600, Intel PRO 2200BG
HP Compaq DC7100, Intel Pentium 4 Processor 541, Intel 915G Express, D-Link DWL-510 AirPlus G
- 06-18-2010 #8
Yabut...
ls -R *.mpg will only work if there actually is a matching file in the specified directory. Also, the output of find is much friendlier as a list to be piped to some other tool. It just gives the full filespec of each matching file, and no cruft to filter out.
--- rod.Last edited by oz; 06-03-2011 at 10:50 PM. Reason: removed SPAM from quote
Stuff happens. Then stays happened.
- 06-19-2010 #9
Obviously there are many different ways to do the same thing.
As OP requested files in ALL directories a small correction is required.
Code:ls -Ra | grep mpg
Fedora 13, GNOME
HP Compaq NC6000, Intel Pentium M Processor 725, ATI Mobility Radeon 9600, Intel PRO 2200BG
HP Compaq DC7100, Intel Pentium 4 Processor 541, Intel 915G Express, D-Link DWL-510 AirPlus G


Reply With Quote
