Switching jobs within a terminal

November 21st, 2006 toydi Posted in Common, fg, jobs | Hits: 31259 | 3 Comments »

While writing a script in a text editor, suddenly, I sense a strong desire to refer the bash manual. To stop the current job and return to shell prompt, press Ctrl+z, and here’s what I see:

Use "fg" to return to nano.

[1]+  Stopped                 nano lotr.sh
$ 

I type man bash and start reading. To switch back to the text editor, again, I press Ctrl+z to stop the current job, and use fg - to resume (to the second previous job, notice the extra minus ‘-’ sign):

[2]+  Stopped                 man bash
$ fg -

Why the second previous job? When I Ctrl+z out from man bash, man bash has become my previous job. I may use fg or fg + to resume it. But that’s not what I want, so I use fg -, it means to resume to the job before the previous job.

Confusing? ;-) Ha, it will be crystal clear when you list ‘em out and try it yourself:

$ jobs
[1]-  Stopped                 nano lotr.sh
[2]+  Stopped                 man bash 

3 Responses to “Switching jobs within a terminal”

  1. Haha its time for you to learn up vim, vim have build in function key bind to look for manuals, move your cursor to the desire word and press shift k.

    Refers to http://lne.blogdns.com/lbe/archives/10/searching-man-page-inside-vi-editor/

  2. there have another way to resume the jobs you want:

    fg %1

    if you have a lot of jobs in background, you able to use this

    fg %n

    to resume any jobs 'n' in background.

  3. [...] 5 is the starting point and 7 is the string length for sub string. Related Posts Switching jobs within a terminal While writing a script in a text editor, suddenly, I sense a strong desire to refer the bash manual. To stop the current… [...]

Leave a Reply