मुझे यह प्रश्न afte मिला मैं पहले से ही अपनी खुद की इसी तरह की लिपि लग रहा था। ऐसा लगता है कि यह आपकी परिस्थितियों में फिट है और बहुत लचीला है इसलिए मैंने सोचा कि मैं इसे एक उत्तर के रूप में जोड़ूंगा।
लाभ:
- को
.
, 1 प्रथम स्तर उपनिर्देशिका, आदि के लिए के लिए किसी भी गहराई (0 बांटा जा सकता है)
- प्रिंट सुंदर उत्पादन
- कोई पाश, और केवल एक
find
आदेश है, इसलिए यह थोड़ा बड़े निर्देशिकाओं पर तेज है
- अभी भी कस्टम फ़िल्टर जोड़ने के लिए (maxdepth यह गैर पुनरावर्ती बनाने के लिए नियोजित किया जा सकता, फ़ाइल नाम पैटर्न)
कच्चे कोड:
find -P . -type f | rev | cut -d/ -f2- | rev | \
cut -d/ -f1-2 | cut -d/ -f2- | sort | uniq -c
एक समारोह में लपेटा और विस्तार से बताया:
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
}
इस तरह उत्पादन का उत्पादन:
$ fc 0
1668 .
$ fC# depth of 1 is default
6 .
3 .ssh
11 Desktop
44 Downloads
1054 Music
550 Pictures
संख्या पहले यह
sort
को पहुंचाया जा सकता है के साथ बेशक
: बैश एक वास्तविक भाषा है:
$ fc | sort
3 .ssh
6 .
11 Desktop
44 Downloads
550 Pictures
1054 Music
व्यक्ति जो पास मतदान करने के लिए
। – Bernard