Master nohup: Run Linux Commands in Background and Capture Output
This guide explains how the nohup command lets you run programs that ignore hang‑up signals, redirects their output to nohup.out or a specified file, and keeps them running after you close the terminal, with practical syntax and examples.
The nohup command runs a program while ignoring hang‑up signals, so the program continues after the terminal closes. Its output is not shown on the terminal; instead it is appended to nohup.out in the current directory, or to $HOME/nohup.out if the former is unwritable.
Command Syntax
nohup Command [Arg …] [&]Parameter Details
Command: the command to execute. Arg: optional arguments, such as output file specifications. &: runs the command in the background, allowing the terminal to exit while the process keeps running.
Redirecting Output and Errors
To send both standard output and standard error to a file (e.g., a.log) while running in the background, use: nohup command > a.log 2>&1 & The redirection 2>&1 means: redirect file descriptor 2 (stderr) to the same destination as file descriptor 1 (stdout), which has already been redirected to a.log.
0 – stdin (standard input)
1 – stdout (standard output)
2 – stderr (standard error)
Background File Download Example
nohup wget https://repo.huaweicloud.com/java/jdk/8u172-b11/jdk-8u172-linux-x64.tar.gz &
# view background jobs
jobs
[1]+ Running nohup wget https://repo.huaweicloud.com/java/jdk/8u172-b11/jdk-8u172-linux-x64.tar.gz &During the download, output is written to nohup.out. You can monitor it in real time with tail -f nohup.out.
Running a Spring Boot Application in Background
nohup java -jar rumenz.jar &Executing a Bash Command and Capturing Output
nohup bash -c 'cal && ls' > output.txtThis runs the calendar and directory listing, redirects both stdout and stderr to output.txt, and keeps the process alive after the terminal is closed.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
