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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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 encrypt traffic between CUPS servers
  2. bmon Command Examples in Linux
  3. ifconfig: command not found
  4. maim Command Examples in Linux
  5. Understanding the rc Scripts in Linux
  6. efibootmgr: command not found
  7. How to Find Number of CPU Sockets on a CentOS/RHEL System
  8. flameshot Command Examples in Linux
  9. macchanger Command Examples in Linux
  10. Understanding /etc/hosts file in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright