Shell – list folders and their content

lsshell-script

I'd need a file reporting for each folder the content and the name of the folder itself.
If I do

ls -l * 

I have (this is just a subset of hundreds of folders)

secondary_endosymbiont_of_Heteropsylla_cubana_Thao2000_uid172738:
total 1232
-rw-r--r--  1 FrancescaDeFilippis  staff  627404  2 Nov  2012 NC_018420.ffn

syncytium_symbiont_of_Diaphorina_citri_uid213384:
total 896
-rw-r--r--  1 FrancescaDeFilippis  staff  446934 29 Lug  2013 NC_021885.ffn
-rw-r--r--  1 FrancescaDeFilippis  staff    5594 29 Lug  2013 NC_021886.ffn

uncultured_Sulfuricurvum_RIFRC_1_uid193658:
total 4840
-rw-r--r--  1 FrancescaDeFilippis  staff     1002  9 Apr  2013 NC_020503.ffn
-rw-r--r--  1 FrancescaDeFilippis  staff  2470123  9 Apr  2013 NC_020505.ffn

uncultured_Termite_group_1_bacterium_phylotype_Rs_D17_uid59059:
total 3392
-rw-r--r--  1 FrancescaDeFilippis  staff  851852  1 Mar  2013 NC_020419.ffn
-rw-r--r--  1 FrancescaDeFilippis  staff    6684  1 Mar  2013 NC_020420.ffn
-rw-r--r--  1 FrancescaDeFilippis  staff    3869  1 Mar  2013 NC_020421.ffn
-rw-r--r--  1 FrancescaDeFilippis  staff    2394  1 Mar  2013 NC_020422.ffn
-rw-r--r--  1 FrancescaDeFilippis  staff  848808 28 Ago  2012 NS_000191.ffn
-rw-r--r--  1 FrancescaDeFilippis  staff    6684 28 Ago  2012 NS_000192.ffn
-rw-r--r--  1 FrancescaDeFilippis  staff    3869 28 Ago  2012 NS_000193.ffn
-rw-r--r--  1 FrancescaDeFilippis  staff    2394 28 Ago  2012 NS_000194.ffn

I'd like to get something like this:

secondary_endosymbiont_of_Heteropsylla_cubana_Thao2000_uid172738:  NC_018420.ffn

syncytium_symbiont_of_Diaphorina_citri_uid213384:  NC_021885.ffn
syncytium_symbiont_of_Diaphorina_citri_uid213384:  NC_021886.ffn

and so on, so I'd need the name of the folder repeated for each file.

How could I get this?

Best Answer

This works in any POSIX shell:

find <directory> -type f -exec sh -c '
  for f do
    printf "%s: %s\n" "${f%/*}" "${f##*/}"
  done' sh {} +

This command executes on every file (file name stored in the variable f) and displays the directory (${f%/*}), a colon and the file name (${f##*/}').

Related Question