linux ファイル転送
圧縮にはtar
転送にはsshやscpを使う
ディスクI/Oがいらない手順
送信したいサーバからtarで圧縮してgzを作ってからsshでサーバに転送
$ tar czf - directory-to-send | ssh user@remote-host 'cd /path/to/remote/destination && tar xzf -'
受信したいサーバから送信元サーバにsshログインし、遠隔操作して手元にデータを展開
$ ssh user@remote-host 'cd /path/to/remote/ && tar czf - source' | tar xzf -
一度gzを作ってからscpなどで送る手順
送信元サーバ作業
$ tar -czvf archive.tar.gz my_directory
$ scp archive.tar.gz user@remote-host:/path/to/destination/
送信先サーバにSSHで接続
$ ssh user@remote-host
送信先サーバ作業
$ tar -xzvf archive.tar.gz
$ cd /path/to/destination/
$ rm archive.tar.gz
code:試した.sh
$ tar czf - test20250927 | ssh asebi@172.16.76.150 'cd /tmp && tar xzf -'
tar: ._test20250927: タイムスタンプ 2025-09-27 21:35:50 は 22201.365829714 秒先を示しています
tar: 未知の拡張ヘッダキーワード 'LIBARCHIVE.xattr.com.apple.provenance' を無視
tar: test20250927/._test1.txt: タイムスタンプ 2025-09-27 21:35:44 は 22195.365744762 秒先を示しています
tar: 未知の拡張ヘッダキーワード 'LIBARCHIVE.xattr.com.apple.provenance' を無視
tar: test20250927/test1.txt: タイムスタンプ 2025-09-27 21:35:44.415514452 は 22195.781223013 秒先を示しています
tar: test20250927/._test2.txt: タイムスタンプ 2025-09-27 21:35:48 は 22199.365692356 秒先を示しています
tar: 未知の拡張ヘッダキーワード 'LIBARCHIVE.xattr.com.apple.provenance' を無視
tar: test20250927/test2.txt: タイムスタンプ 2025-09-27 21:35:48.086295543 は 22199.451966413 秒先を示しています
tar: test20250927/._test3.txt: タイムスタンプ 2025-09-27 21:35:50 は 22201.365657689 秒先を示しています
tar: 未知の拡張ヘッダキーワード 'LIBARCHIVE.xattr.com.apple.provenance' を無視
tar: test20250927/test3.txt: タイムスタンプ 2025-09-27 21:35:50.953636393 は 22202.319266412 秒先を示しています
tar: test20250927: タイムスタンプ 2025-09-27 21:35:50.953384973 は 22202.318973735 秒先を示しています
$ ssh asebi@172.16.76.150
Last login: Sat Sep 27 10:46:45 2025 from 172.16.76.1
asebi@localhost ~$
asebi@localhost ~$ cd /tmp
asebi@localhost tmp$ ls -l
合計 0
drwxr-xr-x 2 asebi asebi 114 9月 27 2025 test20250927
asebi@localhost ~$