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

Popular posts from this blog

Datastax Error : Cannot start node if snitch's data center (dc1) differs from previous data center (dc2)

Datastax Error : Cassandra - Saved cluster name Test Cluster != configured name

Configure Nagios plugin " check_logfiles " for scanning log file

Popular posts from this blog

Datastax Error : Cannot start node if snitch's data center (dc1) differs from previous data center (dc2)

Datastax Error : Cassandra - Saved cluster name Test Cluster != configured name

Configure Nagios plugin " check_logfiles " for scanning log file