Take the 2-minute tour ×

inotifywait -qme CREATE --format '%w%f' /tmp/watch | while read f; 
ln -s "$f" /tmp/other/; 

I've found this script looking for something that react to filesystem event doing a specific job. The script works perfectly what i don't understand is the meaning of while read f;

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

It's capturing the output of your inotifywait command and parsing it line by line, assigning each line to f in the while statement.

That particular inotifywait command continuously monitors the /tmp/watch directory and outputs the full path name when one is created.

The while loop, in turn, processes each each of those file names and creates a symbolic link to it in the /tmp/other/ directory.

Here's an example script showing the while read in action:

pax$ ( echo 1 ; echo 2 ; echo 3 4 ) | while read f
pax> do
pax> echo "[$f]"
pax> done
[3 4]
share|improve this answer
thanks very much,an example is always the best thing... I've no reputation yet so no vote I'm sorry –  elio.d Mar 19 '11 at 15:16
add comment

Your Answer


