Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-11-2007, 01:36 PM   #1
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Rep: Reputation: 33
Shell script "cp file file+date"

Good Day,

I need to back up file with date added at then end of file name.

I was trying some thing like this
dt=date | awk '{print $2"-"$3"-"$6}'
echo hello
echo "$dt"
cp testdate testdate'-'$dt
Off course I could not get that done.

Old 12-11-2007, 01:42 PM   #2
Senior Member
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
l_date=`date +%d%b%Y`
cp -p testdate testdate-$l_date
cp -p testdate testdate-$(date +%d%b%Y)

Last edited by Disillusionist; 12-11-2007 at 01:45 PM.
Old 12-11-2007, 04:11 PM   #3
Senior Member
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
Just a note:

I like using "date +%Y%m%d" as when you do an ls on the directory w/ a bunch of backup files it puts them in order w/ oldest first.



Last edited by forrestt; 12-12-2007 at 09:57 AM. Reason: changed last to first (brain damage?)
Old 12-12-2007, 12:19 AM   #4
Registered: Oct 2007
Location: Sydney, Australia
Distribution: Debian
Posts: 63

Rep: Reputation: 15
linux date command

more help:

linux date command
Simple backup script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 09:00 AM
Shell script: Find "\n\t..." to replace a string in a file michael24h7d Programming 8 05-11-2007 03:07 AM
shell script with "netcat > file" at boottime trajjm Programming 3 10-10-2005 06:54 AM
Creating a file like "DATE.txt" parker Programming 4 03-10-2004 04:44 AM
Monthly Archiving Script... help with "date" & "cron" Supp0rtLinux Linux - Software 3 01-03-2003 09:29 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:16 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration