LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 12-11-2007, 01:36 PM   #1
knockout_artist
Member
 
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
Code:
dt=date | awk '{print $2"-"$3"-"$6}'
echo hello
echo "$dt"
cp testdate testdate'-'$dt
Off course I could not get that done.

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

Rep: Reputation: 98
Try:
Code:
l_date=`date +%d%b%Y`
cp -p testdate testdate-$l_date
or:
Code:
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
forrestt
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.

HTH

Forrest

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
LlNUX
Member
 
Registered: Oct 2007
Location: Sydney, Australia
Distribution: Debian
Posts: 63

Rep: Reputation: 15
linux date command

more help:

linux date command
Simple backup script
 
  


Reply


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:47 AM.

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