LINUX: Link all files from one to another directory [closed]

ε祈祈猫儿з 提交于 2019-11-27 09:06:47

问题


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


回答1:


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

I guess, this belongs to superuser, though.




回答2:


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.




回答3:


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



回答4:


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


来源:https://stackoverflow.com/questions/1347105/linux-link-all-files-from-one-to-another-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!