Skip to main content
ubuntuask.com

Back to all posts

How to Check the Current Date And Time In Bash?

Published on
3 min read
How to Check the Current Date And Time In Bash? image

Best Bash Date and Time Scripts to Buy in November 2025

1 Black Hat Bash: Creative Scripting for Hackers and Pentesters

Black Hat Bash: Creative Scripting for Hackers and Pentesters

BUY & SAVE
$37.90 $59.99
Save 37%
Black Hat Bash: Creative Scripting for Hackers and Pentesters
2 Learning the bash Shell: Unix Shell Programming (In a Nutshell (O'Reilly))

Learning the bash Shell: Unix Shell Programming (In a Nutshell (O'Reilly))

  • AFFORDABLE PRICES FOR QUALITY PRE-OWNED BOOKS.
  • ECO-FRIENDLY CHOICE: REDUCE, REUSE, READ!
  • WIDE SELECTION ACROSS GENRES FOR EVERY READER.
BUY & SAVE
$24.99 $44.99
Save 44%
Learning the bash Shell: Unix Shell Programming (In a Nutshell (O'Reilly))
3 The Ultimate Linux Shell Scripting Guide: Automate, Optimize, and Empower tasks with Linux Shell Scripting

The Ultimate Linux Shell Scripting Guide: Automate, Optimize, and Empower tasks with Linux Shell Scripting

BUY & SAVE
$27.89 $49.99
Save 44%
The Ultimate Linux Shell Scripting Guide: Automate, Optimize, and Empower tasks with Linux Shell Scripting
4 The Linux Command Line, 2nd Edition: A Complete Introduction

The Linux Command Line, 2nd Edition: A Complete Introduction

BUY & SAVE
$23.99 $39.99
Save 40%
The Linux Command Line, 2nd Edition: A Complete Introduction
5 Linux Basics for Hackers: Getting Started with Networking, Scripting, and Security in Kali

Linux Basics for Hackers: Getting Started with Networking, Scripting, and Security in Kali

BUY & SAVE
$18.73 $39.99
Save 53%
Linux Basics for Hackers: Getting Started with Networking, Scripting, and Security in Kali
6 Scripting: Automation with Bash, PowerShell, and Python—Automate Everyday IT Tasks from Backups to Web Scraping in Just a Few Lines of Code (Rheinwerk Computing)

Scripting: Automation with Bash, PowerShell, and Python—Automate Everyday IT Tasks from Backups to Web Scraping in Just a Few Lines of Code (Rheinwerk Computing)

BUY & SAVE
$36.76 $49.95
Save 26%
Scripting: Automation with Bash, PowerShell, and Python—Automate Everyday IT Tasks from Backups to Web Scraping in Just a Few Lines of Code (Rheinwerk Computing)
7 Bash Pocket Reference: Help for Power Users and Sys Admins

Bash Pocket Reference: Help for Power Users and Sys Admins

BUY & SAVE
$17.60 $24.99
Save 30%
Bash Pocket Reference: Help for Power Users and Sys Admins
8 Classic Shell Scripting

Classic Shell Scripting

BUY & SAVE
$24.73 $49.99
Save 51%
Classic Shell Scripting
9 The Book of Batch Scripting: From Fundamentals to Advanced Automation

The Book of Batch Scripting: From Fundamentals to Advanced Automation

BUY & SAVE
$42.46 $59.99
Save 29%
The Book of Batch Scripting: From Fundamentals to Advanced Automation
+
ONE MORE?

To check the current date and time in Bash, you can use the date command. By simply running the date command in your Bash terminal, it will display the current date and time according to your system's settings.

Here's an example of how you can use the date command to display the current date and time:

$ date

This command will output something similar to the following:

Mon Oct 18 09:47:25 UTC 2021

The displayed information includes the day of the week, the month, the day of the month, the time in HH:MM:SS format, the time zone (in this case, UTC), and the year.

You can also format the output of the date command to display the current date and time in a specific format. For example, if you want to display only the date in the format of "YYYY-MM-DD", you can use the following command:

$ date +%Y-%m-%d

This will output the current date in the desired format, such as:

2021-10-18

Similarly, you can format the output to display the time or a specific combination of date and time elements as per your requirements.

That's how you can check the current date and time in Bash using the date command.

How to display the current second in Bash?

In Bash, you can use the date command with the %S format specifier to display the current second. Here's an example:

#!/bin/bash

seconds=$(date +%S) echo "Current second: $seconds"

Save the above code in a file (e.g., display_second.sh), make it executable (chmod +x display_second.sh), and then run it (./display_second.sh). It will display the current second.

What is the command to check the current second since the epoch in Bash?

The command to check the current second since the epoch in Bash is:

date +%s

The %s format specifier tells the date command to display the number of seconds since the Unix epoch (January 1, 1970).

What is the syntax to get the current timestamp in seconds since the epoch in Bash?

The syntax to get the current timestamp in seconds since the epoch in Bash is as follows:

timestamp=$(date +%s)

This uses the date command with the format specifier %s to get the timestamp in seconds since the Unix epoch (January 1, 1970 00:00:00 UTC). The result is then stored in the variable timestamp.

What is the command to check the current minute in Bash?

The command to check the current minute in Bash is:

date +%M

It uses the date command with the format option %M to display only the minute part of the current time.