LINUX: Link all files from one to another director

2019-01-20 23:56发布

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? :)

标签: linux ln
4条回答
不美不萌又怎样
2楼-- · 2019-01-21 00:01
ln -s /mnt/usr/lib/* /usr/lib/

I guess, this belongs to superuser, though.

查看更多
神经病院院长
3楼-- · 2019-01-21 00:08

GNU cp has an option to create symlinks instead of copying.

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

Note this is a GNU extension not found in POSIX cp.

查看更多
一纸荒年 Trace。
4楼-- · 2019-01-21 00:16

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

查看更多
姐就是有狂的资本
5楼-- · 2019-01-21 00:18

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
查看更多
登录 后发表回答