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
Difficulty Easy (rss)
Root privileges No
Requirements Bash/ksh
Time 10m


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)

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

Description Command
To see which jobs are still running jobs jobs
jobs -l
ps aux
To put a command / script to the background command &
/path/to/command &
/path/to/script arg1 &
To bring a background job to the foreground fg n
To send a job to the background without canceling it bg n
%n &

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

See also:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 10 comments so far... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
10 comments… add one
  • [r4] Mar 29, 2013 @ 22:11

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

  • bkpsusmitaa Aug 22, 2013 @ 17:38

    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 Mar 19, 2014 @ 1:36

    great, thanks for help

  • shankar Aug 25, 2014 @ 5:42

    thank you!!

  • John Mark Mobley Oct 24, 2014 @ 18:58
    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 Dec 19, 2014 @ 7:46

    Very useful information to BASH users. Thanks Vivek!

  • A_J Feb 7, 2015 @ 14:11

    Thank you very much,
    Really helpful :)

  • Pauledd Feb 21, 2015 @ 18:50

    That is what I was looking for. Thanx a lot

  • aref ghobadi Aug 16, 2015 @ 12:03


  • Patty RW Dec 31, 2016 @ 2:11

    My program MyCmd is designed to run indefinitely.
    Why doesn’t this work as expected, killing it after 60 secs?
    The output file never correctly contains the date+output+date

    date >>1.txt
    MyCmd >>1.txt &
    sleep 60
    pkill -USR1 MyCmd
    Date >>1.txt

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @