LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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-14-2010, 07:12 PM   #1
VickIsSlick
LQ Newbie
 
Registered: Dec 2010
Posts: 2

Rep: Reputation: 0
Question add time stamps to files


Currently I am using the following command to copy and add date and time stamp to files.
cp /home/work/file.grn /home/xfer/rename_`date +%Y%m%d%H%M%S'.grn.

If I have five files for ex: file_1.grn, file_2.grn,file_3.grn ...
can I copy those five files to a different directory and with a different file name and with date time stamp to it.

The output filenames should be rename_1_yyyymmddhhmmss.grn,rename_2_yyyymmddhhmmss.grn,rename_3_yyyymmddhhmmss.grn ...

Any inputs will be appreciated.
Thanks
Vicky
 
Old 12-14-2010, 07:37 PM   #2
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Post

hi Vicky, just an idea. if you want to copy to a lot of files to a different directory and different filename also. you might need to do a script to accomplish this. but not really sure whether it can be done using a single command line.
hope experts around here can give you more advise,
 
Old 12-14-2010, 10:21 PM   #3
barriehie
Member
 
Registered: Nov 2010
Distribution: Debian Lenny
Posts: 136
Blog Entries: 1

Rep: Reputation: 23
@OP, if this is a recurrent task then, as Vicky stated, a script would be the way to go. If you care to post the input file structure and output desired we'll have a better chance of providing a solution to your query.
 
Old 12-14-2010, 10:45 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Code:
for i in file_*.grn
do
  new=$(echo $i|sed -r 's/file_([0-9]+).*/rename_\1/')$(date +%Y%m%d%H%M%S).gen
  cp $i path/to/dir/$new
done
Something like that should work; untested.



Cheers,
Tink
 
Old 12-16-2010, 12:24 PM   #5
VickIsSlick
LQ Newbie
 
Registered: Dec 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Thank you all for your inputs, I will write a script and btw it will be my first one.
Thanks
Vicky
 
Old 12-16-2010, 07:53 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Here are some good Tutorials on bash scripting:
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
  


Reply



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
[SOLVED] Files sizes and checksums changed, but not time stamps? spockdude Linux - Security 2 11-24-2010 03:27 PM
Time Stamps for command history? WingnutOne Linux - Newbie 3 09-11-2007 08:53 AM
Time stamps following move to British Summer Time aikempshall Linux - General 2 03-30-2007 08:30 AM
Time Stamps Duplication indiancosmonaut Solaris / OpenSolaris 4 02-28-2007 10:30 AM
Samba time-stamps files incorectly k41184 Linux - Software 1 10-02-2005 08:24 AM

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

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