Re: [SLUG] bash problem - renaming files with their time stamp
quote who=david ls | while read file; do ls? Madness. Use find(1). :-) Why? does that overcome the bash size limitation? Sure. Whether you use find -exec (bleah) or find | while read or find | xargs, you won't have any problems with bash size limitations. - Jeff -- Open CeBIT 2007: Sydney, Australia http://www.opencebit.com.au/ There's always a new bogeyman - every two months, there's a new axe to add to the axis of evil. - Michael Moore -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] bash problem - renaming files with their time stamp
On Sat, 2007-01-20 at 18:45 +1100, Jeff Waugh wrote: quote who=Del So the way around that is, when you hit that problem, replace this: for file in *; do with this: ls | while read file; do ls? Madness. Use find(1). :-) Why? does that overcome the bash size limitation? -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] bash problem - renaming files with their time stamp
quote who=Del So the way around that is, when you hit that problem, replace this: for file in *; do with this: ls | while read file; do ls? Madness. Use find(1). :-) - Jeff -- Open CeBIT 2007: Sydney, Australia http://www.opencebit.com.au/ ASCII stupid question, get a stupid ANSI. -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
[SLUG] bash problem - renaming files with their time stamp
A directory with files of unknown names. I want to rename each seperate file with it's date/time thus: -rw-r--r-- 1 david david 105 2007-01-19 11:20 test becomes -rw-r--r-- 1 david david 105 2007-01-19 11:20 200701191120 I've been messing with it for a few hours, and I'm sure it's simple but I'm not getting there. Any help appreciated. David. -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] bash problem - renaming files with their time stamp
david wrote: A directory with files of unknown names. I want to rename each seperate file with it's date/time thus: -rw-r--r-- 1 david david 105 2007-01-19 11:20 test becomes -rw-r--r-- 1 david david 105 2007-01-19 11:20 200701191120 I've been messing with it for a few hours, and I'm sure it's simple but I'm not getting there. Hooray for Friday afternoon scripting fun! This isn't pretty, but will probably work[*]. Except on files with spaces. for file in `ls`; do date=`ls -l --time-style=long-iso $file | awk '{ print $6 $7 }' newname=`date -d $date +%Y%m%d%H%M` mv $file $newname * Only partially tested. Your mileage liable to variance. -- Pete -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] bash problem - renaming files with their time stamp
Peter Hardy wrote: for file in `ls`; do date=`ls -l --time-style=long-iso $file | awk '{ print $6 $7 }' newname=`date -d $date +%Y%m%d%H%M` mv $file $newname Er, that should be awk '{ print $6 $7 }' * Only partially tested. Your mileage liable to variance. ...told you so. -- Pete -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] bash problem - renaming files with their time stamp
Peter Hardy wrote: Peter Hardy wrote: for file in `ls`; do date=`ls -l --time-style=long-iso $file | awk '{ print $6 $7 }' newname=`date -d $date +%Y%m%d%H%M` mv $file $newname Er, that should be awk '{ print $6 $7 }' * Only partially tested. Your mileage liable to variance. ...told you so. What if you have two files with the same timestamp. What do you wish to happen? -rw -- _ Rick Welykochy || Praxis Services The 7 R's of Windows support: retry, restart, reboot, reconfigure, reinstall, reformat and finally, replace with Linux. -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] bash problem - renaming files with their time stamp
On Fri, Jan 19, 2007 at 02:58:16PM +1100, Rick Welykochy wrote: Peter Hardy wrote: Peter Hardy wrote: for file in `ls`; do date=`ls -l --time-style=long-iso $file | awk '{ print $6 $7 }' newname=`date -d $date +%Y%m%d%H%M` mv $file $newname Er, that should be awk '{ print $6 $7 }' * Only partially tested. Your mileage liable to variance. ...told you so. What if you have two files with the same timestamp. What do you wish to happen? change mv to mv $file $newname.$file -rw -- _ Rick Welykochy || Praxis Services The 7 R's of Windows support: retry, restart, reboot, reconfigure, reinstall, reformat and finally, replace with Linux. -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html signature.asc Description: Digital signature -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] bash problem - renaming files with their time stamp
Peter Hardy [EMAIL PROTECTED] writes: Hooray for Friday afternoon scripting fun! This isn't pretty, but will probably work[*]. Except on files with spaces. Here's my very minor contribution. If you change for file in `ls`; do to for file in *; do It should handle spaces date=`ls -l --time-style=long-iso $file | awk '{ print $6 $7 }' I don't see a closing back tick. -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] bash problem - renaming files with their time stamp
Michael Chesterton wrote: Here's my very minor contribution. If you change for file in `ls`; do to for file in *; do It should handle spaces Oh, cool. I seem to recall having problems with the for file in * construct, but I don't remember what they were, so I'll try it again next time I want a for loop. date=`ls -l --time-style=long-iso $file | awk '{ print $6 $7 }' I don't see a closing back tick. You're right. I guess this is why I debug scripts before expecting them to do anything important. -- Pete -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] bash problem - renaming files with their time stamp
Peter Hardy wrote: Oh, cool. I seem to recall having problems with the for file in * construct, but I don't remember what they were, so I'll try it again next time I want a for loop. The problem you'll have with for file in * is that when you have a ridiculously large number of files in a directory you will find that the maximum size of a command line is exceeded by *. So the way around that is, when you hit that problem, replace this: for file in *; do do_something_with $file done with this: ls | while read file; do do_something_with $file done ... the latter is a smudge less efficient, however. -- Del Babel Com Australia http://www.babel.com.au/ ph: 02 9368 0728 fax: 02 9368 0758 -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] bash problem - renaming files with their time stamp
On Fri, 2007-01-19 at 15:38 +1100, Del wrote: Peter Hardy wrote: Oh, cool. I seem to recall having problems with the for file in * construct, but I don't remember what they were, so I'll try it again next time I want a for loop. The problem you'll have with for file in * is that when you have a ridiculously large number of files in a directory you will find that the maximum size of a command line is exceeded by *. So the way around that is, when you hit that problem, replace this: for file in *; do do_something_with $file done with this: ls | while read file; do do_something_with $file done ... the latter is a smudge less efficient, however. -- Less efficient is OK... especially since there is likely to be a very large number of files (100's?) so that may be a problem. As to two files with the same timestamp, it will serve them right for not keeping their distance. ;-) ... but in reality, the files are being created sequentially by another script with a 2 second sleep, so that *should* never happen. Thanks everyone.. time to go test. David. -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html