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 10-25-2010, 12:58 AM   #1
diamond_D
Member
 
Registered: Jul 2005
Posts: 51

Rep: Reputation: 0
copy to a new directory and rename w/date stamp


Hi,

Newbie 1st post here. Trying to find the most efficient way to copy a file to a different directory and rename it with a date stamp extension. Looking to accomplish this with one command if possible.

File = make_file
Full path /home/user1/bin/scripts/make_file

would like to move to the following directory
/home/user1/bin/scripts/archive/

I'm trying to find out how to use command substitution along with the date command that when I copy the file to the archive directory it gets renamed with a time stamp extension. It should look something like "make_page_12:00:00-24-10-2010"

I've tried a few different combinations using the cp and mv commands but can't seem to get it to work the way I want to. Much thanks to anybody that can help getting this Windows sysadmin on the right track to learning this great OS.
 
Old 10-25-2010, 01:04 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
This might help:

Code:
SUFFIX=`date +%y%m%d`
MYFILE=myfile.$SUFFIX
Quote:
echo "SUFFIX: $SUFFIX, MYFILE: $MYFILE"
SUFFIX: 101024, MYFILE: myfile.101024
Type "man date" and/or "date --help" from a command line for more options, and more details.

'Hope that helps

Last edited by paulsm4; 10-25-2010 at 01:06 AM.
 
Old 10-25-2010, 08:35 AM   #3
diamond_D
Member
 
Registered: Jul 2005
Posts: 51

Original Poster
Rep: Reputation: 0
Sorry, but this is confusing me.

echo "SUFFIX: $SUFFIX, MYFILE: $MYFILE"
SUFFIX: 101024, MYFILE: myfile.101024

I was looking to accomplish this by using the mv or cp commands.
 
Old 10-25-2010, 04:49 PM   #4
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 103Reputation: 103
Quote:

mv file File_"$(date +%h-%d-%y)"


file --> File_Oct-25-10

Not sure if this is what you wanted.


Hope this helps.
 
  


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
copy to network drive preserving date/time stamp SBFree Linux - Newbie 8 07-13-2009 04:48 PM
copy and rename the existing directory using BASH script neo2k Linux - Software 3 08-20-2008 10:43 AM
date stamp file or directory name dgermann Linux - General 6 02-02-2008 04:53 PM
Rename file based on its own date/time stamp airman99 Linux - General 19 09-05-2006 07:52 AM
Rename file with date stamp MacSob Linux - General 6 09-13-2005 01:30 PM

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

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