I'm trying to find the number of dirs and files in a given dir. I'm running my bash script like this:
ARCHIVE=/path/to/archive ./myScript
in my script I am doing this:
#find the number of non-empty directories in the given dir
dirs=$(find $ARCHIVE -mindepth 1 -maxdepth 1 -not -empty -type d | wc -l)
#find the number of files in the given dir
msgs=$(find $ARCHIVE -type f | wc -l)
echo "Number of directories: $dirs"
echo "Total number of messages: $msgs"
This works great when I am running the script on a subset of the data I'm looking at, which is located in a dir at the same level as the script. However, the actual data is in someone else's directory and when I run it with the ARCHIVE variable set to that location, both values return as 0. I have a similar script that I use as well, and the find command there does not work on the second directory either. Strangely enough, I use some egrep commands and they work just fine for both.
Why can I not use find in this manner?
bash -x
so it shows you debugging information and variable expansion?$ARCHIVE
with double quotes, like this:find "$ARCHIVE" -min...
. Also make sure you have permission to access the other person's data.ARCHIVE
variable is specifying two directories for find to look in. One is/path/to/archive
, the other is./myScript
. Sofind
will look in those two directories. Is this what you intended?