≡ Menu

Linux: Start Command In Background

I am a new Linux command line user. How do I start or run command in the background so that I can access command prompt immediately?

A command that has been scheduled nonsequentially is called background process. You can not see the background processes on screen. For example, Apache httpd server runs in background to serve web pages. You can put your shell script or any command in background.

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Estimated completion time10m


You can put a task (such as command or script) in a background by appending a & at the end of the command line. The & operator puts command in the background and free up your terminal. The command which runs in background is called a job. You can type other command while background command is running. The syntax is:

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


Put the ls command in the background, enter:
$ ls *.py > output.txt &
Put the following find command in a background by putting a '&' at the end of the command line:

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

Sample outputs:

Fig.01: Linux background job in action (click to enlarge)

Fig.01: Linux background job in action (click to enlarge)

How do I see jobs running in the background?

Type the following command:
Sample outputs:

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


  • [1] and [2] are job IDS.

To see process IDs for JOB IDs in addition to the normal information pass the -l option:
jobs -l
Sample outputs:

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

To see process IDs only, enter:
jobs -p
Sample outputs:


How do I kill the jobs running in the background?

Use the kill command to kill process either gracefully or forcefully. The syntax is:

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

See how to use killall command under Linux operating system for more information.

How do I bring process running in the background to the foreground?

The syntax is:
First, list the current jobs with jobs command, enter:
jobs -l
Sample outputs:

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

To bring the job id #2 to the foreground, enter:
OR use fg command:
fg 2
Sample outputs:

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

To send back this job in the background hit CTRL-Z i.e. while holding the CTRL key, press z key. This will suspend the current foreground job. Type the following command to send back the job in the background:
%2 &
OR use bg command:
The grep command job is now running in the background.

Summary of all useful commands

To see which jobs are still running jobsjobs
jobs -l
ps aux
To put a command / script to the backgroundcommand &
/path/to/command &
/path/to/script arg1 &
To bring a background job to the foregroundfg n
To send a job to the background without canceling itbg n
%n &

Note: n == Job id (use jobs command to see job id)..

See also:
Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 9 comments… add one }

  • [r4] March 29, 2013, 10:11 pm

    You can actually use the following form of kill command:
    kill %1
    to kill the first job in the list.

  • bkpsusmitaa August 22, 2013, 5:38 pm

    How can I send the message box generated from the following code to the background:
    title=$(gettext ‘SCANNING DEVICE’)
    text=$(eval_gettext ‘Looking for PPPoE Access Concentrator on $iface…’) &
    if test -n “$mmm” ; then
    mmode=$(gettext ‘(multi-modem mode)’)

  • mengjia March 19, 2014, 1:36 am

    great, thanks for help

  • shankar August 25, 2014, 5:42 am

    thank you!!

  • John Mark Mobley October 24, 2014, 6:58 pm
    pi@raspberrypi ~ $ cat niceTest2
    # By:......... John Mark Mobley
    # Date:....... 10-23-2014
    # Purpose:.... Test the nice command.
    # Description: Start a number of jobs at different priorities and monitor
    # ............ how much %CPU each job gets.
    #sudo nice -n -20 factor 1111111111111111111 >/dev/null &
    #sudo nice -n -10 factor 1111111111111111111 >/dev/null &
    nice -n 0 factor 1111111111111111111 >/dev/null &
    nice -n 10 factor 1111111111111111111 >/dev/null &
    nice -n 19 factor 1111111111111111111 >/dev/null &
    #top -b -n 1|grep factor
    while true; do
      top -b -n 1 >factorTemp.txt
      head -n 7 factorTemp.txt
      grep factor factorTemp.txt
      rm factorTemp.txt
      echo Press q to exit
      #sleep 10
      #CHAR=getkey with 10 second timeout
      read -s -n 1 -t 10 CHAR
      if [ "$CHAR" = "q" ]; then
    #sudo killall factor >/dev/null 2>&1
    killall factor >/dev/null 2>&1
  • Vijay Kumar Kanta December 19, 2014, 7:46 am

    Very useful information to BASH users. Thanks Vivek!

  • A_J February 7, 2015, 2:11 pm

    Thank you very much,
    Really helpful :)

  • Pauledd February 21, 2015, 6:50 pm

    That is what I was looking for. Thanx a lot

  • aref ghobadi August 16, 2015, 12:03 pm


Leave a Comment