Run command after 1 hour in Linux

前端 未结 3 535
没有蜡笔的小新
没有蜡笔的小新 2021-01-07 18:51

I just want to echo my string after 1 hour. I saw at command but it can run script at specific time (HH:MM). I want my echo<

相关标签:
3条回答
  • 2021-01-07 19:24

    It is sleep 60m && ls

    0 讨论(0)
  • 2021-01-07 19:44

    You can also use at (at is very good at understanding times, see this page for a lot of good examples).

    > at now + 1 hour
    at> echo 'my string' > /dev/stdout
    at> ^D
    

    After you input the at time specification it will take you to the at prompt (your OS my or my not show the at> prompt, OSX doesn't for example). You then type whatever commands you want executed and press Control-D to exit the at prompt. One caveat: at will run your commands and mail you the result. So if you want your output to appear on your terminal, you should direct your output to the appropriate device: /dev/stdout and /dev/tty usually work.

    0 讨论(0)
  • 2021-01-07 19:44

    According to the sleep man page, sleep will

    Pause for NUMBER seconds. SUFFIX may be 's' for seconds (the default), 'm' for minutes, 'h' for hours or 'd' for days. Unlike most implementations that require NUMBER be an integer, here NUMBER may be an arbitrary floating point number. Given two or more arguments, pause for the amount of time specified by the sum of their values.

    So you can either use sleep 1h, sleep 60m or sleep 3600s or just sleep 3600 to sleep for 1 hour and then execute your command ls after that. For example sleep 1h && echo "hello world".

    0 讨论(0)
提交回复
热议问题