Skip to content

Instantly share code, notes, and snippets.

@StefanHeng
Last active April 24, 2022 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StefanHeng/7a08209349a78b5372dcfac49a3271c4 to your computer and use it in GitHub Desktop.
Save StefanHeng/7a08209349a78b5372dcfac49a3271c4 to your computer and use it in GitHub Desktop.
Bash script for counting the number of files in each subdirectory
ls_fl_count () {
max_len=-1
for key in *; do
len=${#key}
((len > max_len)) && max_len=$len
done
pad=$((max_len + 5))
fmt="%-${pad}s %s\n"
for i in *; do
printf "$fmt" "$i" "$(find "$i" | wc -l)";
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment