2
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 1 year has passed since last update.

rsync の送信先・元パス末尾の「/」の有無

Last updated at Posted at 2023-10-25

rsync するときに指定するパスの末尾のスラッシュが、いるのかいらないのか混乱しないよう備忘録として残しておきます。

フォルダ A には a.txt というファイルがあり、フォルダ B は空という設定で進めます。

ls /
A/ B/

ls /A/
a.txt

ls /B/

送信元の末尾のスラッシュ

送信元の末尾のスラッシュは、有無で挙動が変わるため注意が必要です。

なしの場合

A 自体が B の中にコピーされます。
B の中に A が作られることになります。

rsync /A /B/

ls /B/
A/

ありの場合

A の中身が B の中にコピーされます。
(今回のように B が空の場合 A と B の中身が同じになります。)

rsync /A/ /B/

ls /B/
a.txt

送信先の末尾のスラッシュ

送信先の末尾のスラッシュは有無は結果に影響しません。
以下のコマンドは両方で同じ結果になります。

rsync /A/ /B/

rsync /A/ /B

ls /B/
a.txt

参考

2
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
2
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?