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
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)
我想,这属于超级用户。
I guess, this belongs to superuser, though.
GNU cp 可以选择创建符号链接而不是复制。
请注意,这是在 POSIX
cp
中找不到的 GNU 扩展 。GNU
cp
has an option to create symlinks instead of copying.Note this is a GNU extension not found in POSIX
cp
.发布的解决方案不会链接任何隐藏文件。要包含它们,请尝试以下操作:
如果您碰巧想要递归地创建目录并且仅链接文件(这样,如果您在目录中创建文件,它实际上位于
/usr/lib
中,而不是/mnt/usr/lib
),你可以这样做:The posted solutions will not link any hidden files. To include them, try this:
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: