bash

Linux fg bg commands usage and examples

Overview

Linux fg bg commands usage and examples using CTRL-Z and jobs command.
Move a process between background and foreground modes with paused and running states.

Usage and examples

Pause a process

When running a process you can use CTRL-Z to pause the process and free the current shell instance:
Linux fg bg commands ctrl-z-stop

Linux jobs command

To view the stopped jobs use the jobs command:

jobs

You should receive something like this (Job number, Status, Command):
[1]+  Stopped                 ls --color=auto -l --color=auto -lla -R /

Run a process in the background

You can start a process in the background from the start using an ‘&’ mark at the end of the command:

cp /source /destination &

linux fg bg commands

To move a job to the foreground execution (for example job 1):

fg 1

To move a job to the background execution (for example job 1):
bg 1

Kill paused jobs

To kill a paused job you can use the kill command followed by the job number (for example job 1):

kill %1

Enjoy

Leave a Reply

Your email address will not be published.


*