When you execute a command in a Linux system it starts a process and when you exit from the terminal it gets automatically terminated. In some situations, you may want to keep running a process even after exiting from the terminal. So how will you do that?
Well, we can use nohup (No Hang Up) command which keeps processes running even after you close your terminal. It prevents the processes from receiving the SIGHUP signal which is the signal sent to a process when its controlling terminal is closed.
In this article, I will discuss the usage of nohup command along with some examples.
Syntax of nohup command in Linux
The syntax of how to use nohup command in Linux is given below.
nohup command [ argument.. ]
Now let’s see some usage of this command.
Usage of nohup command in Linux
The following examples show the usage of nohup command in Linux.
Check the version of nohup command
Use the given command to see the version of nohup installed in your system.
This will display the output as given in the image below.
Starting a process using nohup command
When you run a command using nohup command this will start a process that will run even after you exit from the terminal.
For example –
Let’s say we have a sample file called
testfile.sh to execute this use –
nohup bash testfile.sh
This will execute the given file and append the output to
Now you can see the output which is saved in
nohup.out file by using the given command –
If you want to redirect the output to a specific file then use –
nohup bash testfile.sh > output.txt
Start a process in the background
You can run a command in the background by appending the
& symbol at the end of the command.
For example –
nohup bash testfile.sh &
If you want to bring the process to the foreground then use
You can see help on nohup command by using –
I hope now you understand the usage of nohup command in Linux. Now if you have a query then write us in the comments below.