Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

One option would be to escape the $ in your awk expression

watch "ls -hal ./file |awk '{print \$5}'"

Alternatively, you could avoid the issue altogether by using stat instead of parsing the output of ls

watch stat -c '%s' ./file
share|improve this answer
@RegisteredUser I recommend to accept this (steeldriver's) answer instead of mine because it gives right solution for awk and also sort syntax by stat! – Pandya Jul 20 '14 at 11:02

Use following command :

watch 'ls -hal ./file|cut -d " " -f 5'

And if you want to highlight difference than,

watch -d 'ls -hal ./file|cut -d " " -f 5'

This will give work as you want!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.