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.
- A system running Linux
- Command Line Access / Terminal Window
The basic syntax for the dispudor command is: disown
[options] jobID1 jobID2 … jobIDN
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.
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
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
If you want to remove a specific job from the job
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:
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
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
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.