Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a folder tree structure like


and I am only after all files inside weekly and daily directories. Is there a way I can achieve that using shell command or commands?

I tried ls -R */weekly/ from the top folder but it didn't work.

share|improve this question
up vote 5 down vote accepted

Well, from the top (the parent of the arndell, claremont, and monte) directories you could type:

ls */*/{weekly,daily}

Which expands to:

ls */*/weekly */*/daily

Which would show you the contents of all the weekly and daily directories.

share|improve this answer
I need to use a string to refine the search and actually do one ls for weekly and another for daily so ls */*/weekly/*NODE* is the winner. Thank you – Radek Apr 3 '12 at 0:26
Out of my curiosity.... is there any way how to do ls without knowing the tree structure? Only knowing that let's say I want to list all weekly directories? – Radek Apr 3 '12 at 0:28
You could find . -name weekly | xargs ls – larsks Apr 3 '12 at 0:45
It works but it's much much very much slower. It took 30mins compare to a sec using ls. – Radek Apr 3 '12 at 1:07
The find command walks the directory tree. There are a number of things you could do to speed it up, including restricting the search to directories, limiting the maximum depth of the search, etc. – larsks Apr 3 '12 at 1:46

if you have bash you could use:

shopt -s globstar
for f in  **/{daily,weekly}/*; do
  whatever $f
share|improve this answer
I need to use one command as I am going to call it from php. I like that in your solution I don't need to know the tree structure. It will list weekly and daily. I haven't try it though. – Radek Apr 3 '12 at 0:29
as one command just to : bash -c 'shopt -s globstar; ls -1 **/{daily,weekly}/*' – glenn jackman Apr 4 '12 at 20:00
find . '(' -path '*/weekly/*' -o -path '*/daily/*' ')' -type f
share|improve this answer
I have to compare the processing speed of ls and find. – Radek Apr 5 '12 at 3:25
The answers using ls aren't really using ls. They're using shell expansion, so it depends on the speed of your shell. – Mikel Apr 5 '12 at 6:24
ls */*/weekly isn't using ls? – Radek Apr 5 '12 at 6:44
ls is doing the printing, but the shell is doing the finding. – Mikel Apr 5 '12 at 14:02
Quick time execution comparison of ls (5sec) and find (14 mins)... does that mean that shell is faster than find? – Radek Apr 10 '12 at 0:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.