need to add current date in filename

Posted on 2005-05-16
Last Modified: 2009-12-16
i have a small shell script that backs up my databases. i want to change it so it adds the dats (YYYY-MM-DD) to the beggining of the filename, here it is.

/usr/local/bin/mysqldump --opt --compress -hHOST -uUSER -pPASSWORD ldww_db TABLENAME >> backups/database/TABLENAME.dat.sql    

so basically it should be

how do it do that? thanks!
Question by:qwertq
    LVL 6

    Accepted Solution

    /usr/local/bin/mysqldump --opt --compress -hHOST -uUSER -pPASSWORD ldww_db TABLENAME >> backups/database/$(date +%F).dat.sql
    LVL 38

    Expert Comment

    use the following as the file name:

    `date +%Y-%m-%d`.dat.sql


    /usr/local/bin/mysqldump --opt --compress -hHOST -uUSER -pPASSWORD ldww_db TABLENAME >> backups/database/`date +%Y-%m-%d`.dat.sql


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
    SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now