好的,所以我一直试图解决这个问题,但我很挣扎。
前提是:我有一个包含许多子目录的目录(其中一些还包含更多子目录),并且我在另一个共享上有另一个单独的目录,它模仿布局中的源目录。我现在需要的是一种循环源目录,发现子目录中的文件,然后在目标目录中为它们创建符号链接的方法。
如果不是很清楚,这篇文章描述得相当不错,除了那个问题是针对符号化的dirs而不是文件本身。
编辑:刚刚注意到Kerrek的目的,忘记包含此链接:Bash script to automatically create symlinks to subdirectories in a tree
好的,到目前为止,基于Kerrek的答案,我有这个:
#!/bin/bash
SOURCE="/home/simon/testdir/src"
DEST="/home/simon/testdir/dest"
cd $DEST
find $SOURCE -type f -exec ln -s -- "{}" "{}" \;
exit
给出以下内容:
ln: creating symbolic link `/home/simon/testdir/src/new.dir/a': File exists
ln: creating symbolic link `/home/simon/testdir/src/new.dir/b': File exists
ln: creating symbolic link `/home/simon/testdir/src/new.dir/c': File exists
但是,它实际上并没有在目标目录中创建符号链接。
答案 0 :(得分:5)
如何使用find
?
cd -- "$SOURCEDIR"
find -type d -exec mkdir --parents -- "$DESTDIR"/{} \;
find -type f -exec ln --symbolic -- "$SOURCEDIR"/{} "$DESTDIR"/{} \;