1

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.

kumar
  • 11

2 Answers2

1

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.

0

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.

goldilocks
  • 87,661
  • 30
  • 204
  • 262