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
- Resume jobs
- Job control
- Process management
- Interactive tasks
- Shell control
Examples with Explanations
Example 1: Current Job
fgResume current job
Example 2: Specific Job
fg %2Resume job number 2
Example 3: Named Job
fg %?nameResume job containing ‘name’
Common Usage Patterns
Background to fore:
fg %1Check then resume:
jobs; fg %2Stop then resume:
Ctrl-Z; fg
Job Control
- Background (bg)
- Foreground (fg)
- Stop (Ctrl-Z)
- List (jobs)
- Kill (kill)
Additional Resources
Best Practices
- Check job status
- Use job numbers
- Monitor output
- Clean up jobs
- Document usage
Security Considerations
- Job ownership
- Process control
- Terminal access
- User permissions
- Resource usage
Troubleshooting
- Job status
- Process state
- Terminal issues
- Shell problems
- Signal handling
Common Scenarios
- Interactive tasks
- Editing sessions
- Program control
- Debug sessions
- Shell operations