Just started a scripting class and could use some help. I am writing a script to inspect the file names of every file and directory in a given directory and accumulate a count of Every file, subdirectory, symlink, old files, graphics files, tmp files, exe files, and total byte count of each file within that directory.
The output needs to be formatted in this way:
- Directories n,nnn,nnn
- Files n,nnn,nnn
- etc...
When I run my script, it doesn't seem to count anything because all count items return 0. I am also having issues with formatting the numbers to have comma's. $1 is the directory the user will enter for searching when they run the script ie: ./srpt /etc. To run the search I am using the find command with printf to format the output and piping the output to wc to count the number of lines. I assume this would give me the number of files granted the file names are just one line. There are probably a billion ways to do this and this way might not be the most elegant, but I would appreciate anyone's input.
if [ -d "$1" ]; then
directories=$(find "$1" -type d -printf "%'d" | wc -l)
files=$(find "$1" -type f -printf "%'d" | wc -l)
sym=$(find "$1" -type l -printf "%'d" | wc -l)
etc...
#Printing the output to the terminal
echo "Directories" $directories
echo "Files" $files
echo "Sym links" $sym
exit 0
else
echo "[ERROR]: need path to perform search"
exit 1
fi
My output:
Directories 0
Files 0
Sym Links 0