> Linux Reviews > Beginners: Learn Linux >

Jobs - the basics of job control

Jobs - the basics of job control v0.1.1 (en), xiando

Every command you give is a job that is executed. A job can be suspended, placed in the background, moved back to the foreground or terminated.

Most commands like ls are executed fast, but things like moving huge files occupy your terminal for quite a while. In these cases the job can be placed in the background, allowing you to execute other commands in the meantime.

While running a command (job) you can pause/suspend it with ctrl-z and kill it with ctrl-c.

While running a job you can Shortcut
suspend a job ctrl -z
terminate a job ctrl -c

When a job is suspended it can be moved back to the foreground with `fg` and placed in the background (where it will continue to execute) with `bg`.

Function Command
Move a suspended job to the foreground fg
Continue a suspended job in the background bg
List all jobs jobs
Kill a job (%N where N is the job number) kill %N && fg
Start a job directly in the background command &

How to run, suspend and continue a command in the background

Examples of how to run a job in the background:

  $ cp video.avi /pub/videos
  [1]+  Stopped  cp video.avi /pub/videos
  [1]+  cp video.avi /pub/videos
  $ bg
  [1]+  Done  cp video.avi /pub/videos

Putting a job in the background with & when executing

  $ cp video.avi /pub/videos &
  [1] 6510
  $ jobs
  [1]+  cp video.avi /pub/videos &
  [1]+  Done cp video.avi /pub/videos &

Killing a running job

  $ cp video.avi /pub/videos
  $  kill %1 && fg
  cp video.avi /pub/videos

Note that `jobs` applies to the running jobs in your current shell, use `top` or `ps -aux` to list all the running jobs on your computer.

The latest version of this documents is available at linuxreviews.org.

Copyright (c) 2002-2004 Øyvind Sæther. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

> Linux Reviews > Beginners: Learn Linux >
Jobs - the basics of job control