tags:

views:

650

answers:

4

I want to link ( ln -s ) all files that are in /mnt/usr/lib/ into /usr/lib/

There are lots of file, how to do it fast? :)

+7  A: 
ln -s /mnt/usr/lib/* /usr/lib/

I guess, this belongs to superuser, though.

HTH, flokra

flokra
This does not include hidden files, and it links whole directories. If either of these is not what you want, see my answer. Otherwise, it's the shortest way.
Jefromi
You're right. But libraries aren't hidden usually. In any case dotfiles are involved your solution comes in more handy.
flokra
+2  A: 

ln -s /mnt/usr/lib/* /usr/lib/

Michael Krelin - hacker
+3  A: 

The posted solutions will not link any hidden files. To include them, try this:

cd /usr/lib
find /mnt/usr/lib -maxdepth 1 -print "%P\n" | while read file; do ln -s "/mnt/usr/lib/$file" "$file"; done

If you should happen to want to recursively create the directories and only link files (so that if you create a file within a directory, it really is in /usr/lib not /mnt/usr/lib), you could do this:

cd /usr/lib
find /mnt/usr/lib -mindepth 1 -depth -type d -printf "%P\n" | while read dir; do mkdir -p "$dir"; done
find /mnt/usr/lib -type f -printf "%P\n" | while read file; do ln -s "/mnt/usr/lib/$file" "$file"; done
Jefromi
I believe this should also work as a way to wildcard in hidden files, if you have extended globbing turned on in bash. It matches everything starting with a dot, followed by something other than nothing or another dot (i.e. it excludes `./` and `../`): `ln -s /mnt/usr/lib/.!(|.)* /usr/lib`
Jefromi
+4  A: 

cp has an option to create symlinks instead of copying.

cp -rs /mnt/usr/lib /usr/
caf