How to run a shell script in the background
Here you will find out:
- when you may run a command in the background
- how to use &, nohups and the SCREEN command
- when DiskInternals can help you
Are you ready? Let's read!
When you may run a command in the background
If commands are executed in the foreground, this may become inconvenient for you. A command can take a long time until it completes, during which time you cannot set a new command. In this case, working at a computer can be complicated and time-consuming. In order to avoid such situations and to increase user comfort, you can run a bash script in the background. That is, the task can be scheduled to run from the terminal without user intervention. This way, you free up your time and improve your computer’s functioning.
Using & at the end of the command
Putting a command in the background is extremely simple, you only need one character: &.
Here’s an example:
After that, you can continue to use the terminal without waiting for the end of the session. If the terminal session is closed, the command ends and the background command is turned off automatically. If this does not suit you, and you want the task to continue in the background on an ongoing basis, then this can also be done. To do this, you must first enter “&”, and then the DISOWN command.
Here's what it looks like in an example:
To verify the correctness of the actions, you can enter the JOBS command.
Now you know that making running a background task is easy!
Using nohups
If you want to run a task in background mode for a long time, then you should use the NOHUP command. For example:
This command weakens the HUP signal as much as possible, as a result of which it is possible to execute commands in the background when the terminal is off.
Using the SCREEN command
Using NOHUP and &, the command in the background will be executed even after logging out. However, this does not mean that you can connect to the same session again to see exactly what is happening on the screen. There is an onscreen command for this. With its help, Linux suggests disconnecting the session on which a process is running. This command weakens the HUP signal as much as possible, as a result of which it is possible to run a script in the background with the terminal turned off.
If you want to get files from Linux
If you are using a dual-boot installation or a virtual machine, and you need to get files from Linux to Windows, you must install a one-of-a-kind application: DiskInternals Linux Reader. This program makes it possible to get absolutely any files in Windows from Linux for free. When there is such an opportunity, you should use it. The application works with many file systems (Ext2 / Ext3 / Ext4, HFS, ReiserFS, and others). Access is available to all files as read-only on Linux disks (the source files will be unchanged in any case). The program reads any kind of drive: SSDs, memory cards, HDDs, flash drives and others. Creating a disk image is an unrivaled bonus for customers.
Related articles
- How to Access Linux Ext2 or Ext3 on Windows
- How to Access Ext4 from Windows
- How to Mount Ext4 on Windows for Free
- Mount Linux Drive on Windows for Free
- Bash Script: All You Need to Know
- An Algorithm: How to Create Bash While Loop
- Linux Shell: What You Need to Know at First
- How to Use Shell Script Sleep Command
- Bash: How to Check if the File Does Not Exist
- How to use bash get script directory in Linux
- 20 Examples of Bash Find Command
- Shell Script Cut: Basic You Need to Know
- Bash: How to Check if String Not Empty in Linux
- Linux: Sudo in Bash Scripts
- Linux: Bash Printf Examples
- Linux: Bash First Line
- Linux: A Bash Startup Script
- Linux: Write a Shell Script
- Shell Script: Replace String in File
- Bash and sh: is there any difference
- A Bash Dirname Command
- Linux: A Bash Source Command
- A Bash to Loop through Lines in File
- A Bash Nested Loop
- Use a Shell Script to Send an Email
- Using Bash to Write to a File
- About Bash Language
- Bash for Loop in One Line
- Learn about useful bash scripts
- About chaining bash commands
- About a bash export command
- Learn about a bash wait command
- Arch Linux install script
- About advanced bash scripting
- Learn about C shell script
- Learn about Korn shell scripting
- Using && in an IF statement in bash
- The disk you inserted was not readable by this computer error
- Learn about SFTP in bash scripting
- Copy command in shell scripts
- Install Oracle Database
- About a bash date command
- Guide in Pictures
- 5 Basic Shell Script Examples for Your First Script
- Bash Time Command on Linux
- How to Check Bash String Equality
- How to Use Linux Wait Command
- Bash: How to Loop Through Files in Directory
- Bash Cat Command in Examples
- Bash Script SSH: How to Use It
- Bash: A Script For User Input
- Linux ZSH: the basic you need to know
- Basic of Grep in Linux Shell Script
- Bash: how to split strings in Linux
- Hello World Script in Bash
- A Linux bin/bash Shell
- Linux: New Line in Shell Script
- Linux: Bash String Ends With
- Linux: $0 in a Shell Script
- A crontab service shell script
- A Bash Multiline Command
- Linux: A Bash Linter
- A Bash Test Command
- A Bash Status of Last Command
- Linux: A Bash Basename Command
- AWK in a Bash Script
- Learn about systemd startup script
- Learn about a bash error code
- Using a bash tee command
- To run a shell script in Dockerfile
- About a bash UNTIL loop
- Using /usr/bin/env command
- Whether bash waits for command to finish
- Using bash if 0
- Learn to run Perl script in Linux
- Examples of using the Expect
- Shell script usage
- Here is everything you need to know about Bash for Windows




