Explorar o código

added countfiles in directory util

George Jones hai 5 meses
pai
achega
a4a34eb94c
Modificáronse 1 ficheiros con 17 adicións e 0 borrados
  1. 17 0
      bin/count-files-in-directories.sh

+ 17 - 0
bin/count-files-in-directories.sh

@@ -0,0 +1,17 @@
+#!/bin/bash
+# Count the files each directory in a heirarchy
+#
+# USAGE: count-files-in-directory.sh [DIR [FILETYPE]]
+
+STARTDIR=${1:-.}
+FILETYPE=${2:-""}
+
+# Use find to get all directories in the directory structure
+find $STARTDIR -type d -name \*${FILETYPE} | while read -r dir
+do
+ # Use wc to count the number of files in each directory
+ num_files=$(find "$dir" -type f | wc -l)
+
+ # Print the directory and the number of files
+ echo "$num_files $dir"
+done | sort -n -r