Current Date to Filename in Bash Shell
To assign current date to file name use month,date,time format like
date +%m%d%y and if You want to assign the date value to a variable follow
the date syntax format
time=$(date +%m%d%y)
or
time=`date +%m%d%y`
Some sample Examples are given below
#!/bin/bash
time=$(date +%m%d%y)
echo “Backup file of $time”
#!/bin/bash
time=$(date +%m%d%y)
musqldumb -u root -ppassword
databasename > database_$time.sql
#!/bin/bash
time=$(date +%m%d%y)
mv /var/www/filename /home/sreeraju/
cd /home/sreeraju/
tar -cvf backup_$time.tar filename
Comments
Post a comment