-1

I want to check if a file is changed or no using stat linux command.

linux@server:~/$ stat test.txt File: `test.txt' Size: 23
Blocks: 8 IO Block: 4096 regular file Device: 802h/2050d Inode: 4887765 Links: 1

Access: (0644/-rw-r--r--) Uid: ( 1000/ anis) Gid: ( 1000/
anis)

Access: 2014-07-07 16:34:42.476315578 +0200

Modify: 2014-07-08 12:54:15.756553868 +0200

Change: 2014-07-08 12:54:15.756553868 +0200

we can see the time of change. the purpose is to use this change time to check if the file is modified or no

linux@server:~/anis$ stat test.txt |grep Change
Change: 2014-07-08 12:54:15.756553868 +0200

linux@server:~/anis$ stat test.txt |grep Change

Change: 2014-07-08 15:14:03.107977776 +0200

so how made script running in infinite loop to check if time is changed ?

Anis_Stack
  • 3,306
  • 4
  • 30
  • 53

2 Answers2

2

Don't use stat. To simply block until the file is modified, use inotifywait:

inotifywait -e modify test.txt

You may want to wait for a less restrictive set of changes:

inotifywait test.txt

will block until any event happens on the file. Also, consider the sanity of your users:

inotifywait -qq test.txt
William Pursell
  • 204,365
  • 48
  • 270
  • 300
0

If you are using OpenWrt Buildroot, then you can select and install inotify-tools during the configuration (make menuconfig, or what ever configuration ui you are using).

After that you can use inotifywait just as William Pursell suggested.

The package inotify-tools was added by with this patch in 2011.

Rikard Söderström
  • 1,000
  • 6
  • 14