-L
を正しく理解していれば cp
の旗 コマンドは、あなたが望むことを正確に実行する必要があります。
すべてのシンボリック リンクをコピーするだけで、シンボリック リンクが指すファイルに置き換えられます。
tar を使用してデータを新しいディレクトリにコピーする方が簡単かもしれません.
-H (c and r mode only) Symbolic links named on the command line will be followed; the target of the link will be archived, not the link itself.
このようなものを使用できます
tar -hcf - sourcedir | tar -xf - -C newdir
tar --help:
-H, --format=FORMAT create archive of the given format
-h, --dereference follow symlinks; archive and dump the files they point to
「簡単」の定義について:
#!/bin/sh
set -e
for link; do
test -h "$link" || continue
dir=$(dirname "$link")
reltarget=$(readlink "$link")
case $reltarget in
/*) abstarget=$reltarget;;
*) abstarget=$dir/$reltarget;;
esac
rm -fv "$link"
cp -afv "$abstarget" "$link" || {
# on failure, restore the symlink
rm -rfv "$link"
ln -sfv "$reltarget" "$link"
}
done
リンク名を引数としてこのスクリプトを実行します。 find . -type l -exec /path/tos/script {} +
まで