Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
rename files to filedate and filetime
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
tam
Guru
Guru


Joined: 04 Mar 2003
Posts: 569

PostPosted: Thu Jan 06, 2005 12:39 pm    Post subject: rename files to filedate and filetime Reply with quote

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
View user's profile Send private message
papal_authority
Veteran
Veteran


Joined: 31 Mar 2004
Posts: 1823
Location: Canada

PostPosted: Thu Jan 06, 2005 5:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
tam
Guru
Guru


Joined: 04 Mar 2003
Posts: 569

PostPosted: Sun Jan 09, 2005 11:28 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum