Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeat command automatically in Linux

Tags:

linux

bash

ubuntu

Is it possible in Linux command line to have a command repeat every n seconds?

Say, I have an import running, and I am doing

ls -l 

to check if the file size is increasing. I would like to have a command to have this repeat automatically.

like image 734
Marty Wallace Avatar asked Nov 27 '12 21:11

Marty Wallace


People also ask

How do I run a repeatedly command in Linux?

Run a Command Multiple Times in Linux using a while Loop Another important part of the while loop is i=$(($i+1)) or (($i++)) which increments the counter until the test condition becomes false.

How do you repeat a command in Unix?

There's a built-in Unix command repeat whose first argument is the number of times to repeat a command, where the command (with any arguments) is specified by the remaining arguments to repeat . For example, % repeat 100 echo "I will not automate this punishment." will echo the given string 100 times and then stop.


1 Answers

Watch every 5 seconds ...

watch -n 5 ls -l

If you wish to have visual confirmation of changes, append --differences prior to the ls command.

According to the OSX man page, there's also

The --cumulative option makes highlighting "sticky", presenting a running display of all positions that have ever changed. The -t or --no-title option turns off the header showing the interval, command, and current time at the top of the display, as well as the following blank line.

Linux/Unix man page can be found here

like image 160
Rawkode Avatar answered Sep 17 '22 17:09

Rawkode