Quantcast
Channel: HP-UX –俺的備忘録 〜なんかいろいろ〜
Viewing all articles
Browse latest Browse all 99

cpコマンドでディレクトリ構造を含めてコピーする

$
0
0

オプション無しだと、cpコマンドではディレクトリ構造ごと(サブディレクトリを含めた状態で)コピーすることはできない。
もしディレクトリ構造とセットでコピーしたい場合は、「–parents」オプションを利用すると良いだろう。

cp --parents コピー元ファイル コピー先PATH

20150729_000000

[root@test-centos7 ~]# cp /work/aaaaa.txt /bkup
[root@test-centos7 ~]# ls -la /bkup
合計 4
drwxr-xr-x.  2 root root   22  7月 29 05:49 .
drwxr-xr-x. 30 root root 4096  7月 29 05:48 ..
-rwxr-xr-x.  1 root root    0  7月 29 05:49 aaaaa.txt
[root@test-centos7 ~]# cp --parents /work/aaaaa.txt /bkup
[root@test-centos7 ~]# ls -la /bkup
合計 4
drwxr-xr-x.  3 root root   33  7月 29 05:49 .
drwxr-xr-x. 30 root root 4096  7月 29 05:48 ..
-rwxr-xr-x.  1 root root    0  7月 29 05:49 aaaaa.txt
drwxr-xr-x.  2 root root   22  7月 29 05:49 work
[root@test-centos7 ~]# ls -la /bkup/work
合計 0
drwxr-xr-x. 2 root root 22  7月 29 05:49 .
drwxr-xr-x. 3 root root 33  7月 29 05:49 ..
-rwxr-xr-x. 1 root root  0  7月 29 05:49 aaaaa.txt
すべてのUNIXで20年動くプログラムはどう書くべきか デプロイ・保守に苦しむエンジニア達へ贈る[シェルスクリプトレシピ集] すべてのUNIXで20年動くプログラムはどう書くべきか デプロイ・保守に苦しむエンジニア達へ贈る[シェルスクリプトレシピ集]

Viewing all articles
Browse latest Browse all 99