shell scripts

How to format dates in shell scripts

date time

When using dates in a shell script, you can format them like this: $(date +[format]) Here are some examples: $(date +”%Y%m%d)20080508 ——————– $(date +”%Y-%m-%d)2008-05-08 ——————– $(date +%D) which is shorthand equivalent for $(date +”%m/%d/%Y) 05/08/2008 To include time: $(date +%r) 10:15:36 PM ——————– $(date +%T) 22:15:36 A typical date format for a log entry: $(date [...]

Read the full article →