LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   copy to a new directory and rename w/date stamp (https://www.linuxquestions.org/questions/linux-newbie-8/copy-to-a-new-directory-and-rename-w-date-stamp-840246/)

diamond_D 10-25-2010 12:58 AM

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.

paulsm4 10-25-2010 01:04 AM

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

diamond_D 10-25-2010 08:35 AM

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.

jv2112 10-25-2010 04:49 PM

Quote:


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


file --> File_Oct-25-10


Not sure if this is what you wanted.


Hope this helps.


All times are GMT -5. The time now is 11:45 PM.