Finer Job Selection
In the previous article we saw basics of job control but we skipped alternatives to select jobs. Consider the following job listing throughout this article.
$jobs  Running find . -name *.xml > /dev/null & - Stopped cat /dev/zero > /dev/null + Stopped find . -name *.cc > /dev/null
1. Using job number
You can use the job number (the number in square bracket) to work on it. Jobs can be referred by job number using
N is the job number.
will resume 2nd job in foreground
2. Using job execution command
It’s not required to know the job number if you are more comfortable with the execution command.
The following command will resume 2nd job (the one starting with cat in background)
Whereas this next one will resume the 3rd one in background
Note the difference of
? in first and second form. Without
?, prefix is searched whereas with
? substring is searched. In case there are more than one job matching, the command will report an error.
3. Selecting current and previous jobs
Current job and previous job can be referred using
A shorthand method to resume jobs in foreground and background exists. Following commands are just short-form of respective longer commands.
%N => fg %N %N & => bg %N
A detailed article on job control can be found here.