I want to keep an eye on a file as it is created. So I used this command
ls -hal ./file |awk '{print $5}'
which gives the size of the file I am looking for. I use awk
because I don't need other stuff, just the file size.
But I'm unable to use this with watch
command, because if I try
watch ls -hal ./file |awk '{print $5}'
then watch only accepts ls -hal ./file
and then pipes it to awk
, giving no output.
If I try
watch "ls -hal ./file |awk '{print $5}'"
then it gets weird showing wrong command and whole output.
Every 2.0s: ls -hal ./file |awk '{print }' Sun Jul 20 15:52:18 2014
-rw-rw---- 1 aditya aditya 1.7K Jul 20 15:52 ./file
You can see there is no $5
in the awk command.
Further quoting creates various similar errors.
So what is the right way to quote this command?
One option would be to escape the
$
in yourawk
expressionAlternatively, you could avoid the issue altogether by using
stat
instead of parsing the output ofls
Use following command :
And if you want to highlight difference than,
This will give work as you want!