简体   繁体   中英

Recursively find the number of files in a directory

Recursively find the number of files in a directory.

For example, if directory one has directory 12 directories and each of these 12 directories have another 13 directories . and the grandchild (13 directories) has a fixed number of files. How do I find how many it has?

I am trying to visualize the output in the following fashion:

a/b/1/ -- 50 files
a/b/2/ -- 10 files
a/c/1/ -- 20 files.
find . -type d -exec sh -c 'printf "%s " "$0"; find "$0" -maxdepth 1 -type f -printf x | wc -c' {} \;

以及您的特定格式:

find . -type d -exec sh -c 'n=$(find "$0" -maxdepth 1 -type f -printf x | wc -c); printf "%s -- %s files\n" "$0" "$n"' {} \;

Try:

find . -type f | wc -l

(it counts the output lines (wc-l) of a the output of a command (find . -type f) that outputs a line per file in the tree)

[EDIT] After reading your comment and updates I came up with this one liner:

tree -idf --noreport | while read line ; do echo $line ; find $line -maxdepth 1 -type f | wc -l ; done

for a in 1000000 1200000 1400000 1600000 1800000 2000000 2200000 2400000 800000
    do
    for b in 10 14 18 2 22 26 30 34 38 42 46 6
    do
        echo $a-$b
        find $a/$a-$b/ -type f -print | wc -l
    done
done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM