View previous topic :: View next topic |
Author |
Message |
tam Guru
Joined: 04 Mar 2003 Posts: 569
|
Posted: Thu Jan 06, 2005 12:39 pm Post subject: rename files to filedate and filetime |
|
|
Hi!
I'm looking for a program or script which will rename mulitple file in a directory and its subdirectories to their timestamp.
For example these files
Code: |
-rw-r--r-- 1 tam users 66028 2005-01-06 00:04:25.000000000 +0100 std.vcf_4
-rw-r--r-- 1 tam users 66028 2004-12-31 17:48:06.000000000 +0100 std.vcf_5
|
sould be renamed to
Code: |
-rw-r--r-- 1 tam users 66028 2005-01-06 00:04:25.000000000 +0100 2005-01-06_00:04:25
-rw-r--r-- 1 tam users 66028 2004-12-31 17:48:06.000000000 +0100 2004-12-31_17:48:06
|
|
|
Back to top |
|
|
papal_authority Veteran
Joined: 31 Mar 2004 Posts: 1823 Location: Canada
|
Posted: Thu Jan 06, 2005 5:09 pm Post subject: |
|
|
Why not just write a script? Something like this maybe?
Code: | #!/bin/sh
for OLD in `ls -1`
do
if [ -f "$OLD" ]
then
NEW=`ls -aFlq $OLD | cut -c35-46 | tr " " "_"`
mv $OLD $NEW
fi
done |
It only does the files in the current directory but it'd be easy enough to hack... _________________ The free market gave me gonorrhea. |
|
Back to top |
|
|
tam Guru
Joined: 04 Mar 2003 Posts: 569
|
Posted: Sun Jan 09, 2005 11:28 am Post subject: |
|
|
Thanks. Here's my script
Code: | #!/bin/bash
clear
bbdir="/var/tmp/bigbrother/"
rm -rf $bbdir*/C*
c=0
for i in `find $bbdir -name "D*" -type f`; do
let c=c+1
newname=`ls --full-time $i | awk ' {print $6 "_" $7}' | cut -b -19`
dir=${i%/*}
mv "$i" "$dir/$newname.$c"
done
|
|
|
Back to top |
|
|
|