Question: How do I kill all the jobs running in the background in Linux command line?
Answer: If you want to kill all the background jobs in Linux, you can use this:
jobs -p | xargs kill
Explanation: Here’s the quick explanation of the above command:
- jobs: the command to display all the jobs started in the current shell
- -p: this option of jobs command will display only the process id of the running job. This will display one job id in each line
- | : pipe the output
- xargs: executes commands from the standard input, in this case, the output of jobs -p command
- kill: kills the process based on its id
So, the jobs -p outputs job ids to the xargs command that executes the kill command on each id.
I hope this quick tip helped you to kill all background jobs in Linux. Stay tuned for more Linux quick tips.