There are many scenarios where the system admin requires to execute length process. Such process are advisable to run in background. In Unix / Linux you can run or execute any command in background by adding ampercent “&” at the end of the command.
root@server [~]# ls &
The above command will verbose the process id and execute the process in background.
root@server [~]# source commandlist.txt &
The above command will verbose the process id and execute the command listed in commandlist.txt in background.
The above commands are extremely useful for taking backups and automated tasks. List all your commands in a text file and execute it in background with the help of above command.
At times you will need to execute certain commands which should continue to run even after log off. Such commands keep on executing even after you log off from system.
Such commands are not affected by hang up signals and hence continue to run.
root@server [~]# nohup COMMAND
The above COMMAND’s execution will not get terminated even if you log off from the system. The nohup command, executes COMMAND, ignoring hang up signals.
root@server [~]# nohup zip -9 -r allfiles.zip /home/username/www/
The above command will compress all files in /home/username/www/ recursively (-r) with best compression (-9) into allfiles.zip. If you want to run this command in background you can add ampercent “&” at the end of the command.
root@server[~]# nohup zip -9 -r allfiles.zip /home/username/www/ &