How to Use Disown Command in Linux – phoenixNAP

Introduction

The disown command is a part of the Unix ksh, bash, and zsh shells and is used to remove jobs from the current shell. Like cd or pwd, it is a built-in shell command and does not require root privileges.

This tutorial will cover different ways you can use the disown command on Linux to terminate jobs and keep them running after logging out.

Prerequisites

  • A system running Linux
  • Command Line Access / Terminal Window

Repudiation

Command Syntax

The basic syntax for the dispudor command is: disown

[options] jobID1 jobID2 … jobIDN

Using

the disown command on Linux

The disown command on Linux is used to remove jobs from the job table. You can also use it to keep a longer, more complex job running in the background even after logging off the server.

Review

jobs in progress

To use the disown command, you must first have jobs running on your Linux system.

In this example, we’ll start a couple of jobs running in the background

: cat /dev/random > /dev/null & ping google.com > /dev/null &

Use the jobs command to list all current jobs: jobs

-l

You should get output similar to the one seen below:

The ping command is denoted by ‘+’, which means it is a currently active job.

The cat command is denoted by ‘-‘, which means that it will become the active job if the ping command ends

.

Remove all jobs To delete all jobs from the job table, use the following command: disown -a

Remove

specific

jobs

If you want to remove a specific job from the job

table, use

the

disown command with the appropriate job ID. The job ID appears in parentheses

in the job table: In our example, if we want to remove the ping command, we need to use the disown command in job 2: repudiation %2

Using the disown command without any options or job IDs deletes the last job from the job table:

Remove currently

running

jobs To delete only the jobs that

are currently running, use the following command: disown -r

In our example, the command mentioned above clears the job table, as both jobs are currently running in the background: Keep jobs

running after logging off

Once you exit your system’s terminal, All running jobs are automatically completed. To avoid this, use the disown command with the -h:disown -h

jobID option

In our example, we want to keep the cat command running in the background. To prevent it from terminating on exit, use the following command

: disown -h %1 After using the disown command, close the terminal: exit

Any job in which you have used the disown -h command will continue to run

.

Conclusion

After following this tutorial, you learned how to use the disown command to remove jobs from the job list or keep them running even after you close the terminal window

.

For more Linux commands, take a look at our Linux Command Cheat Sheet.

Contact US