---
title: "Linux中后台执行命令"
author: "samjavaeye"
date: "2011-12-28T16:08:59Z"
tags: []
categories: ["操作系统"]
slug: "linux"
draft: false
lastmod: "2011-12-28T16:08:59Z"
id: 1328711
url: "https://samjavaeye.iteye.com/blog/1328711"
---

使用nohup命令可以使进程在退出账户或关闭终端后仍然继续执行，一般形式为：

***nohup command &***

        其中command为要执行的命令，例如：

   *nohup tar –xvf xxx.tar &*

        缺省情况下，该作业的所有输出都被重定向到一个名为nohup.out的文件中，除非另行指定了输出文件，例如：

        *nohup tar –xvf xxx.tar &gt; tar\_xxx.log 2&gt;&1 &*

        在上面的例子中，输出被重定向到了tar\_xxx.log文件中。

另外，如果使用缺省的***nohup command &***形式，需要按Ctrl+C之后才能关闭终端。