• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

inotifywait Command Examples in Linux

by admin

inotifywait is a command-line tool that uses the inotify Linux kernel subsystem to watch for changes to one or more files or directories. It can be used to monitor a file or directory for modifications, such as changes to the file’s contents or attributes, or for events such as a file being created or deleted.

When a change is detected, inotifywait will output the event and the file or directory that it occurred on to the console. The tool can also be used to execute a specific command when a change is detected.

inotifywait Command Examples

1. Watch a specific file for events, exiting after the first one:

# inotifywait /path/to/file

2. Continuously watch a specific file for events without exiting:

# inotifywait --monitor /path/to/file

3. Watch a directory recursively for events:

# inotifywait --monitor --recursive path/to/directory

4. Watch a directory for changes, excluding files, whose names match a regular expression:

# inotifywait --monitor --recursive --exclude "regular_expression" /path/to/directory

5. Watch a file for changes, exiting when no event occurs for 30 seconds:

# inotifywait --monitor --timeout 30 /path/to/file

6. Only watch a file for file modification events:

# inotifywait --event modify /path/to/file

7. Watch a file printing only events, and no status messages:

# inotifywait --quiet path/to/file

8. Run a command when a file is accessed:

# inotifywait --event access path/to/file && command

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to find the inode size of an ext2/ext3/ext4 filesystem?
  2. Time goes out of sync on a node running CentOS/RHEL 7
  3. ar – Create, modify, and extract from archives (.a, .so, .o)
  4. grub-install Command Options
  5. A File Is Claimed to Be Disappearing – How to monitor a file for deletion in Linux
  6. chsh: command not found
  7. CentOS / RHEL : How to mount filesystems using UUID
  8. apt-mark Command Examples in Linux
  9. Command ‘df -i’ Shows ‘Inode=0’ on BTRFS File System
  10. gem: Interact with the package manager for the Ruby programming language

You May Also Like

Primary Sidebar

Recent Posts

  • gixy Command Examples
  • gitsome Command Examples
  • gitmoji Command Examples
  • gitlint Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright