1

I have following directories:

Sample1 
Sample2        

Each of it contains multiple subfolders like

Sample1/R1/
Sample1/R2/
Sample1/R3/
Sample2/R1/
Sample2/R2/
Sample2/R3/

Which further contains the files:

Sample1/R1/file1
Sample1/R2/file1
Sample1/R3/file1
Sample2/R1/file1
Sample2/R2/file1
Sample2/R3/file1

I want a list like:

Sample1/R1/file1 Sample1/R2/file1 Sample1/R3/file1
Sample2/R1/file1 Sample2/R2/file1 Sample2/R3/file1

I tried 'ls;, 'find' but no luck.

Please can someone help?

May thanks in advance.

  • 1
    ls */*/* ? (star slash star slash star) ls Sample?/R?/file1 ? – Archemar Jan 15 '16 at 11:10
  • 1
    ls */*/* | xargs -n3 ? – 123 Jan 15 '16 at 11:29
2
find . -type f | awk -F / '{a[$2]=a[$2] " " $0}; END {for(b in a){print a[b]}}'
  • @StéphaneChazelas, thank you for POSIXification. – JJoao Jan 15 '16 at 15:15
1

With zsh:

for d (Sample*) print -r $d/*/*

Or to print all non-directory files:

for d (Sample*) print -r $d/**/*(^/)

(note that if there are file names that contain newline characters, that won't be on one line).

Or with any Bourne-like shell:

for d in Sample*; do
  find "$d" ! -type d | paste -sd ' ' -
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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