Linux Sleep Command (Pause a Bash Script)

sleep is a command-line utility that allows you to suspends the calling process for a specified time. In other words, the sleep command pauses the execution of the next command for a given number of seconds.

The sleep command is useful when used within a bash shell script, for example, when retrying a failed operation or inside a loop.

In this tutorial, we will show you how to use the Linux sleep command.

How to Use the sleep Command

The syntax for the sleep command is as follows:

sleep NUMBER[SUFFIX]...

Copy

The NUMBER may be a positive integer or a floating-point number.

The SUFFIX may be one of the following:

  • s - seconds (default)
  • m - minutes
  • h - hours
  • d - days

When no suffix is specified, it defaults to seconds.

When two or more arguments are given, the total amount of time is equivalent to the sum of their values.

#sleep #linux sleep #bash script #bash

What is GEEK

Buddha Community

Linux Sleep Command (Pause a Bash Script)

Linux Sleep Command (Pause a Bash Script)

sleep is a command-line utility that allows you to suspends the calling process for a specified time. In other words, the sleep command pauses the execution of the next command for a given number of seconds.

The sleep command is useful when used within a bash shell script, for example, when retrying a failed operation or inside a loop.

In this tutorial, we will show you how to use the Linux sleep command.

How to Use the sleep Command

The syntax for the sleep command is as follows:

sleep NUMBER[SUFFIX]...

Copy

The NUMBER may be a positive integer or a floating-point number.

The SUFFIX may be one of the following:

  • s - seconds (default)
  • m - minutes
  • h - hours
  • d - days

When no suffix is specified, it defaults to seconds.

When two or more arguments are given, the total amount of time is equivalent to the sum of their values.

#sleep #linux sleep #bash script #bash

Annalise  Hyatt

Annalise Hyatt

1594449240

Bash add pause in shell script with bash pause command

ost of you may be aware of old good DOS/2000/XP pause command. It is used to display the prompt while suspending the processing of a batch script. It is used within a computer batch file and allows the computer to pause the currently running batch file until the user presses any key. Let us see how to pause our bash based shell script for a given number of times in seconds/minutes/hours before continuing to next operation/command running on a Linux or Unix-like systems.

ADVERTISEMENTS

bash pause command under Linux / UNIX / macOS

There is no pause command under Linux/UNIX bash shell. You can easily use the read command with the -p option to display pause along with a message.

Bash add pause prompt using sleep and read command in shell scripts under Linux and Unix

Bash add pause prompt in a shell script with bash pause command

For example:

read -p "Press [Enter] key to start backup..."
read -p "Press any key to resume ..."
## Bash add pause prompt for 5 seconds ##
read -t 5 -p "I am going to wait for 5 seconds only ..."

#bash #pause #linux #unix

Examples of the dig command in Linux

Dig Command Line Options and Examples
Here is the frequently used command line options and example’s of dig command.
1. Basic Dig Command
A basic dig command accept domain name as command line parameter and prints Address record.
2. Query With Specific DNS Server
The default dig command queries to dns server configured on your system. For example, the Linux systems keep default DNS entry in /etc/resolv.conf.
3. Print Short Answer
Use +short command line option to print result in short form. This is basically useful with the shell scripting and other automation tasks.
4. Print Detailed but Specific Result
Use +noall with +answer to print detailed information but specific. This will print only answer section including few more details as a result.

#linux commands #command #dig #dig command #useful examples #linux

Useful Example for the mv command in Linux

mv Command Examples
Below is the basic mv command examples on Linux terminal.

  • Rename file in current directory – For example rename file source.txt to dest.txt in current directory.
  • Move file to destination directory – Move a source.txt file available in current directory to /tmp directory. In above command the file name is unchanged at target directory. You can also rename file name at destination directory just by providing filename at destination.
  • Move file from source directory to destination directory – We can also move files or directory from some other directory to destination directory.
  • Move multiple files to destination at once – The mv accepts multiple source files and move them to the destination directory at once. The following command will move file1.txt, file2.txt in current directory and /opt/file3.txt to the /tmp directory. Here the last command line parameter is used as destination by the mv command.

#linux commands #command #mv #useful example #mv command #linux

date command in Linux with Examples

date Command Examples
Show date time in UTC/GMT
View past dates on specific days
View future dates
View date in other timezone
Print date in specific format
View file modification time

#linux commands #command #date #linux