スポンサーリンク

【Linux】特定のディレクトリ以外をコピーする

$ cp -pr /parent/ /new_parent/

「/parent/children1」をコピーしたくないとする

上記のcpコマンドだとできないのでrsyncコマンドを使う

 

$ rsync -a /parent/ /new_parent/ –exclude ‘/children1/’

# –excludeに指定するパスは/parent/を起点としたものとなる

つまり/parent/children1/でparentの中にあるので/children1/となる

 

 

ちなみに指定したディレクトリ配下ではなく、指定したディレクトリごとコピーしたい場合は以下となる

$ rsync -a /parent /new_parent/ –exclude ‘/children1/’

($ cp /parent/ /new_parent/)

ここはrsyncの仕様の話だが注意しとく

 

コメント

タイトルとURLをコピーしました