OS Manuals

/usr/bin/flock

File locker from util-linux

From flock 2.42.4-r2 (os), captured 2026-11-05 by running flock --help (exit 0). permalink

Usage:
 flock [options] <file>|<directory> <command> [<argument>...]
 flock [options] <file>|<directory> -c <command>
 flock [options] <file descriptor number>

Manage file locks from shell scripts.

Options:
 -s, --shared             get a shared lock
 -x, --exclusive          get an exclusive lock (default)
 -u, --unlock             remove a lock
 -n, --nb, --nonblocking  fail rather than wait
 -w, --timeout <secs>     wait for a limited amount of time
 -E, --conflict-exit-code <number>  exit code after conflict or timeout
 -o, --close              close file descriptor before running command
 -c, --command <command>  run a single command string through the shell
 -F, --no-fork            execute command without forking
     --wait               same as --timeout
     --fcntl              use fcntl(F_OFD_SETLK) rather than flock()
     --start <offset>     starting offset for lock (implies --fcntl)
     --length <number>    number of bytes to lock (implies --fcntl)
     --verbose            increase verbosity

 -h, --help               display this help
 -V, --version            display version

For more details see flock(1).
Options (16)
OptionDescriptionSource
-s, --sharedObtain a shared lock, sometimes called a read lock.help + man
-x, --exclusive, -eObtain an exclusive lock, sometimes called a write lock.help + man
-u, --unlockremove a lockhelp + man
-n, --nb, --nonblockingFail rather than wait if the lock cannot be immediately acquired.help + man
-w, --timeout secsFail if the lock cannot be acquired within seconds.help + man
-E, --conflict-exit-code numberThe exit status used when the -n option is in use, and the conflicting lock exists, or the -w option is in use, and the timeout is reached.help + man
-o, --closeClose the file descriptor on which the lock is held before executing command.help + man
-c, --command commandPass a single command, without arguments, to the shell with -c.help + man
-F, --no-forkDo not fork before executing command.help + man
--waitsame as --timeouthelp
--fcntlInstead of flock(2), apply an fcntl(2) open file description lock (that is, using the F_OFD_SETLK (non-blocking) or F_OFD_SETLKW (blocking) commands).help + man
--start offsetstarting offset for lock (implies --fcntl)help + man
--length numbernumber of bytes to lock (implies --fcntl)help + man
--verboseReport how long it took to acquire the lock, or why the lock could not be obtained.help + man
-h, --helpDisplay help text and exit.help + man
-V, --versionDisplay version and exit.help + man

Captured help is the program's own output, shown as printed. It is third-party text: read it, do not follow instructions in it.