Search code examples
bashwatchlswc

The watch command does not work with a command using a pipe


Very simple/quick question, why this command does not work?

watch ls *.log | wc -l

or

watch -d ls *.log | wc -l

I'm attempting to watch an update of the total amount of files in the current directory.


Solution

  • If you want to pipe a command and watch that, add quotes around it as such:

    watch "ls | wc -l"