Bash – Create symbolic links to files using wildcards

bashshellsymlinkwildcards

I want to create symlinks to multiple files:

ln -s dev-*.php 's/dev-(.*\.php)/$1/'

Results hoped for:  
    site.php links to dev-site.php  
    file.php links to dev-file.php

What's the most concise way to achieve this?

Best Answer

Well, if it's all in the same directory you could do something like this in bash or any other Bourne-style/POSIX shell:

for FILE in dev-*; do ln -s "$FILE" "${FILE#dev-}"; done

which would create symlinks without "dev-" to files beginning with "dev-".

Related Question