Sometimes, I need to make a symbolic link to each of quite many files, I can write a perl or python script for that. I'm learning the shell script but I cannot write something effectively with it till the moment. However, I found out that I can do the job by two lines of commands.
For example, I have many files ending with .so.1.0.0
First I make a link to each file by giving the name of the link an additional .link based on the original filename:
find . -type f -exec ln -s '{}' '{}'.link \;or with xargs if there are too many files to handle:
find . -type f | xargs -t -l1 -i ln -s '{}' '{}'.linkSo I have many links ending with .so.1.0.0.link
A small problem here with xargs, I can add prefix or postfix but not modify the actual name, what I needed is a shorter name, in order to do that, I use rename to change the name as I wanted, a name shorter than the original file name.
rename 's/\.1.0.0.link//' *this will rename all the links I have created with name .so.1.0.0.link to .so, the 1.0.0.link is removed.
I'll give discuss each of them in more details later.
No comments:
Post a Comment