LoginSignup
4
6

More than 5 years have passed since last update.

scpでディレクトリ転送時の'/'の有無による挙動の違い

Last updated at Posted at 2018-01-29

scpでディレクトリをコピーするときに、転送元のパスに'/'をつけるかどうかとリモートから転送する場合かどうかで挙動が変わる。

元の状態

$ tree
.
├── d1
│   └── f1
└── d2

'/'をつけずにローカルコピー

$ scp -r d1 d2
$ tree .
.
├── d1
│   └── f1
└── d2
    └── d1
        └── f1

d1がd2の下にコピーされる

'/'をつけてローカルコピー

$ scp -r d1/ d2
$ tree .
.
├── d1
│   └── f1
└── d2
    └── f1

d1の「中身」がd2の下にコピーされる

'/'をつけずにリモートから転送

$ scp -r localhost:~/test/d1 d2
f1                                                     100%    0     0.0KB/s   00:00
$ tree .
.
├── d1
│   └── f1
└── d2
    └── d1
        └── f1

d1がd2の下にコピーされる

'/'をつけてリモートから転送

$ scp -r localhost:~/test/d1/ d2
f1                                                    100%    0     0.0KB/s   00:00
$ tree .
.
├── d1
│   └── f1
└── d2
    └── d1
        └── f1

末尾に'/'があるのにd1がd2配下にコピーされる!

ちなみにrsyncだとこのような挙動にはならず、末尾に'/'があればディレクトリの中身がコピーされる。

4
6
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
4
6