#!/bin/bash # Write a script that will count the number of files in each of your subdirectories. # ------------------------------------------------------------------------- # Copyright (c) 2001 nixCraft project <http://cyberciti.biz/fb/> # This script is licensed under GNU GPL version 2.0 or above # ------------------------------------------------------------------------- # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. # ------------------------------------------------------------------------- START=$HOME # change your directory to command line if passed # otherwise use home directory [ $# -eq 1 ] && START=$1 || : if [ ! -d $START ] then echo "$START not a directory!" exit 1 fi # use find command to get all subdirs name in DIRS variable DIRS=$(find "$START" -type d) # loop thought each dir to get the number of files in each of subdir for d in $DIRS do [ "$d" != "." -a "$d" != ".." ] && echo "$d dirctory has $(ls -l $d | wc -l) files" || : done
4000+ howtos and counting! If you enjoyed this article, join 45000+ others and get free email updates!
Click here to subscribe via email.
Click here to subscribe via email.
- Download Script
- Email this to a friend
- Rss Feed
- Last Updated: 09/19/08






