• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Move Running Command to Background in Linux

Written by Rahul, Updated on February 22, 2016

In our previous tutorial, you have learned about how to start or run command in background. Now this tutorial will help you to how to move running command in background. This is helpful, if you have started a command on terminal and that command is taking to much time. Now you want to move that in background, so that you can continue with other tasks.

Move Running Command in Background

For example you are taking a backup of large number of files, You have started command on terminal, But after mid of this task you think that this is taking longer time and you have some other pending tasks like below:

[email protected]:~$ tar czf log-backup.tar.gz /var/log

Now press CTRL + Z to pause the current running command on terminal.

CTRL + Z

[1]+  Stopped          tar czf log-backup.tar.gz /var/log

Now type bg command on terminal, This will start last paused command in background by appending & in command.

[email protected]:~$ bg

[1]+ tar czf log-backup.tar.gz /var/log &

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.

[email protected]:~$ jobs

[1]+  Running                 tar czf log-backup.tar.gz /var/log &

Move Background Commands to Foreground (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.

[email protected]:~$ fg 1

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

2 Comments

  1. Avatar Surya Reply
    June 14, 2019 at 8:20 am

    Well explained. Thank you.

  2. Avatar Kiba Dempsey Reply
    May 12, 2019 at 5:11 pm

    Nice.

    I had a critical headlessVM running that died at the worst time. I spent ages getting it working, but in my investigation, I moved the VM process from being spin up default in the background to the foreground to get extra diag info. Now it’s working I can’t risk shutting it down to dig deeper for about a week until it’s not in use. If my putty window drops I’m might be back in the same situ. The above saved my bacon. Thanks.

Leave a Reply Cancel reply

Popular Posts

  • How To Install Python 3.9 on Ubuntu 20.04 5
  • How To Install Python 3.9 on Ubuntu 18.04 0
  • How to Use AppImage on Linux (Beginner Guide) 2
  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy