Linux Commands

How to Use disown Command in Linux

Creating a Job isn’t a big deal but the ability to control when to stop and resume the process again according to need. When working with any operating system, multiple jobs are in an active state, while some are running and some are in a waiting state.

The disown command-line utility is one of the commands that help to manage the jobs, remove them from the current shell, and keep them active even when the terminal session is logged out.

To use the disown command the following syntax would be followed:

disown [optons] [job_ID1] [job_ID2] …… [job_IDN]

How to Use disown Command in Linux

For a better understanding first, we need to create jobs using the terminal. Execute the following commands to create a job in Ubuntu 20.04:

ping linuxhint.com > /dev/null &

Note: /dev/null is the temporary null file that stores the ping data in it.

gnome-calculator &

Now, we have two jobs in a running state, confirm their statuses through the following command:

jobs -l

Let’s practically run some disown commands.

1. Remove Currently Running Jobs Using disown Command

Execute the mentioned command to delete the currently running jobs from the background:

disown -r

In the above example, we have checked the currently running jobs using the -l command and then deleted them through the disown command.

2. Remove the Specific Job Using disown Command

If you want to remove the specific job from the background, you can do so by mentioning its job ID with disown command. Check the below-mentioned image to learn about job ID:

These numbers in brackets are the IDs of running jobs.

To remove any of these jobs, we need to run the disown command with that relevant job ID; like:

disown %1

As you can see, the above command has removed the ping job from the table and

3. Remove All Jobs Using disown Command

With the help of the disown command tool, the user can remove all the running jobs from the background. For this, the -a parameter would be used with the disown command:

disown -a

4. Remove the Last Job Using disown Command

If you run the disown command without passing any argument or job ID, this will delete the last job from the table:

disown

In the above output, the disown command has removed the gnome-calculator job. To confirm, we have executed the job -l command, and the result is shown above.

5. Prevent Jobs after Log Out Using disown Command

The disown command is also used to keep the jobs running in the background even when the user is logged out from the terminal.

Type the following disown command with the job ID you want to keep running with the -h parameter:

disown -h %1

Conclusion

Shell scripting languages allow the user to automate the operating system tasks. This prevents time as well as increases the efficiency of the system. The disown shell command tool is also used for this purpose, it helps to remove the tasks from the background and also keeps running them even when the user is logged out. This guide has mentioned some of the important working commands of the disown shell tool that include, deleting the specific job or all jobs from the job table, deleting currently running jobs, and preventing the job and keeping it running when the shell terminal is closed.

About the author

Syeda Wardah Batool

I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.