I try to put a lock on a file like this:

flock -e myfile.lock

The result is:

flock: bad number: myfile.lock

Doesn't matter whether file exist or not, or whether I'm root. I even tried chmod a+rwx myfile. Still get the same error. I tried the same not on my machine but on Debian and I get the same error...


The command is missing. Try:

flock -e myfile.lock ls

The number is the file descriptor of the usage alternativ:

  flock -e 200
) 200>myfile.lock

See the man page.

  • thanks, the number part I still dont get, but the missing command tip worked here: terminal 1 flock -x ./test.txt sleep 10, and after at terminal 2 flock -x ./test.txt ls – Aquarius Power Aug 18 '13 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.