daily pastebin goal
8%
SHARE
TWEET

countFiles

a guest Jun 14th, 2017 7 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # Create a bash program that counts the files of a directory without counting directories
  4.  
  5. # Creates a file listing
  6. # Separate file listing output from total number of blocks
  7. # Get the second column from the file listing
  8. LISTING=`ls -l | grep -v ^t | awk '{print $2}'`
  9.  
  10. # Make the second column into a string array
  11. strarray=($LISTING)
  12. # Make a variable for the file count
  13. COUNT=0
  14. # Make a variable for the directory count
  15. DIRCOUNT=0
  16.  
  17. for i in "${strarray[@]}"
  18. do
  19.         #echo $i
  20.         if ((i < 2)); then
  21.                 COUNT=$((COUNT + 1))
  22.         else
  23.                 DIRCOUNT=$((DIRCOUNT + 1))
  24.         fi
  25. done
  26.  
  27. echo "Count of Directories ->" $DIRCOUNT
  28. echo "Count of Files -> " $COUNT
RAW Paste Data
Top