Linux’s inotifywait command watches a directory for filesystem events. It can show when a file is created or moved into a folder, but a creation event does not mean the file has finished uploading.
Install and try the watcher
On Debian or Ubuntu:
sudo apt update
sudo apt install inotify-toolsUse your distribution’s supported package source elsewhere. Replace the example path with a directory you can read:
inotifywait -m -e create,moved_to,close_write --format '%e %w%f' /var/www/uploads-m keeps watching, create detects new entries, moved_to detects entries moved into the folder and close_write detects a file being closed after writing. One upload may produce several events. Press Ctrl+C to stop.
Add -r to watch subdirectories, allowing for the system’s watch limit and recursive-watch race conditions.
Keep a log
Redirect the output to a writable file outside the watched directory to avoid the log generating its own events:
inotifywait -m -e create,moved_to,close_write --format '%e %w%f' /var/www/uploads >> "$HOME/file-monitor.log" 2>&1This output is intended for inspection. Filenames can contain spaces or newlines, so do not turn each text line into an unchecked command or automatically process a file before confirming it is ready.
Run a persistent systemd watcher
For ongoing operation, an administrator can create /etc/systemd/system/file-monitor.service with these settings. Replace username, the directory and the executable path with verified values:
[Unit]
Description=Directory event monitor
[Service]
Type=simple
User=username
ExecStart=/usr/bin/inotifywait -m -e create,moved_to,close_write --format "%%e %%w%%f" /var/www/uploads
Restart=on-failure
RestartSec=5
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.targetThe doubled percent signs pass literal formatting tokens through systemd. The service account needs permission to watch the directory.
sudo systemctl daemon-reload
sudo systemctl enable --now file-monitor.service
sudo systemctl status file-monitor.service
sudo journalctl -u file-monitor.serviceUnderstand the limits
Events can be lost during downtime or queue overflow, and remote changes on some network filesystems are not reported. Use periodic reconciliation and application-level readiness checks if every file must be processed. A watcher is not a complete audit trail or a backup.