Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Possible Duplicate:
Renaming a bunch of files with date modified timestamp at the end of the filename?

I want to move files from one folder to another folder with appending time stamp to file names.

For example, I have two files called file1 and file2 in folder f1.

I want to move these files to folder f2 as file names file1_22_jan_11:42 and file2_22_jan_11:42.

share|improve this question
add comment

marked as duplicate by jasonwryan, Renan, Gilles, Caleb, manatwork Dec 8 '12 at 16:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

If that time stamp is meant to be the modification time of the file, with GNU find and xargs, you could do:

find f1 -maxdepth 1 -mindepth 1 -printf '%p\0f2/%f_%Td_%Tb_%TH:%TM\0' |
  xargs -r0n2 echo mv

and remove echo when happy.

share|improve this answer
add comment

To copy somefile to otherplace/somefile_ with modification date appended (eg, 2012_12_06):

cp somefile otherplace/somefile_`stat --printf=%y somefile | sed -e 's/ .*//'`

Probably easiest if you put that in a script:

#!/bin/bash

suffix=_`stat --printf=%y $1 | sed -e 's/ .*//'`
cp $1 $2/$1_$suffix

Name it 'mycp' and you can go:

mycp somefile otherplace

For the stat info, see man stat.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.