LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   search for specific file extension (https://www.linuxquestions.org/questions/linux-newbie-8/search-for-specific-file-extension-733370/)

limdel 06-16-2009 10:37 AM

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

noctilucent 06-16-2009 10:44 AM

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]

colucix 06-16-2009 10:47 AM

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

ghostdog74 06-16-2009 11:13 AM

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
  } 
}'


limdel 06-17-2009 08:06 AM

@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.


All times are GMT -5. The time now is 03:56 PM.