{
    "content": [
        {
            "type": "text",
            "text": "# flock (perldoc)\n\n## TLDR\n\n> Manage file locks from shell scripts.\n\n- Run a command with a file lock as soon as the lock is available:\n  `flock {{path/to/lock.lock}} {{command}}`\n- Run a command with a file lock, or exit if the lock is currently being held (with exit code 1):\n  `flock {{-n|--nonblock}} {{path/to/lock.lock}} {{command}}`\n- Run a command with a file lock, or exit with a specific error code if the lock is currently being held:\n  `flock {{-n|--nonblock}} {{-E|--conflict-exit-code}} {{123}} {{path/to/lock.lock}} {{command}}`\n- Run a command with a file lock, waiting up to 10 seconds for the lock to be available before giving up:\n  `flock {{-w|--timeout}} 10 {{path/to/lock.lock}} {{command}}`\n- Backup a bunch of files, waiting for the previous `tar` command to finish if it's still running elsewhere and holding the same lock file (can be used in a `cron` job that runs often):\n  `flock {{path/to/backup.lock}} {{tar -cvf path/to/backup.tar path/to/data/}}`\n\n*Source: tldr-pages*\n\n---\n\n## Full Content\n\n"
        }
    ],
    "structuredContent": {
        "command": "flock",
        "section": "-f",
        "mode": "perldoc",
        "summary": null,
        "synopsis": null,
        "tldr_summary": "Manage file locks from shell scripts.",
        "tldr_examples": [
            {
                "description": "Run a command with a file lock as soon as the lock is available",
                "command": "flock {{path/to/lock.lock}} {{command}}"
            },
            {
                "description": "Run a command with a file lock, or exit if the lock is currently being held (with exit code 1)",
                "command": "flock {{-n|--nonblock}} {{path/to/lock.lock}} {{command}}"
            },
            {
                "description": "Run a command with a file lock, or exit with a specific error code if the lock is currently being held",
                "command": "flock {{-n|--nonblock}} {{-E|--conflict-exit-code}} {{123}} {{path/to/lock.lock}} {{command}}"
            },
            {
                "description": "Run a command with a file lock, waiting up to 10 seconds for the lock to be available before giving up",
                "command": "flock {{-w|--timeout}} 10 {{path/to/lock.lock}} {{command}}"
            },
            {
                "description": "Backup a bunch of files, waiting for the previous `tar` command to finish if it's still running elsewhere and holding the same lock file (can be used in a `cron` job that runs often)",
                "command": "flock {{path/to/backup.lock}} {{tar -cvf path/to/backup.tar path/to/data/}}"
            }
        ],
        "tldr_source": "official",
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [],
        "sections": []
    }
}