LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 06-16-2009, 11:37 AM   #1
limdel
Member
 
Registered: May 2009
Location: Ho Chi Minh City, Vietnam
Distribution: CentOS 6.4, FEDORA 18 x64, Linux Mint 15 x64
Posts: 57

Rep: Reputation: 15
search for specific file extension


Well, i ashamed to ask such question. but i did look at tutorial and wiki, but i'm unable to list all mp3 file i have on a folder and his sub-folder.
i tried
Code:
ls -R *.mp3
but it's return me
Code:
ls: cannot access *.mp3: No such file or directory
but when i tried
Code:
ls -R *
it list me all files, my mp3 files and of course the others.

What did i do wrong ?

Thanks in advance
 
Old 06-16-2009, 11:44 AM   #2
noctilucent
Member
 
Registered: Jun 2009
Distribution: slackware
Posts: 123

Rep: Reputation: 25
1. -R will not help you
2. Does the case-ing differ? i.e. perhaps the files are .MP3 rather than .mp3 [or .mP3 or .Mp3]
 
Old 06-16-2009, 11:47 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
I guess the files are not in the current directory, since you're using -R. You can do either
Code:
ls -R | grep .mp3$
or
Code:
find . -name \*.mp3
 
Old 06-16-2009, 12:13 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
ls -laR | awk 'BEGIN{
 q="\047"
}
/total|^\.$|^\.\.$/{next}
/^\// && f{f=0}
/^\/|^[.]/{        
    f=1
    gsub(/:$/,"")
    old=$0          
    next
}
f && $1 ~/^-/{
   $1=$2=$3=$4=$6=$7=$8=""     
   m=split($0,s , " ")   
   if ( s[2] ~ /[mM][pP][3]/){
    fold = old "/" s[2]
    print fold 
   }   
}'
 
Old 06-17-2009, 09:06 AM   #5
limdel
Member
 
Registered: May 2009
Location: Ho Chi Minh City, Vietnam
Distribution: CentOS 6.4, FEDORA 18 x64, Linux Mint 15 x64
Posts: 57

Original Poster
Rep: Reputation: 15
@noctilucent
-1- Yes i need the -R option since i'm looking for these file in all sub-folder
-2- I checked already, all are lower case

Thanks

@noctilucent
Your solutions (both) are exactly what i was looking for.
Thanks for your kind and fast help.

@ghostdog74
I'm not(yet) an expert on shell(is it ?) so i would not comment you code.
Thanks anyway.
 
  


Reply


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
Linux file extension vs Dos file Extension? manaa Linux - Newbie 6 02-12-2009 05:19 PM
How to use grep to search for a specific variable.. memo007 Linux - Software 4 02-24-2007 06:52 PM
Search logfiles for specific words kinetik Linux - General 2 03-29-2006 08:04 PM
Searching a specific directory for a specific extension? RoaCh Of DisCor Linux - Newbie 3 08-13-2005 04:28 PM
The LinuxQuestions search extension for Mozilla/Firebird/Firefox is now available. Travis86 General 1 03-24-2004 07:24 PM


All times are GMT -5. The time now is 08:54 PM.

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