Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-23-2004, 10:42 PM   #1
LQ Newbie
Registered: Sep 2003
Location: Lancaster, PA
Distribution: Redhat 9
Posts: 2

Rep: Reputation: 0
ls command behavior


How do I search for files more then one level below my current dir? For example by typing:

ls */*.mp3 I will see all mp3s one directory below my current dir. What I will not see is any mp3s more then one level below the current dir.

I've tried working the -R option (recurse dirs), but haven't been able to make it work. That is:

ls -R /*.mp3 or ls -R */*.mp3 or ls -R *.mp3 doesn't seem to work.

Any thoughts?

Old 01-23-2004, 11:04 PM   #2
Registered: Dec 2003
Location: Little Rock, AR
Distribution: Fedora Core 2, AIX, HP-UX, Solaris, Whitebox
Posts: 193

Rep: Reputation: 31
Check the output again. This confused me at first, but it IS listing it recursively. The output doesn't include the full path in the name of the file. It's listing the path in the output just before the list of files in the directory that match your criteria.

In my home directory 'ls -R *mp3 gave back some output like:

02 Your Wall.mp3
04 Seven.mp3
05 Goodbye Again.mp3

Blue October- Calling You.mp3 Blue October - Razorblade.mp3
Blue October - Inner Glow.mp3 Blue October - Ugly side.mp3
Old 01-24-2004, 12:00 AM   #3
Registered: Aug 2003
Location: Ohio
Posts: 173

Rep: Reputation: 30
try typing in

ls /
this gives you a root directory output.

ls /user/
gives a user directory output.

ls /home/

gives the /home directory output.
Old 01-24-2004, 07:55 AM   #4
LQ Newbie
Registered: Sep 2003
Location: Lancaster, PA
Distribution: Redhat 9
Posts: 2

Original Poster
Rep: Reputation: 0
thanks for the help. using 'ls -R *mp3' does what I wanted. I was using 'ls -R *.mp3' and it was not working. I guess the '.' was tripping it up. Oddly enough using a command like 'ls */*.mp3' doesn't mind the '.', but then again that command won't recurse through all subdirs.

Old 01-24-2004, 09:13 AM   #5
Registered: May 2002
Location: Argentina
Distribution: Mandrake 9.2
Posts: 177

Rep: Reputation: 30
You can type
ls --help
and watch the all options that the commmand have
Old 01-24-2004, 09:25 AM   #6
Registered: Mar 2003
Location: NY
Distribution: Fedora Core 1,RH AS 2.1, RH AS 3.0, Mandrake 9.0
Posts: 33

Rep: Reputation: 15
I think the find command will help you more in this.

If you want to find all mp3 lets say under /home you can use

find /home -name *.mp3

Old 01-25-2004, 12:56 AM   #7
LQ Newbie
Registered: Jan 2004
Posts: 1

Rep: Reputation: 0
i use the find cmd as well and then pipe it to grep, ie:
find . | grep mp3
Old 01-25-2004, 01:57 AM   #8
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911
Why not
find -iname *.mp3



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shutdown Behavior rhb327 Slackware 19 11-07-2004 10:39 PM
Unexpected Behavior (passwd command) Penguin666 Linux - General 3 11-20-2003 12:34 AM
ls -l behavior vjl323 Mandriva 3 11-05-2003 08:30 AM
Strange Behavior andrewb758 Linux - Hardware 5 08-31-2003 03:42 PM
disgraceful behavior gui10 General 7 04-23-2002 09:46 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:14 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration