# ls <dir> | wc -l
Example:
# ls / | wc -l 23 # ls /home/tor/*.txt | wc -1 2
You can assign this to a variable in bash and use it in if statments:
SOMEVAR=`ls <dir> | wc -l`
And now you can test SOMEVAR for 0 (no files) or files.
# ls <dir> | wc -l
# ls / | wc -l 23 # ls /home/tor/*.txt | wc -1 2
SOMEVAR=`ls <dir> | wc -l`
|
|
|
0 members, 2 guests, 0 anonymous users