Managing Linux Jobs from Bash - A Practical Guide
When working in a Linux terminal, especially over SSH or in long-running workflows, managing jobs effectively can save you time, prevent frustration, and keep your system organized. Bash provides built-in job control features that let you start, pause, resume, and move processes between the foreground and background.
1. What is a “job” in Bash?
A job is a process (or pipeline of processes) started from your current shell session. Bash tracks these jobs and gives you tools to control them without needing external utilities.
There are two main states: - Foreground jobs: occupy your terminal - Background jobs: run without blocking your terminal
2. Running Jobs in the Background
To start a job in the background, append &:
sleep 60 &
3. Viewing Active Jobs
Use:
jobs
4. Moving Jobs Between Foreground and Background
Bring a job to the foreground:
fg %1
Send a job to the background:
bg %1
5. Suspending a Running Job
Press Ctrl + Z to pause a job.
6. Killing Jobs
kill %1
kill -9 %1
7. Disowning Jobs
disown %1
8. Keeping Jobs Running After Logout
nohup long_script.sh &
or
./script.sh & disown
9. Job Control with Pipelines
tar -czf archive.tar.gz folder | gzip > out.gz &
10. Advanced Tips
jobs -l
tail -f output.log
fg %%
Conclusion
Bash job control is simple but powerful. Mastering a few commands gives you flexible control over your processes without leaving the terminal.