LinuxCommandLibrary

gvfs-monitor-file

Monitor a file for changes

SYNOPSIS

gvfs-monitor-file [OPTION...] LOCATION...

PARAMETERS

-h, --help
    Show basic help options

--help-all
    Show all help options

--help-gvfs
    Show GVFS-specific help

--version
    Print version and exit

-v, --verbose
    Enable verbose/debug output

-n, --nofilemon
    Disable GFileMonitor; use polling fallback

DESCRIPTION

gvfs-monitor-file is a utility from the gvfs-utils package in GNOME's Virtual File System (GVFS) ecosystem. It watches specified files (via GVFS URIs or local paths) for changes such as modifications, deletions, creations (if recreated), or attribute updates. Upon detecting an event, it outputs a single line to stdout in the format: EVENT_TYPE URI, where event types include CHANGED, DELETED, CREATED, and ATTRIB.

This tool uses GIO's GFileMonitor API, enabling seamless monitoring across local filesystems and GVFS backends like smb://, ftp://, trash://, or recent:// without special permissions. It's ideal for shell scripting, daemons, or automation reacting to file events in desktop environments like GNOME.

Monitoring starts immediately and runs indefinitely until interrupted (e.g., Ctrl+C). Multiple files can be monitored simultaneously. Verbose mode aids debugging backend issues, while --nofilemon falls back to polling for backends lacking native monitors. It requires a running gvfsd daemon for full functionality.

CAVEATS

Requires running gvfsd daemon. Limited to file monitoring (use gvfs-monitor-dir for directories). Some GVFS backends may poll inefficiently or miss events. Not suitable for high-frequency monitoring.

EVENT OUTPUT EXAMPLE

CHANGED file:///home/user/doc.txt
ATTRIB file:///home/user/doc.txt
DELETED file:///home/user/doc.txt

USAGE EXAMPLE

gvfs-monitor-file ~/important.txt — Watches file, prints events on change.
gvfs-monitor-file -v trash:///file.txt — Verbose monitor of trash URI.

HISTORY

Introduced in GVFS 0.1.3 (2008) alongside GIO file monitoring APIs to support cross-backend file watching in GNOME. Evolved with GLib/GIO updates for better remote FS support.

SEE ALSO

Copied to clipboard