Friday, February 13, 2009

Linux / Unix / Solaris date command

Using perl Command line
ls -1 | perl -n -e 'chop; print localtime( (stat($_))[9] ) . "\n";

The perl command processes each line of input (with -n option) and for each line, $_ is the input line. "chop" removes the newline character at the end of the line. "stat" retrieves the inode data from the filename (in $_). "localtime" will spit out the date/time of the file using the local timezone. (Use "gmtime" if you want it to ignore timezone settings.)

Log style date command
date '+ %b %e %T'


YYYY-MM-DD

echo `date +"%Y-%m-%d"`


Result:

2008-05-29


YYYY-MM-DD_HH_MM_SS

echo `date +"%Y-%m-%d_%H-%M-%S"`


Result:

2008-05-29_10-35-44

You can use these for creating files names of backups.

Taken from following linkdate command
Another good date link

No comments: