When running a large complex command or time consuming command such as moving a large quantity of files from one drive to another or running a mass rename script, your terminal will become locked and only become available when that command has finished running.
To bypass this and run the command in the background simply append an & to the command. You will then be given a process ID of the command as it runs in the background.
Syntax:
command &
Here is a working example. I want to move all my .arw files from one drive to another, as i have quite a few large arw files this process takes up a lot of time. I also tend to access my linux box via ssh so don't want multiple connections to the terminal. This is the command i run:
mv *.arw /media/photos/ &
To see what jobs you have running use the following command
jobs
The following is a sample output that will be returned by this command
[1]+ Running mv *.arw /media/photos/ &
The [1] returned is the job ID, if you want to see the process ID then pass the -l option as below
jobs -l
This will return the same information as the main command but also include the process ID which is useful if you want to kill a process. See sample output below:
[1]+ 30125 Running mv *.arw /media/photos/ &
If you want to bring the job to the foreground use the following syntax:
%JOB_ID
so for our example:
%1
This will then show the command that you are running with any output in my case it will just display:
mv *.arw /media/photos/
To send it to the background again simply ctrl + z
and then %1 &
this will run it again in the background
Clive Walkden
Posted:
Latest Articles
Linux —
How to Install NordLayer VPN Client on Ubuntu 20.04 and Connect to a Virtual NetworkA simple to follow installation guide for NordLayer VPN
Author
MySQL —
Mastering MySQL Database Imports on LinuxLearn efficient ways to import MySQL databases on Linux using the mysql command-line client. Explore the --source option and < operator for seamless data migration. Master MySQL imports on Linux with our comprehensive guide.
Author
DevOps —
Mastering SSH Key Conversions for DevOpsA guide to convert SSH keys from one version to another using Linux CLI
Author