Operations 7 min read

How to Run Linux Commands in the Background: 6 Practical Techniques

Learn six effective ways to execute Linux commands in the background—including using &, bg, nohup, output redirection, disown, and tmux—so you can keep working in the same terminal or close it without stopping long‑running tasks.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Run Linux Commands in the Background: 6 Practical Techniques

Running commands in the background is essential for efficient Linux system administration, allowing you to continue using the terminal or even close it while tasks keep running.

1. Append an ampersand (&) to the command

Placing & after a command starts it in the background immediately. Example: gedit & This frees the shell for other work, though any output to stdout or stderr will still appear in the foreground.

2. Use bg to resume a stopped job

Press Ctrl+Z to suspend a running foreground job, then type bg to continue it in the background. List jobs with jobs and bring a job back with fg %jobnumber. To resume a specific paused job, use bg %jobnumber.

3. Use nohup to ignore hang‑up signals

The nohup command runs a process immune to the SIGHUP signal, so it keeps running after you log out. Example: nohup sudo nmap -sS --top-ports=15 192.168.150.1/24 Output is written to nohup.out in the current directory or $HOME if not redirected.

4. Redirect output and run in background

You can combine redirection with & to run a command silently. Example: ping -c5 8.8.8.8 >linuxmi.com.log 2>&1 & This sends both stdout and stderr to linuxmi.com.log. Use /dev/null to discard output.

5. Use disown to detach from the shell

After starting a background job with &, run disown to remove it from the shell’s job table, preventing it from being terminated when the shell exits. Example: gedit & disown This behaves similarly to nohup regarding shell logout.

6. Use tmux to run commands in a detached session

tmux

is a terminal multiplexer that can start a detached session to run commands independently of any open terminal. Example: tmux new -d 'ping -c 10 8.8.8.8 > www.linuxmi.com.log' The command runs in its own shell and continues after you detach or close the original terminal.

Conclusion

Background execution tools like &, bg, nohup, redirection, disown, and tmux each have strengths and limitations; choose the appropriate method based on whether you need to preserve output, survive logout, or manage multiple jobs. Also monitor for zombie processes that can degrade system performance.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxCommand-linebackground processes
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.