[Watford] Bulk Rename Files

Dimitrios Siganos dimitris at siganos.org
Wed Dec 5 09:08:01 UTC 2012


Hi Rob,

The pattern *.gsm is replaced by all the filenames ending in .gsm
separated with a space. As if you typed them out one by one on one long
line. If you have a lot of files, then the line would be very big and
there are fairly small limits to how big the line can be.

For that reason, you want to find another way to pass the list of files.
Rename supports reading from stdin. So can do this instead:

ls -1 *.gsm | rename 'your_regex'

BTW, your regex looks incorrect to me. You need to do a tutorial on
regular expressions for half an hour and try again.

Regards,
Dimitris

On 05/12/12 08:36, Rob Jefferis wrote:
> Morning all, apologies for the delay in getting back on this.
> 
> Thanks very much for the replies.
> 
> I managed to find a line that worked to rename the files as I wanted
> which is, rename -v "s/^OUT???-????????-??????-//g" *.gsm
> 
> The problem i have now is that running that on the actual folder gives
> me an Argument list too long error.
> 
> When i copy files between these folders i use the line  find -iname *
> -exec cp -v {} /temp/. \; so that i am essentially copying one file at a
> time.
> 
> I have been trying to combine my 2 examples to complete my bulk rename
> but so far without much success. Any help would be appreciated.
> 
> Thanks again
> 
> Rob
> 
> 
> 
> ________________________________________
> From: watford-bounces at mailman.lug.org.uk
> [watford-bounces at mailman.lug.org.uk] on behalf of Alain Williams
> [addw at phcomp.co.uk]
> Sent: 28 November 2012 00:44
> To: watford at mailman.lug.org.uk
> Subject: Re: [Watford] Bulk Rename Files
> 
> On Tue, Nov 27, 2012 at 11:43:05PM +0000, Rob Jefferis wrote:
>> Hi guys, I have a load of files in a directory with file names similar
> to below
>>
>> OUT119-20120702-084956-1341215396.177198.gsm
>>
>> It is basically OUT(dialingextensionnumber)-DATE-TIME-UNIQUEID.gsm
>>
>> I would like to somehow bulk rename all the files in this folder to
> strip everything other than the uniqueid.gsm bit
>>
>> So in this case I want the file to end up called
>>
>> 1341215396.177198.gsm
>>
>>
>> Is there a quick way to do this?
> 
> Using ksh
> 
> for file in *.gsm
> do mv $file ${file#~(E:+(OUT+(\d)-+(\d)-+(\d)-))}
> done
> 
> The syntax is a little strange.
> 
> --
> Alain Williams
> Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer,
> IT Lecturer.
> +44 (0) 787 668 0256 http://www.phcomp.co.uk/
> Parliament Hill Computers Ltd. Registration Information:
> http://www.phcomp.co.uk/contact.php
> #include <std_disclaimer.h>
> 
> _______________________________________________
> Watford mailing list
> Watford at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/watford
> 
> 
> 
> _______________________________________________
> Watford mailing list
> Watford at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/watford
> 




More information about the Watford mailing list