Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-14-2010, 08:12 PM   #1
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.
Old 12-14-2010, 08:37 PM   #2
Senior Member
Registered: Apr 2010
Posts: 1,914

Rep: Reputation: 342Reputation: 342Reputation: 342Reputation: 342

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, 11:21 PM   #3
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, 11:45 PM   #4
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927
for i in file_*.grn
  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
Something like that should work; untested.

Old 12-16-2010, 01:24 PM   #5
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.
Old 12-16-2010, 08:53 PM   #6
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 18,141

Rep: Reputation: 2671Reputation: 2671Reputation: 2671Reputation: 2671Reputation: 2671Reputation: 2671Reputation: 2671Reputation: 2671Reputation: 2671Reputation: 2671Reputation: 2671
Here are some good Tutorials on bash scripting:


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

All times are GMT -5. The time now is 01:15 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration