Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In an interactive Bash session, press Ctrl+Z to suspend a foreground command and reclaim the prompt. Run bg to continue that job in the background, and use fg later to return it to the terminal. The jobs builtin shows the shell’s job numbers and states so you can target the right task.

What foreground and background mean

A foreground job owns the terminal’s input and interactive control. Bash waits for it, and keystrokes such as Ctrl+C or Ctrl+Z are delivered to that job.

A background job continues while Bash displays a prompt for other commands. It normally cannot read from the controlling terminal. If it attempts to do so, Bash documents that it receives SIGTTIN and is ordinarily suspended. Commands that need keyboard input or interactive control therefore belong in the foreground.

Job-control numbers are references maintained by the current shell; they are not process IDs. Job control requires an interactive shell with job control enabled, so behavior in noninteractive scripts, some remote-session managers, and other shells can differ.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Move a running command to the background

  1. Start a command normally:

    long_command
  2. Press Ctrl+Z. Bash suspends the foreground job and returns the prompt. This step stops the job; it does not make the job continue running in the background.

  3. List the shell’s jobs:

    jobs

    Read the displayed job number and state. Bash may mark the current job with + and the previous job with -.

  4. Resume the selected job in the background:

    bg %1

    Replace %1 with the job number shown by jobs. With no jobspec, bg uses the shell’s current job.

After bg, the command continues without taking over the terminal. Its output may still appear in the terminal unless you redirected it when launching the command.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Bring a background job back to the terminal

Use fg with the shell job specification:

fg %1

Bash resumes job 1 in the foreground and returns terminal interaction to it. If you omit the jobspec, fg selects the current job. A command that was stopped because it tried to read terminal input can normally proceed once you foreground it.

Start a command in the background immediately

If you know at launch that a command does not need terminal input, append &:

long_command &

Bash starts the command asynchronously and gives you another prompt. Use jobs to inspect it, fg to make it interactive, or bg when continuing a job that was previously stopped.

Understand Bash job specifications

Notation Meaning
%1 Shell job number 1, as reported by jobs.
%+ or %% The shell’s current job.
%- The shell’s previous job.

The + and - markers in relevant jobs output identify the current and previous jobs. These symbols and numbers are shell references, not stable process IDs; they can change as jobs finish or as you create new jobs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A complete state-change example

long_command
# press Ctrl-Z
jobs
bg %1
jobs
fg %1
  • After long_command: the command owns the terminal in the foreground.
  • After Ctrl+Z: the job is stopped and Bash prints a prompt.
  • After the first jobs: you learn the job number and state.
  • After bg %1: job 1 is continued in the background.
  • After the second jobs: you can verify its current state.
  • After fg %1: job 1 is continued in the foreground and receives terminal interaction again.

Monitor or stop a job

Check state with jobs

Run jobs whenever you are unsure whether a job is running, stopped, or finished. Target the job number it displays rather than guessing from a process ID.

Terminate a shell job

The shell can send a signal using its job specification, for example:

kill %1

Use the job’s actual number. A termination request is not the same as suspending or foregrounding; check jobs afterward to confirm the result.

When backgrounding is appropriate

  • Use command & for a task that can run without keyboard input.
  • Use Ctrl+Z followed by bg when a command is already occupying the terminal and you decide it can continue unattended.
  • Use fg before supplying input, responding to an interactive prompt, or otherwise controlling the program from the terminal.
  • Keep output and lifetime in mind: a background job can still write to your terminal, and an illustrative loop that writes the date and time to a file and sleeps for two minutes will continue until you terminate it or the session, logout, or system state ends it. That example demonstrates job control, not a production recommendation or performance measurement.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common mistakes and recovery

Assuming Ctrl+Z keeps the command running

It does not. It suspends the job. Run bg with the correct jobspec to continue it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Using a process ID where a jobspec is expected

fg, bg, and kill can use Bash jobspecs such as %1. Get that value from jobs; do not treat it as the operating system’s process ID.

Backgrounding an interactive program

A background program that reads the controlling terminal is ordinarily stopped with SIGTTIN. Use fg to return it to the terminal, or restart it in a context designed for noninteractive operation.

Targeting the wrong job

Job numbers and current/previous markers are shell-specific and change over time. Run jobs immediately before selecting a job when several tasks are active.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.