0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cp、mv コマンドのよく使うオプションまとめ

Last updated at Posted at 2019-08-31

CentOS 7 で確認。cp と mv のバージョンは GNU coreutils 8.22。

ファイル/ディレクトリを属性を保ってコピー/移動

cp -a
mv

cp -r は属性を保存せずディレクトリをコピー。

ディレクトリを既存のディレクトリにコピー/移動しようとすると、コピー/移動元ディレクトリがコピー/移動先ディレクトリの中にコピー/移動される。

ディレクトリを既存のディレクトリにコピー/移動

-T

cp では -a-r をつける。

移動先ディレクトリの中にファイルがある場合、cp ではファイルを追加または上書き、mv ではエラー。

コピー/移動したファイルを表示

-v

SELinux のコンテキストをコピー/移動先に合わせる

-Z

コピー/移動先に同じ名前のファイルがあったら処理を尋ねる

-i

コピー/移動先に同じ名前のファイルがあったらバックアップを作成

-b

デフォルトではファイルの末尾に ~ がつく。これを変更するには -S <接尾辞> をつける。

コピー/移動先に同じ名前の新しいファイルがあったらコピー/移動しない

-u

コピー/移動先に同じ名前のファイルがあったらコピー/移動しない

-n
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?