Monday, 15 October 2018

Repeat command automatically in Linux

Is it possible in linux command line to have a command repeat every n seconds.
For example, say I have an import running and i am doing
ls -l
to check the file size is increasing. I would like to have a command to have this automatically repeat

Answer:
If the command contains some special characters such as pipes and quotes, the command needs to be padded with quotes. For example, to repeat ls -l | grep "txt", the watch command should be:
watch -n 5 'ls -l | grep "txt"'


0 comments:

Post a Comment