{"id":18605,"date":"2022-09-17T05:23:00","date_gmt":"2022-09-17T05:23:00","guid":{"rendered":"https:\/\/linuxways.net\/?p=18605"},"modified":"2022-09-20T12:55:48","modified_gmt":"2022-09-20T12:55:48","slug":"linux-nohup-command","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/linux-commands\/linux-nohup-command\/","title":{"rendered":"Linux NOHUP Command"},"content":{"rendered":"<p>NOHUP stands for No Hang-up, a command in Linux that simply ignores the Hang-up signal. It means that running a command while using the NOHUP command will keep it running even if the user logs out of the system. However, once this command finishes its execution, its output will be saved in a file named \u201cnohup.out\u201d instead of appearing on the terminal. In this guide, we will learn a little more about the NOHUP command in Linux.<\/p>\n<h2><strong>NOHUP Command in Linux<\/strong><\/h2>\n<p>The usage of the NOHUP command in Linux can quickly be learned by looking at its help manual. To access that, you will have to execute the following command:<\/p>\n<pre>\r\n$ nohup --help\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"328\" height=\"24\" class=\"wp-image-18623\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-1.png 328w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-1-300x22.png 300w\" sizes=\"auto, (max-width: 328px) 100vw, 328px\" \/><\/strong><\/p>\n<p>You can see the help manual for this command in the following image:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"632\" height=\"385\" class=\"wp-image-18624\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-2.png 632w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-2-300x183.png 300w\" sizes=\"auto, (max-width: 632px) 100vw, 632px\" \/><\/p>\n<p>However, to use this command effectively, you can go through the following examples:<\/p>\n<h2><strong>Example 1: Run a Command With NOHUP<\/strong><\/h2>\n<p>In this example, we will use the NOHUP command in Linux to run a bash script. The exact command for this purpose is as follows:<\/p>\n<pre>\r\n$ nohup bash Space.sh\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"383\" height=\"29\" class=\"wp-image-18625\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-3.png 383w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-3-300x23.png 300w\" sizes=\"auto, (max-width: 383px) 100vw, 383px\" \/><\/strong><\/p>\n<p>Here, \u201cSpace.sh\u201d is the name of the bash script file that needs to be executed.<\/p>\n<p>Since we have used the NOHUP command for executing this script, its output will not appear on the terminal. Instead, it will be redirected to a newly created file named \u201cnohup.out\u201d, as shown in the following image:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"482\" height=\"63\" class=\"wp-image-18626\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-4.png 482w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-4-300x39.png 300w\" sizes=\"auto, (max-width: 482px) 100vw, 482px\" \/><\/p>\n<h2><strong>Example 2: Redirect the Output of a Command to a Different File With NOHUP<\/strong><\/h2>\n<p>In the previous example, we did not provide a name for the file in which the output of our command is supposed to be redirected. However, in this example, we will be using the NOHUP command for redirecting the output of another command to a specifically mentioned file, as you can witness from the following command:<\/p>\n<pre>\r\n$ nohup bash Space.sh &gt; newfile.txt\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"502\" height=\"25\" class=\"wp-image-18627\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-5.png 502w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-5-300x15.png 300w\" sizes=\"auto, (max-width: 502px) 100vw, 502px\" \/><\/strong><\/p>\n<p>You can have any name of your choice for the output file. However, in this particular case, the output of our bash script will be redirected to the \u201cnewfile.txt\u201d file and not to the \u201cnohup.out\u201d file, as shown in the following image:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"505\" height=\"61\" class=\"wp-image-18628\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-6.png 505w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-6-300x36.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-6-501x61.png 501w\" sizes=\"auto, (max-width: 505px) 100vw, 505px\" \/><\/p>\n<p>To confirm if the output of the bash script has been redirected to the said output file or not, we will display the contents of this file with the following command:<\/p>\n<pre>\r\n$ cat newfile.txt\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"351\" height=\"24\" class=\"wp-image-18629\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-7.png 351w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-7-300x21.png 300w\" sizes=\"auto, (max-width: 351px) 100vw, 351px\" \/><\/strong><\/p>\n<p>The contents of this file shown in the following image confirm that the output of our bash script has successfully been redirected to this file.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"477\" height=\"134\" class=\"wp-image-18630\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-8.png 477w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-8-300x84.png 300w\" sizes=\"auto, (max-width: 477px) 100vw, 477px\" \/><\/p>\n<h2><strong>Example 3: Run a Command in the Background With NOHUP<\/strong><\/h2>\n<p>Now, we will use the NOHUP command to run another command in the background in Linux. It means that even after closing the terminal, that command will keep running in the background until we explicitly kill it. To understand this, you can consider the following command:<\/p>\n<pre>\r\n$ sudo nohup ping &amp;\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"378\" height=\"23\" class=\"wp-image-18631\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-9.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-9.png 378w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-9-300x18.png 300w\" sizes=\"auto, (max-width: 378px) 100vw, 378px\" \/><\/strong><\/p>\n<p>The previous command will start executing the ping command in the background, as shown in the following image:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"389\" height=\"61\" class=\"wp-image-18632\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-10.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-10.png 389w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-10-300x47.png 300w\" sizes=\"auto, (max-width: 389px) 100vw, 389px\" \/><\/p>\n<p>Now, even if you close your terminal, this command will keep running in the background. Therefore, whenever you wish to terminate its execution, you will have to kill it explicitly with the following command:<\/p>\n<pre>\r\n$ kill -9 2700\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"330\" height=\"25\" class=\"wp-image-18633\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-11.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-11.png 330w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/09\/word-image-18605-11-300x23.png 300w\" sizes=\"auto, (max-width: 330px) 100vw, 330px\" \/><\/strong><\/p>\n<p>Here, \u201c2700\u201d refers to the process ID (PID) of the command to be killed that appeared earlier due to executing the NOHUP command.<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>This article introduced you to the NOHUP command in Linux. This command is handy when a user cannot stay logged in all the time but still wants their work done in their absence. With the help of a few relevant examples, we have tried to convey the basic gist of this Linux command. By now, you will have an excellent idea of how the NOHUP command works in Linux.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>A step-by-step guide on the NOHUP command in Linux so that users can complete and have their work done even if they are not logged on all the time.<\/p>","protected":false},"author":3,"featured_media":18687,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049],"tags":[],"class_list":["post-18605","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/18605","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=18605"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/18605\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/18687"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=18605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=18605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=18605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}