Usage: cp [OPTION]... [-T] SOURCE DEST
or: cp [OPTION]... SOURCE... DIRECTORY
or: cp [OPTION]... -t DIRECTORY SOURCE...
SOURCE から DEST へ、或いは FILE (複数可)を DIRECTORY へコピーする。
長いオプションに必須の引数は短いオプションにも必須です.
-a, --archive same as -dR --preserve=all
--backup[=CONTROL] make a backup of each existing destination file
-b like --backup but does not accept an argument
--copy-contents copy contents of special files when recursive
-d same as --no-dereference --preserve=links
-f, --force if an existing destination file cannot be
opened, remove it and try again (redundant if
the -n option is used)
-i, --interactive prompt before overwrite (overrides a previous -n
option)
-H follow command-line symbolic links in SOURCE
-l, --link link files instead of copying
-L, --dereference always follow symbolic links in SOURCE
-n, --no-clobber do not overwrite an existing file (overrides
a previous -i option)
-P, --no-dereference never follow symbolic links in SOURCE
-p same as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST] preserve the specified attributes (default:
mode,ownership,timestamps), if possible
additional attributes: context, links, xattr,
all
-c same as --preserve=context
--no-preserve=ATTR_LIST don't preserve the specified attributes
--parents use full source file name under DIRECTORY
-R, -r, --recursive copy directories recursively
--reflink[=WHEN] control clone/CoW copies. See below.
--remove-destination remove each existing destination file before
attempting to open it (contrast with --force)
--sparse=WHEN control creation of sparse files. See below.
--strip-trailing-slashes remove any trailing slashes from each SOURCE
argument
-s, --symbolic-link make symbolic links instead of copying
-S, --suffix=SUFFIX override the usual backup suffix
-t, --target-directory=DIRECTORY copy all SOURCE arguments into DIRECTORY
-T, --no-target-directory treat DEST as a normal file
-u, --update copy only when the SOURCE file is newer
than the destination file or when the
destination file is missing
-v, --verbose explain what is being done
-x, --one-file-system stay on this file system
-Z, --context=CONTEXT set security context of copy to CONTEXT
--help この使い方を表示して終了
--version バージョン情報を表示して終了
By default, sparse SOURCE files are detected by a crude heuristic and the
corresponding DEST file is made sparse as well. That is the behavior
selected by --sparse=auto. Specify --sparse=always to create a sparse DEST
file whenever the SOURCE file contains a long enough sequence of zero bytes.
Use --sparse=never to inhibit creation of sparse files.
When --reflink[=always] is specified, perform a lightweight copy, where the
data blocks are copied only when modified. If this is not possible the copy
fails, or if --reflink=auto is specified, fall back to a standard copy.
バックアップ接尾辞は、--suffix や SIMPLE_BACKUP_SUFFIX が設定されないと `~' に
なります。バージョン管理方法は --backup オプションや VERSION_CONTROL 環境変数
を通じて選択できます。以下がその際の値です:
none, off バックアップを作らない (--backup をつけた時でも)
numbered, t 番号つきバックアップを作成する
existing, nil 番号つきバックアップがあれば番号つき、
そうでなければ、simple で
simple, never 常に簡易バックアップを作成
特別な場合として、cp は -f と -b オプションが与えられ、SOURCE と DEST が
同一ファイルである時は、SOURCE のバックアップを作成する。
Report cp bugs to bug-coreutils@gnu.org
GNU coreutils home page:
Usage: cp [OPTION]... [-T] SOURCE DEST
or: cp [OPTION]... SOURCE... DIRECTORY
or: cp [OPTION]... -t DIRECTORY SOURCE...
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.
-a, --archive same as -dR --preserve=all
--backup[=CONTROL] make a backup of each existing destination file
-b like --backup but does not accept an argument
--copy-contents copy contents of special files when recursive
-d same as --no-dereference --preserve=links
-f, --force if an existing destination file cannot be
opened, remove it and try again (redundant if
the -n option is used)
-i, --interactive prompt before overwrite (overrides a previous -n
option)
-H follow command-line symbolic links in SOURCE
-l, --link link files instead of copying
-L, --dereference always follow symbolic links in SOURCE
-n, --no-clobber do not overwrite an existing file (overrides
a previous -i option)
-P, --no-dereference never follow symbolic links in SOURCE
-p same as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST] preserve the specified attributes (default:
mode,ownership,timestamps), if possible
additional attributes: context, links, xattr,
all
-c same as --preserve=context
--no-preserve=ATTR_LIST don't preserve the specified attributes
--parents use full source file name under DIRECTORY
-R, -r, --recursive copy directories recursively
--reflink[=WHEN] control clone/CoW copies. See below.
--remove-destination remove each existing destination file before
attempting to open it (contrast with --force)
--sparse=WHEN control creation of sparse files. See below.
--strip-trailing-slashes remove any trailing slashes from each SOURCE
argument
-s, --symbolic-link make symbolic links instead of copying
-S, --suffix=SUFFIX override the usual backup suffix
-t, --target-directory=DIRECTORY copy all SOURCE arguments into DIRECTORY
-T, --no-target-directory treat DEST as a normal file
-u, --update copy only when the SOURCE file is newer
than the destination file or when the
destination file is missing
-v, --verbose explain what is being done
-x, --one-file-system stay on this file system
-Z, --context=CONTEXT set security context of copy to CONTEXT
--help display this help and exit
--version output version information and exit
By default, sparse SOURCE files are detected by a crude heuristic and the
corresponding DEST file is made sparse as well. That is the behavior
selected by --sparse=auto. Specify --sparse=always to create a sparse DEST
file whenever the SOURCE file contains a long enough sequence of zero bytes.
Use --sparse=never to inhibit creation of sparse files.
When --reflink[=always] is specified, perform a lightweight copy, where the
data blocks are copied only when modified. If this is not possible the copy
fails, or if --reflink=auto is specified, fall back to a standard copy.
The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable. Here are the values:
none, off never make backups (even if --backup is given)
numbered, t make numbered backups
existing, nil numbered if numbered backups exist, simple otherwise
simple, never always make simple backups
As a special case, cp makes a backup of SOURCE when the force and backup
options are given and SOURCE and DEST are the same name for an existing,
regular file.
Report cp bugs to bug-coreutils@gnu.org
GNU coreutils home page:
CP(1) CP(1) 名前 cp - ファイルやディレクトリをコピーする 書式 cp [options] file path cp [options] file... directory POSIX オプション: [-fipRr] GNU オ プション (簡略形式): [-abdfilprsuvxHLPR] [-S SUFFIX] [-V {num- bered,existing,simple}] [--remove-destination] [--sparse=WHEN] [--strip-trailing-slashes] [--target-directory=DIR] [--help] [--ver- sion] [--] 説明 cp はファイル (あるいはそのように指定すればディレクトリ) をコピーする。 1 つのファイルを指定先にコピーしたり、複数のファイルを指定ディレクトリ にコピーしたりできる。 最後の引き数が既に存在するディレクトリを指している場合、 cp はコピー 元 の file をそれぞれ (同じ名前のまま) そのディレクトリにコピーする。 2 つ のファイルだけが指定された場合、 1 つ目のファイルを 2 つ目のファイル に コピーする。最後の引き数がディレクトリでなく、 2 つ以上のオプションでな い引き数が与えられた場合はエラーになる。 (したがって ‘cp -r /a /b’ とすると、 /b が存在する場合は /a を /b/a に 、 /a/x を /b/a/x にコピーする。しかしコピー前に /b がない場合は /a を /b に、/a/x を /b/x にコピーする。) 作られたファイルとディレクトリのモードは、まずオリジナルファイルのモ ー ド と同じものにされ、 0777 との AND をとられ、ユーザーの umask のビット が引かれる (-p オプションが指定された場合を除く)。 (しかし再帰コピー の 最 中 に は、新しく作られたディレクトリの最終モードに、一時的に S_IRWXU (0700) が OR される。こればプロセスがこれらの新しく作られたディレクトリ の読み出し・書き込み・検索のプロセスを可能にするためである。) フ ァイルをそれ自身にコピーしようとした場合、 (エラーメッセージを出す以 外は) 何もしない。既存のファイルにコピーする場合、コピー先のファイル は ‘open(path, O_WRONLY | O_TRUNC)’ で開かれる。新規ファイルにコピーする場 合、新規ファイルは ‘open(path, O_WRONLY | O_CREAT, mode)’ で作成され る 。 コピー先のファイルが存在し、かつ -f オプションが与えられている場合に この形式でのファイルのオープンに失敗すると、 cp は既存のファイルの削 除 (もしくはアンリンク) を試みる。そして、削除に成功した場合は新規ファイル へのコピーとして命令を続行する。 再帰的にコピーする場合、デフォルトでは cp はシンボリックリンクを辿る だ けである (-dHL オプションを参照)。 POSIX オプション POSIX では、以下のオプションを認識する。 -f 必要であれば、既存のコピー先のファイルを削除する (上記参照)。 -H コマンドラインで指定された全てのシンボリックリンクを辿る。 -i コピー先に既に存在するファイルを上書きするかを問い合わせてくる。 (問い合わせは標準エラーに書かれ、返答は標準入力から読まれる。 上 書きを肯定する返答があった場合のみコピーされる。) -L シンボリックリンクを辿り、それが指しているファイルをコピーまたは 上書きする。 -p オリジナルファイルの所有者・グループ・アクセス権・アクセス時刻を 保存する (以下の --preserve を参照)。 -R ディレクトリを再帰的にコピーし、一般のファイルでもなくディレクト リでもないものに対してはそれに相応したコピーをする。 (たと え ば FIFO とスペシャルファイルのコピーは、それぞれ FIFO とスペシャル ファイルにされる。) -r ディレクトリを再帰的にコピーするが、一般のファイルでもなくディレ クトリでもないものに対してどうするかは規定されていない。 (したが って -r オプションを -R オプションの単なる別名にすることも可能で ある (実は推奨されている)。しかし、現在の GNU 版の cp のような単 純な動作 (下記参照) も禁止されていない。) GNU 詳細 通常、ファイルは読まれた通りに書き出される。 --sparse オプションの場 合 は例外であるので下記を参照すること。 デフォルトでは、‘cp’ はディレクトリのコピーを行わない (以下の -r オプシ ョンを見よ)。 cp はファイルのそれ自身へのコピーを通常は拒否するが、次のような例外があ る : --force --backup が指定されていて、 コピー元と コピー先が同一で、 通常のファイルを参照している場合には、 cp はバックアップファイルを作 る 。 バックアップファイル名には通常または番号付きの拡張子が、通常の場合と 同じように付く。これは、既に存在するファイルを変更前に単純にバックア ッ プしたい場合に有用である。 GNU オプション -a, --archive コピー先で、できる限り元のファイルの構成と属性を保持する (ディレ クトリ構造体は保存しない)。 -dpR と同じ。 -d, --no-dereference シンボリックリンクをコピーする場合、シンボリックリンクが指してい るファイルをコピーするのではなく、シンボリックリンクとしてコピー する。また、コピー元でのハードリンクはコピー先でもハードリンクと して保持される。 -f, --force コピー先のファイルを書き込みまたはアンリンクするため、ファイルを オープンしようとする。失敗した場合、途中で中止することなくデフォ ルトの動作を行う。 --remove-destination を参照。 -i, --interactive コピー先に上書きされる通常のファイルが存在する場合、上書きの可否 を問い合わせてくる。 -l, --link コピーする代わりにハードリンクを作る (ただし、ディレクトリ以 外) 。 -L, --dereference シンボリックリンクを辿り、それが指しているファイルをコピーまたは 上書きする。 -p, --preserve オリジナルファイルの所有者・グループ・アクセス権 (setuid, setgid ビ ットを含む)・最終修正時刻・最終アクセス時刻を保存する。所有者 やグループの複製に失敗した場合には、 setuid ビットと setgid ビッ トはクリアされる。 (この場合コピー元とコピー先の最終アクセス時刻 が異なってしまうことに注意。コピー操作はコピー元ファイルへのアク セスであるから。) -P, --parents コピー先のファイル名の作り方を「コピー先ディレクトリにスラッシュ (/) とコピー元ファイルの名前を加える」とする。 cp の最後の引き数 は既に存在するディレクトリでなければならない。たとえば、 cp --parents a/b/c existing_dir というコマンドは ‘a/b/c’というファイルを ‘existing_dir/a/b/c’ に (途中のディレクトリがない場合はそれも作って) コピーする。 -r ディレクトリを再帰的にコピーする。(FIFO やスペシャルファイルとい った) ディレクトリでもなくシンボリックリンクでもないものを通常の ファイルとしてコピーする。この場合 cp はコピー元ファイルからデー タが読み込み、コピー先に書き出そうとする。よくある間違いは、 ‘cp -r’ をスペシャルファイル、 FIFO、‘/dev’ ディレクトリ以下にあるも の に 対して使うことである。多くの場合、cp は FIFO や ‘/dev/con- sole’ といったスペシャルファイルから読み込もうとして永久にハング し たり、 ‘/dev/zero’ をコピーしようとしてコピー先ディスクを溢れ させたり、不明なディバイスを開いてハードウェアによくわからない効 果を及ぼしてしまったりする。スペシャルファイルの内容をコピーする のでなく、スペシャルファイルをその特性を保持したままコピーしたい 場合は、 --recursive または -R オプションを使うこと。 --remove-destination フ ァ イ ル を 書 き込みオープンするのではなく、アンリンクする。 --force を参照。 -R, --recursive ディレクトリでないものを保存しつつ、ディレクトリを再帰的にコピー する (すぐ上の -r オプションを見よ)。 --sparse=WHEN 「スパースなファイル」とは「ホール( 穴 )」 (物理ディスクブロック を占有しないゼロバイトの連続) を含むものである。 read システムコ ールはそれらのファイルをゼロとして読み込む。多くのバイナリファイ ルにはゼロバイトの並びがたくさん含まれているので、このオプション により、かなりのディスク容量を節約し、スピードを上げることができ る。デフォルトでは ‘cp’ は大雑把な発見的手法で入力されたコピー元 ファイルからホールを検知し、対応する出力ファイルもスパースにする 。 WHEN の値は下のいずれかである: auto デフォルトの動作:入力ファイルがスパースのとき、出力フ ァ イルもスパースにする。 always 常に出力ファイルをスパースにする。このオプションは入力フ ァイルがスパースなファイルをサポートしないファイルシス テ ム 上にあるが、出力ファイルはスパースなファイルをサポート するファイルシステム上に置かれる場合に有用である。 never 出力ファイルをスパースにしない。このオプションの有意義 な 利用法を見付けたら筆者に教えてほしい。 --strip-trailing-slashes 指定された全ての引き数について、後ろに付いているスラッシュを取り 除く。これは ‘mkdir a; ln -s a la; mv la/ b’ のような場合に役 立 つ 。この場合 POSIX の命令では、 mv はシンボリックリンク ‘la’ で はなくディレクトリ ‘a’ を実際に移動してしまう。 -s, --symbolic-link ディレクトリ以外のファイルに対して、コピーするかわりにシンボリッ クリンクを作る。シンボリックリンクファイルをカレントディレクトリ に作る場合を除き、コピー元ファイル名は (’/’ で始まる) 絶対パスで なければならない。シンボリックリンクをサポートしていないシステム では、このオプションは単にエラーメッセージを出力するだけである。 --target-directory=DIR コピー先ディレクトリを、コマンドラインの最後の引き数ではなく、オ プションで指定する。 xargs(1) と一緒に用いると便利。 -u, --update ディレクトリ以外のファイルのコピーで、コピー先ファイルが既に存在 し、修正時刻がコピー元と同じかより新しい場合、コピーを行わない。 -v, --verbose コピーする前にそれぞれのファイル名を出力する。また名前を変更する 際のバックアップファイル名も表示する。 -x, --one-file-system コピーを始めたディレクトリと異なるファイルシステム上にあるサブデ ィレクトリをコピーをしない。マウントポイントは同じファイルシステ ム上にあるのでコピーされる。 GNU バックアップオプション GNU 版のプログラム cp, mv, ln, install, patch は、上書き、修正、削除と いった場合に、指示すればファイルのバックアップを作成する。バックアッ プ フ ァイルを必要とする場合は -b オプションで指定する。どのような名前にす るかは --backup オプションで指定する。バックアップファイルの名前を、 フ ァ イ ル名に拡張子を追加する形で与えるようにしたい場合、この拡張子を -S オプションで指示する。 -b, --backup[=METHOD] 上書きもしくは削除の必要がある場合には、ファイルのバックアップを 作成する。 -b は引き数を取らない点に注意すること。 -S SUFFIX, --suffix=SUFFIX SUFFIX をバックアップファイルそれぞれに付け加える。このオプショ ンが指定されていない場合、環境変数 SIMPLE_BACKUP_SUFFIX に設定さ れている値が使われる。 SIMPLE_BACKUP_SUFFIX が設定されていない場 合の標準値は ‘~’ である。 -V METHOD, --version-control=METHOD バックアップファイルの命名方法を指定する。引き数 METHOD に は 、‘numbered’ (または ‘t’)、‘existing’ (または ‘nil’)、 ‘never’ ( または ‘simple’) を指定できる。このオプションが指定されていな い 場 合、環境変数 VERSION_CONTROL の値が使われる。 VERSION_CONTROL が設定されていない場合の標準値は ‘existing’ である。 このオプションは Emacs 変数の ‘version-control’ に対応している。 有効な METHOD は (他と重複しない短縮形が使える): t, numbered 常に番号の拡張子を持つバックアップが作られる。 nil, existing 番 号の拡張子を持つバックアップがすでにある場合には番号の 拡張子を持つバックアップを、そうでない場合には単純なバ ッ クアップを作成する。 never, simple 常に単純なバックアップが作られる。 こ のオプションは推奨されない。代りに --backup=METHOD を使うこと 。 GNU 標準オプション --help 標準出力に使用方法のメッセージを出力して正常終了する。 --version 標準出力にバージョン情報を出力して正常終了する。 -- オプションリストの終りを示す。 環境変数 変数 LANG, LC_ALL, LC_CTYPE, LC_MESSAGES が通常の意味を持つ。 GNU 版 で は、変数 SIMPLE_BACKUP_SUFFIX と VERSION_CONTROL がバックアップファイル の命名法を上で説明した方法で管理する。 準拠 POSIX 1003.2 注意 このページは fileutils-4.1 パッケージの cp コマンドについて説明したもの で ある; その他のバージョンでは少し違いがあるかもしれない。修正や追加は aeb@cwi.nl, aw@mail1.bet1.puv.fi, ragnar@ragnar-hojland.com 宛にメー ル で連絡してください。プログラムのバグについては bug-fileutils@gnu.org へ 報告してください。 GNU fileutils 4.1 18 June 2002 CP(1)
CP(1) User Commands CP(1)
NAME
cp - copy files and directories
SYNOPSIS
cp [OPTION]... [-T] SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY
cp [OPTION]... -t DIRECTORY SOURCE...
DESCRIPTION
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options
too.
-a, --archive
same as -dR --preserve=all
--backup[=CONTROL]
make a backup of each existing destination file
-b like --backup but does not accept an argument
--copy-contents
copy contents of special files when recursive
-d same as --no-dereference --preserve=links
-f, --force
if an existing destination file cannot be opened, remove it and
try again (redundant if the -n option is used)
-i, --interactive
prompt before overwrite (overrides a previous -n option)
-H follow command-line symbolic links in SOURCE
-l, --link
link files instead of copying
-L, --dereference
always follow symbolic links in SOURCE
-n, --no-clobber
do not overwrite an existing file (overrides a previous -i
option)
-P, --no-dereference
never follow symbolic links in SOURCE
-p same as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST]
preserve the specified attributes (default: mode,owner-
ship,timestamps), if possible additional attributes: context,
links, xattr, all
-c same as --preserve=context
--no-preserve=ATTR_LIST
don’t preserve the specified attributes
--parents
use full source file name under DIRECTORY
-R, -r, --recursive
copy directories recursively
--reflink[=WHEN]
control clone/CoW copies. See below.
--remove-destination
remove each existing destination file before attempting to open
it (contrast with --force)
--sparse=WHEN
control creation of sparse files. See below.
--strip-trailing-slashes
remove any trailing slashes from each SOURCE argument
-s, --symbolic-link
make symbolic links instead of copying
-S, --suffix=SUFFIX
override the usual backup suffix
-t, --target-directory=DIRECTORY
copy all SOURCE arguments into DIRECTORY
-T, --no-target-directory
treat DEST as a normal file
-u, --update
copy only when the SOURCE file is newer than the destination
file or when the destination file is missing
-v, --verbose
explain what is being done
-x, --one-file-system
stay on this file system
-Z, --context=CONTEXT
set security context of copy to CONTEXT
--help display this help and exit
--version
output version information and exit
By default, sparse SOURCE files are detected by a crude heuristic and
the corresponding DEST file is made sparse as well. That is the behav-
ior selected by --sparse=auto. Specify --sparse=always to create a
sparse DEST file whenever the SOURCE file contains a long enough
sequence of zero bytes. Use --sparse=never to inhibit creation of
sparse files.
When --reflink[=always] is specified, perform a lightweight copy, where
the data blocks are copied only when modified. If this is not possible
the copy fails, or if --reflink=auto is specified, fall back to a stan-
dard copy.
The backup suffix is ‘~’, unless set with --suffix or SIM-
PLE_BACKUP_SUFFIX. The version control method may be selected via the
--backup option or through the VERSION_CONTROL environment variable.
Here are the values:
none, off
never make backups (even if --backup is given)
numbered, t
make numbered backups
existing, nil
numbered if numbered backups exist, simple otherwise
simple, never
always make simple backups
As a special case, cp makes a backup of SOURCE when the force and
backup options are given and SOURCE and DEST are the same name for an
existing, regular file.
AUTHOR
Written by Torbjorn Granlund, David MacKenzie, and Jim Meyering.
REPORTING BUGS
Report cp bugs to bug-coreutils@gnu.org
GNU coreutils home page:
コロナウイルスの日ごとの感染者数・死者数をグラフ化してみました。どの国が増加傾向にあり、どの国が終息に向かっているかを視覚化しています。
Copyright(C) linux-cmd.com All Rights Reserved. Author Takayuki Yukawa