Thursday, August 28, 2025

COPY ไฟล์มาด้วย permission และ owner เดิม ทั้งแบบ local และ remote

  • ปกติเราจะใช้  $ cp -rf foldrer /path/destination แบบนี้สำหรับ local
  • และแบบ remote จาก client เราจะใช้ $ scp -r user@host:/path/folder /path/destination
  • ประมาณนั้น ปัญหาที่เจอตลอดคือเรื่อง permission และ owner และ timestamp จะเป็นเวลา copy มา และowner user เป็นเจ้าของไฟล์ที่คัดลอกมาใหม่ และ permission เป็น 700 ประมาณนี้คือ owner ทำได้หมด แต่เอาสิทธิ์ write ออกจาก group และ other user ประมาณนี้

Solved

วิธีการด้านล่างจะได้ permission, owner , timestamp เดิมจะ  source เลย

  • แบบ local

$ sudo cp -p /path/source/file /path/destination/file_copy

$ sudo cp -a /path/source/folder /path/destination/folder_copy

  • สำหรับย้าย folder ขนาดใหญ่

$ rsync -av source_dir/ destination_dir/

  • แบบ remote AI เค้าแนะนำ  rsync หว่า

$ rsync -avz user@host:/path/source_dir/ destination_dir/ /path/destination/

Ref

  • https://chatgpt.com/share/68afbdc8-4784-8010-949f-78d57028f4cb


No comments:

Post a Comment

Popular Posts