fg

Overview

The fg command resumes jobs in the foreground. It brings a background or stopped job into the foreground, making it the current job.

Syntax

fg [jobspec]

Common Options

Option Description
-h Show help
-v Show version

Job Specification

Spec Description
%n Job number n
%str Job starting with str
%?str Job containing str
%+ Current job
%- Previous job
%% Current job

Key Use Cases

  1. Resume jobs
  2. Job control
  3. Process management
  4. Interactive tasks
  5. Shell control

Examples with Explanations

Example 1: Current Job

fg

Resume current job

Example 2: Specific Job

fg %2

Resume job number 2

Example 3: Named Job

fg %?name

Resume job containing ‘name’

Common Usage Patterns

  1. Background to fore:

    fg %1
  2. Check then resume:

    jobs; fg %2
  3. Stop then resume:

    Ctrl-Z; fg

Job Control

  1. Background (bg)
  2. Foreground (fg)
  3. Stop (Ctrl-Z)
  4. List (jobs)
  5. Kill (kill)

Additional Resources

Best Practices

  1. Check job status
  2. Use job numbers
  3. Monitor output
  4. Clean up jobs
  5. Document usage

Security Considerations

  1. Job ownership
  2. Process control
  3. Terminal access
  4. User permissions
  5. Resource usage

Troubleshooting

  1. Job status
  2. Process state
  3. Terminal issues
  4. Shell problems
  5. Signal handling

Common Scenarios

  1. Interactive tasks
  2. Editing sessions
  3. Program control
  4. Debug sessions
  5. Shell operations