The rename command...

Rashkae ubuntu at tigershaunt.com
Mon Aug 25 14:36:16 UTC 2008


Johnny Rosenberg wrote:
> Since there is a serious bug in Nautilus, that adds the very unnecessary
> text "Link to " to a link created with Ctrl+Shift+Drag&Drop, I searched the
> Internet for a way to remove that ridiculous part of the file name, and I
> came up with this:
> 
> rename -v 's/Länk till //' *
> 
> Or, if your language is English:
> 
> rename -v 's/Link to //' *
> 
> However, there doesn't seem to be an option for recursivity built in to that
> command. I am not good with scripts, but I am sure there is a way around
> that.
> 
> What could I add to this command to also make it work in all the subfolders
> of the current folder?
> 
> J.R.
> 

You will probably need to use the find command.  Pls look in the man
page (since I'm too lazy), but there is an option in find to run a
command on the files it finds...  So you use find to find all files that
 start with Link To recursively, then apply your rename command. You
might have to escape the ' with a \ so they end up intact when the
command is run.

Alternatively, you can hack up a quick and dirty script like this:

#!/bin/bash
for i in *; rename -v 's/Link to //' $i/*; done


This will choke out errors for any files in the current directory, since
rename will try to operate on filename/* (which doesn't exist), but it
should conveniently also run your rename command in each subdirectory of
your current directory, (but not really recursive, this one only goes 1
subdirectory deep.)




More information about the ubuntu-users mailing list