The nuances of running a command through the Linux background

The instructions will tell you how to register certain commands through the background and directly use the command line interface.

A background process is any commands that have been forcibly scheduled by the user. Such actions will not be displayed on the monitor and are not visible to the average user. A prime example of a process is an server serving a web page, as well as scripts and commands.

Syntax rules

[step num=”1″]

The work of many commands, tasks and scripts can be rebuilt for a background process by simply adding the “&” character. The ampersand should be placed on the command line at the very end of the function. After that, he will quickly transfer the scripts and free up some free space.


[step num=”2″]

Those scripts that will run through the background are called jobs. The syntax to execute them would look like this:

command & -name & /path/to/command arg1 arg2 & command-1 | command-2 arg1 & command-1 | command-2 -arg1 -arg2 >/path/to/output &


What does look like

[step num=”3″]

Consider a simple example of translating some ls command:

$ ls *.py > output.txt &


[step num=”4″]

To translate the subsequent search script, you will need to add an ampersand after the entire expression:

find . -iname "*.mp3" > myplaylist.txt &


Detection of jobs running through background processes

[step num=”5″]

To find commands and scripts that have been put into the background, you need the command:




[1]- Running find / -iname "*.c" 2> //null > /tmp/output.txt & [2]+ Running grep -R "hostNamed" / 2> /dev/null > /tmp/grep.txt &

In this expression, [1] and [2] are job identifiers. To display them further through the process ID, you will need to enter -l:

jobs –l


[1]- 7307 Running find / -iname "*.c" 2> /dev/null > /tmp/output.txt & [2]+ 7324 Running grep -R "hostNamed" / 2> /dev/null > /tmp/grep.txt &

[step num=”6″]

If you want to show only the process ID, you should write:

jobs -p



7307 7324

Removing scripts running in the background

[step num=”7″]

If the user needed to gradually or forcibly end the background process of one of the tasks, you should use the “kill” command:

kill PID kill -15 PID kill -9 PID killall process-Name-Here killall -15 process-Name-Here killall -9 process-Name-Here


Move background process to foreground process

[step num=”8″]

To perform movements, use:





[step num=”9″]

First, all current background processes are displayed using the syntax:

jobs -l



[1]- 7307 Running find / -iname "*.c" 2> /dev/null > /tmp/output.txt & [2]+ 7324 Running grep -R "hostNamed" / 2> /dev/null > /tmp/grep.txt &

[step num=”10″]

Translation of the task with the second identifier will be carried out thanks to the command:

%2 ЛИБО fg 2


[step num=”11″]

How can I get the data:

grep -R "hostNamed" / 2> /dev/null > /tmp/grep.txt


[step num=”12″]

If you need to make priority tasks back to the background, it will be enough to hold “CTRL” and simultaneously press “Z”. All running priority tasks will be stopped for a while.


[step num=”13″]

Returning to the background will be done like this:

%2 & ЛИБО bg


This way “grep” will fall back to the background.

Most Useful Commands

Shows all running jobs, as well as their
jobs -l
ps aux
Translates a command or script to work in the foreground.command &
/path/to/command &
/path/to/script arg1 &
Changes the background job to run in the foreground.fg n
Will put the command back into the background without prompting it to be n
%n &

By “n” is meant the identification number of the jobs, it is output when the “jobs” command is executed.


Welcome to the world of DomainRooster, where roosters (and hens) rule the roost! We're a one-stop shop for all your entrepreneurial needs, bringing together domain names and website hosting, and all the tools you need to bring your ideas to life. With our help, you'll soar to new heights and hatch great success. Think of us as your trusty sidekick, always there to lend a wing and help you navigate the sometimes-complex world of domain names and web hosting. Our team of roosters are experts in their fields and are always on hand to answer any questions and provide guidance. So why wait? Sign up today and join the ranks of the world's greatest entrepreneurs. With DomainRooster, the sky's the limit! And remember, as the saying goes, "Successful people do what unsuccessful people are not willing to do." So don't be afraid to take that leap of faith - DomainRooster is here to help you reach for the stars. Caw on!