This question already has an answer here:
I have a script that I use to set up "slave" machines in my multi-computer setup. There's one master that kind of controls the rest. The script needs to check if everything is ready, including whether some things have been fooled with. Right now I'm interested in best practice for testing if a directory is empty. If not it could be very full so I don't want something that can take a long time just to say "no".
My first thought is something like
if [ $(ls | head -2 | wc -l) -lt 1 ] ; then echo empty;
else echo fooled with; fi
but while the head command kills the ls fairly quickly (broken pipe) it still strikes me as tortured in cases where there are a lot of entries. Is there a better way?
Aucun commentaire:
Enregistrer un commentaire