mkunit path
Create a systemd path unit to trigger on file/directory changes.
mkunit path <name> [flags]
Description
The path command creates a .path unit file for monitoring
filesystem paths. When the watched path changes, systemd triggers the associated service.
This is useful for processing uploaded files, reloading configurations, or reacting
to log file changes.
Arguments
| Argument | Description |
|---|---|
<name> |
Name of the path unit (without .path extension) |
Flags
| Flag | Description | Default |
|---|---|---|
--unit <name> |
Service unit to trigger | <name>.service |
--path-exists <path> |
Trigger when path exists | — |
--path-exists-glob <glob> |
Trigger when glob matches any files | — |
--path-changed <path> |
Trigger when path is modified | — |
--path-modified <path> |
Trigger when path is written to | — |
--directory-not-empty <path> |
Trigger when directory has files | — |
--make-directory |
Create the watched directory if missing | false |
--directory-mode <mode> |
Mode for created directory (octal) | 0755 |
--description <text> |
Human-readable description | Auto-generated |
--system |
Create a system path unit | false |
--install |
Install the unit file | false |
--start |
Start the path watcher | false |
--enable |
Enable on boot | false |
--dry-run |
Print without writing | false |
Watch Types
| Type | Triggers When |
|---|---|
PathExists |
File or directory exists (checked on timer start and periodically) |
PathExistsGlob |
Any files match the glob pattern |
PathChanged |
File is renamed, deleted, or attributes change |
PathModified |
File content is written (close after write) |
DirectoryNotEmpty |
Directory contains at least one file |
Examples
Watch for new files in upload directory
mkunit path upload-processor \
--directory-not-empty /var/uploads \
--make-directory \
--install --start
Trigger processing when config changes
mkunit path config-reload \
--path-modified /etc/myapp/config.yaml \
--unit myapp-reload.service \
--install --enable
React to log file modifications
mkunit path log-analyzer \
--path-modified /var/log/myapp/access.log \
--install --start
Watch for lock file (simple semaphore)
mkunit path trigger-job \
--path-exists /tmp/run-job.trigger \
--install --enable
Process matching files with glob
mkunit path csv-importer \
--path-exists-glob "/var/data/incoming/*.csv" \
--install --start
Watch multiple conditions
# First create the path unit
mkunit path multi-watch \
--path-modified /etc/myapp/config.yaml \
--directory-not-empty /var/spool/myapp \
--install
Note
Path units use inotify under the hood. For high-volume directories, consider using a timer instead to batch process files periodically.
See Also
- mkunit service - Create the triggered service
- mkunit timer - For scheduled (vs event-based) triggers
- mkunit status - Check path unit status