Suppose that at the moment some command is already running in the console. It takes a long time. I would like to execute one or more commands after this one is completed. How to do it?

I know that you can Ctrl + Z and bg , but this is not quite that. It is necessary not to send a command to the background, namely, to wait for its completion.

  • You can create a sh-script, especially if the commands are executed frequently. - Dmitriy
  • @ Dmitry, yes, it is possible, but the one-time situation is interesting to me. That is, the command is already running, you need to add new ones. - Nick Volynkin

1 answer 1

use not bg ( background ), but fg ( foreground ), after which add the necessary command (s):

 $ date; sleep 10 Fri Oct 2 10:45:04 MSK 2015 ^Z [1]+ Stopped sleep 10 $ fg; date sleep 10 Fri Oct 2 10:45:14 MSK 2015 

fg and the following command can be associated with conditions, for example: && or || .