Menu

Move Running Command to Background in Linux

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:


root@hackthesec:~$ tar czf random-file.tar.gz /var/log
Now press CTRL + Z to pause the current running command on terminal.
 
CTRL + Z

[1]+  Stopped          tar czf random-file.tar.gz /var/log
Now type bg command on terminal, This will start last paused command in background by appending & in command.
root@hackthesec:~$ bg

[1]+ tar czf random-file.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.
root@hackthesec:~$ jobs

[1]+  Running                 tar czf random-file.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.
root@hackthesec:~$ fg 1
www.hackthesec.co.in
About US
HackTheSec-Twitter

About Author:


I am a Linux Administrator and Security Expert with this site i can help lot's of people about linux knowladge and as per security expert i also intersted about hacking related news.TwitterFacebook

Next
Newer Post
Previous
Older Post

0 comments:

Post a Comment

 
Top