Moving a command or script that you're running on the command line to the background so that you can start another job and managing backgrounded processes requires only a handful of commands. When working on the Linux command line, you can start a task, move it to the background, and, when you’re ready to reverse the process, bring it back to the foreground. When you run a command or script in the foreground, it occupies your time on the command line – until it’s finished. When you need to do something else while still allowing that first task to complete, you can move it to the background where it will continue processing and spend your time working on something else. The easiest way to do this is by typing ^z (hold the Ctrl key and press “z”) after starting the process. This stops the process. Then type “bg” to move it to the background. The jobs command will show you that it is still running. $ mytask ^Z [2]+ Stopped mytask $ bg $ jobs [1]+ Running mytask & Now let’s look at an easy way to try this out. First, put a simple script like this together and make it ready to run. #!/bin/bash while true do date > x sleep 120 done That script will put the current date and time to a file called “x” every 2 minutes. Since it overwrites the file once it exists, it doesn’t use up additional disk space. Next, start the script. If the script is called “loop”, you would use a command like this: $ loop Next, use the ^z trick to stop the process after starting it. $ loop ^Z [1]+ Stopped loop Then use the bg command to move it to the background where it will continue running. $ bg [1]+ loop & This particular script will run forever or until you kill it, log out or reboot the system. You can terminate it by using the kill command followed by the background process id. $ kill %1 [1]+ Terminated loop $ jobs The jobs command with no output tells you that no more backgrounded processes are still running. Start a process in the background You can also put a process in the background when you first start it by following the command or script name with an & character. In the example below, I’m running a second looping script in the background and then using the jobs command to view all backgrounded processes. $ loop2 & [2] 4651 $ jobs [1]- Running loop & [2]+ Running loop2 & Notice the – and + signs in the output above output following the [1] and [2] process numbers. These will only appear for the two most recently backgounded tasks. These jobs can be referred to as %1, %2 or simply as – and + when you want to move them to the foreground with a command like fg +. Bringing backgrounded tasks back to the foreground If you have processes that are running in the background, you use the fg command to bring them back to the foreground. To move the loop task to the foreground, you could use either of the commands shown below. $ fg %1 $ fg – You can use the jobs command to show the backgrounded tasks. $ jobs [2]+ Running loop2 & Notice that only one of the two tasks remained in the background after the first was brought back to the foreground with the fg – command. Wrap-up Depending on what you’re working on, moving tasks to the background so that you can take control of the command line for more pressing tasks while allowing the backgrounded tasks to continue running can save time can be a smart move. Related content how-to How to find files on Linux There are many options you can use to find files on Linux, including searching by file name (or partial name), age, owner, group, size, type and inode number. By Sandra Henry Stocker Jun 24, 2024 8 mins Linux opinion Linux in your car: Red Hat’s milestone collaboration with exida With contributions from Red Hat and critical collaborators, the safety and security of automotive vehicles has reached a new level of reliability. By Sandra Henry Stocker Jun 17, 2024 5 mins Linux how-to How to print from the Linux command line: double-sided, landscape and more There's a lot more to printing from the Linux command line than the lp command. Check out some of the many available options. By Sandra Henry Stocker Jun 11, 2024 6 mins Linux how-to Converting between uppercase and lowercase on the Linux command line Converting text between uppercase and lowercase can be very tedious, especially when you want to avoid inadvertent misspellings. Fortunately, Linux provides a handful of commands that can make the job very easy. By Sandra Henry Stocker Jun 07, 2024 5 mins Linux PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe