How to use a date shell script
Here you will find out:
- what a bash date command is
- how to format the bash date and how to use these scripts
- when DiskInternals can help you
Are you ready? Let's read!
What is a bash date command?
Simply put, this is a command used to print the current system date and time. Also, it can be used to set the date and time on a Linux system. The bash date command is among the core Linux utilities, and it prints the date and time zone when a Unix/Linux system is configured.
The current date and time
If you run the bash date command without including a variable, the result will look like what you see below:
How to format the bash date
There are different ways to format the output of a bash date command.
To get date and time in U.S. format (MM/DD/YY HH:MM:SS), use the code below:
Output:
If you want to get the date and time in a different format (e.g., YYYY-MM-DD HH:MM:SS):
How to use these scripts
The easiest way to learn how to run bash date scripts is to run date --help to print the help information.
The following describes the bash date options:
| Format option | Output |
| %a | Abbreviated weekday name (e.g., Mon) |
| %A | Full weekday name (e.g., Monday) |
| %b | Abbreviated month name (e.g., Aug) |
| %B | Full month name (e.g., August) |
| %c | Abbreviated local date and time (e.g., Mon Jan 5 24:20:54 2019) |
| %F | Full date in this format: %Y-%m-%d |
| %s | Seconds |
| %u | Day of the week (1-7), where 1 represents Monday, 2 is Tuesday, etc. |
| %U | Week number of the year (00-53), where Sunday is treated as the first day of the week |
Examples of using a bash date script
For all these examples, take note of the capital and small letters, because “M” and “m” do not mean the same thing.
Get date in MM-YYYY
Get date and time in MM/DD/YY HH:MM:SS
Get date in MM-DD-YYYY
Get time on Unix epoch format
Get date and time in YYYY-MM-DD HH:MM:SS
How to open Linux files in Windows easily
If you have ever worried about accessing Linux files in Windows, here’s an ideal solution for you. DiskInternals Linux Reader is an advanced PC utility that is available for free. It comes with a bunch of handy features for accessing and viewing Linux files in Windows computers. Also, DiskInternals Linux Reader works for virtual machines. The most interesting part of this utility is that it doesn't support any algorithm. It is intuitive to use, and supports various file systems and previews any type of file (pictures, videos, documents, etc.).
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
- 5 Basic Shell Script Examples for Your First Script
- Bash: How to Check if the File Does Not Exist
- Bash Time Command on Linux
- How to use bash get script directory in Linux
- How to Check Bash String Equality
- How to Use Linux Wait Command
- Bash: How to Loop Through Files in Directory
- 20 Examples of Bash Find Command
- 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
- Shell Script Cut: Basic You Need to Know
- Bash: How to Check if String Not Empty in Linux
- Bash: how to split strings in Linux
- Linux: Sudo in Bash Scripts
- Hello World Script in Bash
- A Linux bin/bash Shell
- Linux: New Line in Shell Script
- Linux: Bash String Ends With
- Linux: Bash Printf Examples
- Linux: Bash First Line
- Linux: $0 in a Shell Script
- Linux: A Bash Startup Script
- Linux: Write a Shell Script
- Shell Script: Replace String in File
- A crontab service shell script
- Bash and sh: is there any difference
- A Bash Dirname Command
- Linux: A Bash Source Command
- A Bash to Loop through Lines in File
- Linux: A Bash Linter
- A Bash Nested Loop
- A Bash Test Command
- Use a Shell Script to Send an Email
- A Bash Status of Last Command
- Linux: A Bash Basename Command
- Using Bash to Write to a File
- About Bash Language
- Bash for Loop in One Line
- AWK in a Bash Script
- Learn about useful bash scripts
- Learn about systemd startup script
- About chaining bash commands
- Learn about a bash error code
- Using a bash tee command
- About a bash export command
- Learn about a bash wait command
- Arch Linux install script
- About advanced bash scripting
- To run a shell script in Dockerfile
- About a bash UNTIL loop
- Learn about C shell script
- Learn about Korn shell scripting
- Using /usr/bin/env command
- Whether bash waits for command to finish
- Using bash if 0
- Using && in an IF statement in bash
- If you want to run shell script in background
- The disk you inserted was not readable by this computer error
- Learn about SFTP in bash scripting
- Learn to run Perl script in Linux
- Examples of using the Expect
- Copy command in shell scripts
- Shell script usage
- Install Oracle Database
- Here is everything you need to know about Bash for Windows
- Guide in Pictures
- How to Use Shell Script Sleep Command
- A Bash Multiline Command




