Writing a shell script and I want to do something like this:
cp myfile.ext myfile.2011-06-10.ext
where 2011-06-10 is the current date.
Thoughts?
To get current date and time in Bash script, use date command. date command returns current date and time with the current timezone set in the system.
Bash Date format YYYY-MM-DD To format date in YYYY-MM-DD format, use the command date +%F or printf "%(%F)T\n" $EPOCHSECONDS . The %F option is an alias for %Y-%m-%d . This format is the ISO 8601 format.
Date command is an external bash program that allows to set or display system date and time. It also provides several formatting options. Date command is installed in all Linux distros by default. Type date command in terminal which will display current date and time.
We can use the `date` command to display or change the current date and time value of the system.
cp myfile.ext myfile.`date +%Y-%m-%d`.ext
or use shorthand format
date +%F
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With