LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 11-15-2010, 02:46 AM   #1
einy
LQ Newbie
 
Registered: Mar 2010
Posts: 2

Rep: Reputation: 0
Date as a directory name


Hello,

Everyday I need to make a backup of certain files on my system (I have set up cron job for this).

Can I somehow put a formatted current data as an argument for "cp" command? E.g. I would like to run a "cp ... /backup/2010_12_01" on December, 1st.

As of now, it seems easier for me to write a perl script for this, but I am sure there is an elegant commandline solution for this, can you tech me?

Thank you!
 
Old 11-15-2010, 02:58 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
The date command can generate that and command substitution can make the string available to the mkdir command.
 
Old 11-15-2010, 03:05 AM   #3
einy
LQ Newbie
 
Registered: Mar 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Thank you! Can I ask your for an exmaple?
 
Old 11-15-2010, 05:04 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by einy View Post
Thank you! Can I ask your for an exmaple?
You could but you would learn more by looking at the date man page and command substitution and netsearching if they are not enough.

Please ask again if you get stuck and show what you have tried.
 
Old 11-15-2010, 10:42 AM   #5
whk
Member
 
Registered: Jun 2005
Posts: 202

Rep: Reputation: 35
Another way to skin a cat is an alias.
alias dt="date +'%Y_%m_%e'"

hth

Addendum
Make a directory with backup/<with today's date>
alias bdt='echo "$(mkdir -p backup/$(dt))"'

A word to the wise:
careful with abbrev's cause you might tend to forget them.
I do. heh
Also make full instructions,readmes and/or logs on your work.

Last edited by whk; 11-15-2010 at 11:53 AM.
 
  


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
Trying to make a directory with mkdir using the date command. Altheastronut Linux - General 5 06-09-2009 01:14 PM
grep a directory with date order ust Linux - Newbie 4 02-16-2009 03:17 AM
date stamp file or directory name dgermann Linux - General 6 02-02-2008 05:53 PM
How to find the date for all the files in a directory Uday123 AIX 6 02-23-2006 09:26 PM
backup from date keep directory structure secretlydead Linux - General 1 09-30-2005 04:51 PM

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

All times are GMT -5. The time now is 05:25 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