How do I make a symlink to every directory in the current directory that has the same name but has u

Posted by Jason Baker on Stack Overflow See other posts from Stack Overflow or by Jason Baker
Published on 2010-05-13T19:57:39Z Indexed on 2010/05/13 20:04 UTC
Read the original article Hit count: 198

Filed under:
|

For instance, I suppose I have a directory that contains the following folders

foo_bar
baz

What I would like to have is a bash command that will make a symlink foo-bar to foo_bar so it would look like this:

foo-bar
foo_bar
baz

I'm pretty sure I can write a Python script to do this, but I'm curious if there's a way to do this with bash. Here's where I'm stuck:

ls -1 | grep _ | xargs -I {} ln -s {} `{} | sed 's/_/-/'`

What I'm trying to do is run the command ln -s with the first argument being the directory name and the second argument being that name passed through sed s/_/-/. Is there another way to do this?

© Stack Overflow or respective owner

Related posts about bash

Related posts about symlink