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 Aug 18 '13 at 20:41
  • Why is the command ls necessary?
    – Viesturs
    May 9 '20 at 17:00
  • @Viesturs It is just a placeholder for anything you want to execute with the lock.
    – ceving
    May 12 '20 at 16:47

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.