Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Create a bash program that counts the files of a directory without counting directories
- # Creates a file listing
- # Separate file listing output from total number of blocks
- # Get the second column from the file listing
- LISTING=`ls -l | grep -v ^t | awk '{print $2}'`
- # Make the second column into a string array
- strarray=($LISTING)
- # Make a variable for the file count
- COUNT=0
- # Make a variable for the directory count
- DIRCOUNT=0
- for i in "${strarray[@]}"
- do
- #echo $i
- if ((i < 2)); then
- COUNT=$((COUNT + 1))
- else
- DIRCOUNT=$((DIRCOUNT + 1))
- fi
- done
- echo "Count of Directories ->" $DIRCOUNT
- echo "Count of Files -> " $COUNT
Advertisement
Add Comment
Please, Sign In to add comment