View Full Version : [SOLVED] Mass renaming symlinks

May 27th, 2009, 03:51 PM
I have over 200 symlinks in a directory. Each say 'Link to' before the actual filename. How can i quickly rename each of these files so that I can strip the 'Link to' text via terminal, or even a bash script?

note *These symlinks point to files outside of this particular directory*

May 27th, 2009, 04:20 PM
throw this in a script file and run it


for file in *;
mv "$file" "`echo $file | sed 's:Link to ::'`"

Just be in the same folder.
Oh and this will name all the files in that folder. If you want to narrow it down, just play with the line "for file in *" replacing the * with your needed expression.

May 27th, 2009, 04:24 PM
You could do that with following bash oneliner:

for i in "Link to"*; do mv "$i" "$(echo "$i" | sed -e "s/Link to //")"; done

That loops through all files which begin with phrase "Link to " and assigns filename to variable i each time. Sed command is used to substitute "Link to " with empty string. Double quotes are needed to handle spaces properly.

May 27th, 2009, 04:38 PM
Thanks for the quick replies. Works Flawlessly.