これが1つの可能な解決策です、ただ実行してください
mkdir "./onlylinkedfiles" && cd "./onlylinkedfiles"
tar -ch "../symlinks" | tar -x --strip-components=1
../symlinks/
そして、あなたは現在のディレクトリ内にシンボリックリンクされたすべてのファイルとdirsだけを取得しました。
一部の自動化と同じ:
cd "delete_here"
f="../symlinkshere"; mkdir ../temporary && pushd ../temporary && tar -vch "${f}" | tar -x --strip-components=1 && rm -rf "`dirs +1`" && cd .. && mv temporary "`dirs +1`" && popd
その後、現在のディレクトリには、でシンボリックリンクを取得したファイルのみが含まれます../symlinkshere/
。
それを分解しましょう:
# Specify directory where symlinks are:
f="../symlinkshere";
# Create temporary directory:
mkdir ../temporary &&
# Remember current and change cwd to temporary folder:
pushd ../temporary &&
# Copy all symlinked files and directories to cwd:
tar -vch "${f}" | tar -x --strip-components=1 &&
# Remove directory where we been when pushd called:
rm -rf "`dirs +1`" &&
# Cd out of temporary dir:
cd .. &&
# Rename temporary to original cwd
mv temporary "`dirs +1`" &&
# Go back to path where we started:
popd
簡単に使用できるシェルスクリプトは次のとおりです。
これは現在のディレクトリで機能し、シンボリックリンクへのパスである1つの引数を取ります。
cd /path/to/clean
replacebylinks.sh /here/is/symlinks/
ファイル:~/bin/replacebylinks.sh
#!/bin/bash
tmp="`mktemp -d`"
sourced="`readlink -f ${1}`"
workd="`pwd -P`"
cd "${tmp}"
tar -vchC "${sourced}" . | tar -xv --strip-components=1
rm -vrf "${workd}"
cd ..
mv -v "${tmp}" "${workd}" && cd "${workd}"
いくつかのメモ:
-v
出力が多すぎると思われる場合は、コマンドから
詳細スイッチを削除できます。- ソースディレクトリツリー全体が宛先に保持さ
tar -chC "source" .
れない
ため、使用する方がよい場合があります。-C source
絶対パスでは、これは/
ルートから始まります。