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:
- How to Use disown Command in Linux
- Remove Currently Running Jobs Using disown Command
- Remove the Specific Job Using disown Command
- Remove All Jobs Using disown Command
- Remove the Last Job Using disown Command
- Prevent Jobs after Log Out Using disown Command
- Conclusion
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:
Note: /dev/null is the temporary null file that stores the ping data in it.
Now, we have two jobs in a running state, confirm their statuses through the following command:
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:
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:
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:
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:
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:
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.