Ho trovato questa domanda afte Ho già capito la mia sceneggiatura simile. Sembra adattarsi alle tue condizioni ed è molto flessibile, quindi ho pensato di aggiungerlo come risposta.
Vantaggi:
- possono essere raggruppati per qualsiasi profondità (0 per
.
, 1 per sottodirectory di primo livello, etc.)
- stampe abbastanza uscita
- alcun loop, e solo uno
find
di comando, quindi è un po 'più veloce su grandi directory
- può ancora essere sintonizzati per aggiungere filtri personalizzati (maxdepth per renderlo non ricorsiva, il nome del file modello)
codice prima:
find -P . -type f | rev | cut -d/ -f2- | rev | \
cut -d/ -f1-2 | cut -d/ -f2- | sort | uniq -c
avvolto in una funzione e ha spiegato:
fc() {
# Usage: fc [depth >= 0, default 1]
# 1. List all files, not following symlinks.
# (Add filters like -maxdepth 1 or -iname='*.jpg' here.)
# 2. Cut off filenames in bulk. Reverse and chop to the
# first/(remove filename). Reverse back.
# 3. Cut everything after the specified depth, so that each line
# contains only the relevant directory path
# 4. Cut off the preceeding '.' unless that's all there is.
# 5. Sort and group to unique lines with count.
find -P . -type f \
| rev | cut -d/ -f2- | rev \
| cut -d/ -f1-$((${1:-1}+1)) \
| cut -d/ -f2- \
| sort | uniq -c
}
produce un output simile a questo:
$ fc 0
1668 .
$ fC# depth of 1 is default
6 .
3 .ssh
11 Desktop
44 Downloads
1054 Music
550 Pictures
Naturalmente con il primo numero che può essere convogliato a sort
:
$ fc | sort
3 .ssh
6 .
11 Desktop
44 Downloads
550 Pictures
1054 Music
Per la persona che ha votato vicino: bash è un linguaggio vero e proprio . – Bernard