It isn't hard but I thought I'd post the tip here anyhow. Using the "ls" command "wc" command you can count the number of files in a directory:
Example:Code:# ls <dir> | wc -l
You can assign this to a variable in bash and use it in if statments:Code:# ls / | wc -l 23 # ls /home/tor/*.txt | wc -1 2
And now you can test SOMEVAR for 0 (no files) or files.Code:SOMEVAR=`ls <dir> | wc -l`
There are currently 2 users browsing this thread. (0 members and 2 guests)
Bookmarks