Skip to content
28 January 2011 / avoulk

Watching directories for file changes with inotifywait.

I was in need for a quick script that would monitor a certain directory for file changes.

The case is a quite easy one: I own a directory where the results of certain simulations are stored. As I wanted to know when a new simulation begins and what is the number of simulations already finished, I decided to take a look at the way I could handle with this new challenge.

The first attempt was an easy one, using time delays and commands like $ ls -1 | wc -l and of course $ sleep. However this was quite annoying as i kept getting multiple indications for the same number of simulation results. Then, I discovered a package named inotify-tools. inotify-tools contains several useful commands that take advantage of the inotify events dispatched by the respective Linux kernel subsystem. I am not going to list the uses of the commands contained in inotify-tools, further information can be found in the project homepage, here. Be sure to check it, it is really valuable 🙂

Anyway, a simple yet effective command that eventually did the trick for me was $ inotifywait. As stated in its manpage:

inotifywait efficiently waits for changes to files using Linux’s inotify(7) interface. It is suitable for waiting for changes to files from shell scripts. It can either exit once an event occurs, or continually execute and output events as they occur.

So, inotifywait watches a directory for file changes and fires certain events, such as create, delete, modify etc. PLUS it is really simple to use. In my case, where i wanted to check for file changes in directory $WATCH_PATH and display the file count, each time a file is created, it was fairly simple 🙂






declare -i WATCH_COUNT;

declare -i COUNTER;

inotifywait -m –format ‘%f’ -e create $WATCH_PATH | while read FILE



if [ $WATCH_COUNT -eq 1 ]; then

echo -ne “Files found: “



if [ $COUNTER -eq 1 ]; then

echo -ne “\nStarted new simulation. \nFiles found: “


echo -n “$COUNTER “;


The switches in inotifywait are quite standard and are well described in the manpage. -m states that the command should monitor the directory indefinitely (telling it not to exit upon a single file change), –format ‘%f’ describes the formatting of the output (piped to the while statement) while -e create indicates that only CREATE events are monitored. The output is the one attached 🙂

Powered by Blogilo

18 January 2011 / avoulk


They say falling for a sin is a sign of weakness. Is it though? I see people waving white flags and others embracing them with joy.

I honestly don’t know what’s worse: sins we love or stuff we love to hate? Or is the latter a sin, too?

I often see people acting weird, as if generally admitted moral code or common sense are absent from their motives. But how is common sense established? Are sins just a religion-sourced know-what-to-avoid guidelines? Well, i am not sure. In times of great sorrow and crisis only few have the clarity of mind to challenge the crowds. Hell, i am part of the rest. And I definitely hate to love to hate. Is that a sin, too?

14 January 2011 / avoulk

Temporary mania: Light

I will stay with you tonight
Keep you safe from all you hide
All we were was just a dream…

Here our past is left behind
Now our paths are intertwined
All we were and all we’ll be…

(Now…) I’ll keep it all alight
When there’s nobody out there
When you’re far beyond the waves
I will bring you air…

I will stay with you tonight
Keep you safe from all you hide
All we were was just a dream…

A thousand lives we’ve lived til now
All this beauty that surrounds
All we were and all we seek…

(Now…) I’ll keep it all alight
Make sure you find the way
When you feel you are nowhere…

I’ll keep it all alight
When there’s nobody out there
When you’re far beyond the waves
I will bring you air…

I will bring you air…

11 January 2011 / avoulk


Where pain and suffering meet, you are there.

In my joy, you are present. My present.

Let me breathe you, let me sing your scent.

Let me be your eyes, to see me through you,

just for a second, no more.

And when the eternal night falls,

let me be your perpetuous nightingale,

your shining star, just like you.


It’s a cosy feeling to have someone to hold when you ‘re cold.

And if you feel you have noone? What happens next?

Either way,  you can always live on the moon..

29 December 2010 / avoulk


Happy new Year to everybody!

Hopefully 2011 will be better than the nasty 2010! 🙂

Powered by Blogilo

19 December 2010 / avoulk

New Quote

Chase life and let it roll!


PS: Taken from a Volbeat song (The human Instrument)

Powered by Blogilo

18 December 2010 / avoulk

Great Programming Font: envy-code-r

Few days ago, i discovered a font perfectly suitable for my monospaced-font-demanding apps like konsole, kate, kile etc.

Its name: envy-code-r

You can grab it here. An Archlinux package is available in the AUR, here.

Powered by Blogilo