date command

I‘m using the date +’%D_%T’ to store Unix system date and time in a shell variable called $_now:

_now=”$(date +’%D_%T’)”
echo $_now

Outputs:
01/20/12_16:10:42

I’d like to replace / and : with _. I’m aware of the following sed command:

sed ‘s/\//_/g
> s/:/_/g’ <<<"$_now"

Outputs:
01_20_12_16_14_09

How do I specify two pattern within the same sed command to replace | and : with _ so that I can get output as 01_20_12_16_10_42?

{ 1 comment }

HowTo: UNIX Set Date and Time Command

by Vivek Gite on April 26, 2011 · 3 comments

I recently noticed that one of my UNIX servers was about 4 hours behind the correct time. I wanted to correct the date and time manually. How do I set date and/or time under UNIX operating systems using command line options?

{ 3 comments }

UNIX / Linux: Increment The Date

by Vivek Gite on April 26, 2011 · 1 comment

I want to increment the date under UNIX or Linux operating system while writing shell scripts. For example Apr/27/2011 should be incremented as Apr/28/2011 and so on. How do I increment a date in UNIX or Linux shell?

{ 1 comment }

Linux: Bash Get Time

by Vivek Gite on October 27, 2010 · 1 comment

How do I get the system time in BASH? How can I get the Linux system using bash shell?

{ 1 comment }

How do I append current date (mm_dd_yyyy format) to a filename (e.g., backup_mm_dd_yyyy.sql) under UNIX like operating systems?

{ 0 comments }

The rndc stats commands created /var/named/chroot/var/named/data/named_stats.txt file under RHEL 5.x or CentOS 5.x BIND 9 server. However, date is not is correct format. The date is in the following format:
grep ‘Dump’ /var/named/chroot/var/named/data/named_stats.txt
outputs:

+++ Statistics Dump +++ (1263408025)
— Statistics Dump — (1263408025)
+++ Statistics Dump +++ (1263408071)
— Statistics Dump — (1263408071)
+++ Statistics Dump +++ (1268304218)
— Statistics Dump — (1268304218)
+++ Statistics Dump +++ (1268304248)
— Statistics Dump — (1268304248)

How do I convert date (e.g., 1263408025) in a human readable format?

{ 5 comments }

Bash: Display Current Date

by Vivek Gite on December 6, 2009 · 0 comments

How do I display the current date under Bash UNIX / Linux / OS X shell?

{ 0 comments }