Skip to main content
How To

Run Ubuntu Commands in the Background

This quick tutorial shows how to run a new command in the background or send a running command to the background in Ubuntu Linux.

Sagar Sharma

In times when you are in hurry or want to get control of the terminal screen, running time-taking commands in the background can be a lifesaver for you.

To run the command in the background, all you have to do is append the & to the command while executing:

command &

And it will show the PID of the process running in the background.

But what about sending the already running process to the background and bringing it back to the foreground?

Well, that's what I'll be covering in this tutorial.

Run commands in the background

To run a command in the background, all you have to do is append the & to the command while executing.

For reference, here, I used the gzip command in the background:

run ubuntu commands in the background

And as you can see, it brought the PID (33572) of the gzip process in the background.

Move an already running process to background

You may find yourself in a situation where you want to shift the ongoing process to the background.

And to do so, all you have to do is follow the given 2 steps:

Step 1: Stop the process using Ctrl + Z

Using the Ctrl + z shortcut, it will stop the process and return you to the current shell.

Don't worry, in the next step, I will show you how you can resume the process in the background.

For example, here, I used the Ctrl +z over the ongoing gzip process to stop the process:

stop the on going process in ubuntu terminal

Step 2: Send the process in the background

To resume the stopped process and keep it running in the background, all you have to do is use the bg command:

bg
resume the stopped process in background

To verify whether the process is running in the background, you can also use the jobs command:

jobs
check running processes in background in Ubuntu terminal

And there you have it!

Did you know that you can use an ISO file as a local repository?

The major advantage of using a local repository is you can apply patches offline. Which also enables you to install packages without an internet connection.

This can be a lifesaver for Enterprise servers where you deal with critical situations on the daily basis.

And for that, we have a detailed guide on how you can use the Rocky Linux ISO as a local repository:

Use Rocky Linux ISO as a Local Repository
In DIY mood? See how I experimented to use the Rocky Linux ISO as a local repository.

I hope you will find this guide helpful.

And if you have any queries, feel free to ask in the comments.