Low Orbit Flux Logo 2 F

Linux Command - bg

The bg command will resume a stopped background process. This is generally done after stopping a job with ctrl - z.

Start job number 5 as a background task:



bg %5

Start job that matches the specified string:



bg %myscript

Common use case:



bg %ping

More options:



bg %+    # current job
bg %%    # current job
bg %-    # previous job

Jobspec examples:

%5 job ID
%test starts with string
%?test contains string
%+ current job
%% current job
%- previous job

The fg command can be used to bring a job to the foreground.



fg  %5

The jobs command will list out jobs with IDs and status:



jobs
jobs -l

You can stop jobs like this:



kill -s stop %5

Remember you can start a job already running in the background with the ampersand:



./myscript.sh &

More Info

Check the type for the bg command:



type -a bg

Note that it is usually a shell built in and also exists as a binary. You will usually need to use the builtin.