Running Commands In The Background In Linux

9th May 2010

A useful technique to know about when using Linux is to run commands in the background. Sometimes certain commands can either take a while (like copying a large file) or will simply take over the terminal window when run. For example, lets say that you open a file in gedit, you might use the following command.

gedit file.txt

Doing this will open the file in gedit but will not allow you to do anything in the terminal window until you close gedit. To open the file but still keep the terminal window active use the & symbol at the end of the command. This will run the proceeding command in the background.

gedit file.txt&

To run a file copy in the background do the following.

cp file.txt file.txt.bak&

Note that this command shouldn't be used for all commands, especially those that produce some form of output. For example, running the following command

ls&

Will cause the terminal window to print out the contents of the current directory and sit patiently waiting for you to quit the program. You can do this by pressing Ctrl+c.

Comments

Permalink
Hello there! I truly appreciated reading your write-up. Hope you write more similar to this!

Josie (Thu, 05/23/2013 - 09:44)

Permalink
thanks for your post, it is very helpful for me.

linux command (Sat, 01/17/2015 - 10:28)

Add new comment

The content of this field is kept private and will not be shown publicly.