LINUX:将所有文件从一个目录链接到另一个目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1347105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 17:39:22  来源:igfitidea点击:

LINUX: Link all files from one to another directory

linuxln

提问by

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

我想将 ( ln -s) 中的所有文件链接/mnt/usr/lib//usr/lib/

There are lots of files, how can it be done quickly? :)

文件很多,如何快速完成?:)

回答by

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

I guess, this belongs to superuser, though.

不过,我想这属于超级用户。

回答by Michael Krelin - hacker

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

回答by Cascabel

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/libnot /mnt/usr/lib), you could do this:

如果您碰巧想要递归创建目录并且只链接文件(这样如果您在目录中创建一个文件,它确实在/usr/libnot 中/mnt/usr/lib),您可以这样做:

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

回答by caf

GNU cphas an option to create symlinks instead of copying.

GNUcp可以选择创建符号链接而不是复制。

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

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

请注意,这是在 POSIX 中cp找不到的 GNU 扩展。