LoginSignup
8
8

More than 5 years have passed since last update.

ディレクトリ構造を維持しつつ特定のファイルのみコピー

Posted at

例えば /var/log 以下のログファイルを一括でコピーしたい、でも /var/log/apache2 以下は要らないや、という場合。
cp --parent を使います。

for f in $(find /var/log | grep -v 'apache2' | grep 'log$'); do
cp --parents $f ~/
done

~/ 以下に var/log ディレクトリができ、ヒットしたログのみツリー構造が維持されてコピーされます。

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8