LinuxQuestions.org
Visit Jeremy's Blog.
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 01-21-2013, 11:35 AM   #1
miros84
Member
 
Registered: Aug 2009
Location: Spain
Distribution: Debian stable, squeeze
Posts: 501

Rep: Reputation: 31
Problem with variable date


I try to use one line command to copy file with date and I cannot get it works. Any idea what is my error?

Code:
rsync -r /home/user/test /home/user2/backup'date +%D'
I want to copy file test to folder user2 and change name to backup+date.

But I dont want to use variable and more then one line command. What's wrong to command above?
 
Old 01-21-2013, 11:44 AM   #2
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

Rep: Reputation: 135Reputation: 135
Try this:

Quote:
rsync -r /home/user/test /home/user2/backup-`date +%F`

Use backtick(``) instead of quote, which is used for command substitution.

And %D will output with / chracter and with that a folder cant be created, so try with %F or any other combonation, you can find from man date.
 
2 members found this post helpful.
Old 01-21-2013, 11:51 AM   #3
miros84
Member
 
Registered: Aug 2009
Location: Spain
Distribution: Debian stable, squeeze
Posts: 501

Original Poster
Rep: Reputation: 31
Well, problem was really /
I tried with %D and %c and therefore I got errors.
But example you gave me doesnot work. It created a folder named
Code:
date +%F
What work for me is:
Code:
/backup$(date +%m%d)

Last edited by miros84; 01-21-2013 at 11:52 AM.
 
Old 01-21-2013, 11:57 AM   #4
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by miros84 View Post
Well, problem was really /
I tried with %D and %c and therefore I got errors.
But example you gave me doesnot work. It created a folder named
Code:
date +%F
What work for me is:
Code:
/backup$(date +%m%d)
Yes , both backtick(``) and $() are used for command substitution. You can use anyone.
 
Old 01-21-2013, 11:58 AM   #5
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,158
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
Code:
echo rsync -r /home/user/test /home/user2/backup-`date +%F` 
rsync -r /home/user/test /home/user2/backup-2013-01-21
echo is a wonderful thing.
 
1 members found this post helpful.
  


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
Problem with loading date into variable boumphreyfr Linux - Newbie 10 05-09-2011 02:27 PM
Need variable for yesterday's date stefaandk Programming 8 01-28-2007 11:50 PM
date variable user52 Linux - Newbie 2 11-28-2006 09:48 AM
Find variable in template file replace w/date+ and save as jmanjohn61 Linux - General 14 12-13-2004 07:49 AM
Setting environment variable to current date/time nafan Programming 1 08-23-2004 10:04 PM


All times are GMT -5. The time now is 06:48 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration