In our past article, you have found out about how to begin or run command in background. Presently this article will help you to how to move running command in background. This is useful, in the event that you have begun a command on terminal and that command is taking to much time. Presently you need to move that in background, so you can proceed with other tasks.
Move Running Command in Background
Suppose you are making a zip file of large number of files, You run the commmand from terminal, But after some time you need to start some other task and running process is taking longer time. So you can do like below:
# zip -r backup.zip public_html
Now press CTRL + Z to pause the current running command on terminal.
CTRL + Z
+ Stopped zip -r backup.zip public_html
Now type bg command on terminal, This will start last paused command in background by appending & in command.
+ zip -r backup.zip public_html &
List Running Commands in Background
To list all jobs running in background use jobs command. It will show all running commands with their job id.
+ Running zip -r backup.zip public_html &
Move Background Commands to Terminal
Now, If you need to any background jobs to move to foreground. Use fg command with job id and this will move background command with that job id to terminal. Job id can be found using jobs command as showing in above example.
# fg 1