Thanks Ahamed,
I have to do this as a postprocessing script after receiving the zip archive,
I can't rename all contents of the directory because of it's a shared directory
1- unzip file.zip
2- for each file in zip archive "append filename+ current timestamp"
3- for each file created in last step create a copy/touch with trg file extention "filename+ current timestamp.trg"
4- results will be in a shared directory
This will rename all the files inside the test directory which will get created once you unzip the file with the current time stamp.
Then it will create a copy of each file with the extenstion .trg
Once done, you can move all the files to the shared folder or wherever you want.
unzip test.zip
cd test
rename "s/\./_$(date +%H%M%S)\./" *
ls | xargs -l sh -c 'cp $0 ${0%.*}.trg'
unfortunately on my box i found util versione of "rename", so i found this code;
for file in *.zip
do
mv $file ${file}`date +%Y%m%d'
done
ls | xargs -l sh -c 'cp $0 ${0%.*}.trg'
but if my process launchs two instance of script after of reception of two seperate .zip archive, under my work dir i will have two set of file, how can i determine which file belongs to first script invocation and which group belongs to second instance of script, any idea, thanks anyway Ahamad
'mv' with a destination inside the same folder should be atomic. Only one will end up renaming the file, the other will harmlessly say 'no such file or directory'.
The following code when run from the directory where the zip files exists will
For all the zip files
unzip the file
cd to the unzipped folder
rename the file with timestamp
create a copy of the renamed file with the extension .trg
for file in *.zip; do
unzip $file
cd ${file%.*}
for fl in *; do
ext=${fl##*.}
new_fl=${fl/.*/}_$(date +%Y%m%d)$ext
mv $fl $new_fl
cp $new_fl ${new_fl/.*/.trg}
done
cd ../
done