Linux

為每個使用者將文件從路徑複製到路徑相同的結構

  • October 2, 2013

如何從源文件複製

/backup/cpbackup/daily/a1/public_html/index.html
/backup/cpbackup/daily/b2/public_html/index.html
/backup/cpbackup/daily/c3/public_html/index.html
/backup/cpbackup/daily/d4/public_html/index.html
/backup/cpbackup/daily/e5/public_html/index.html
/backup/cpbackup/daily/f6/public_html/index.html

到目的地

/home/a1/public_html/index.html
/home/b2/public_html/index.html
/home/c3/public_html/index.html
/home/c4/public_html/index.html
/home/e5/public_html/index.html
/home/f6/public_html/index.html

另一種方法(假設您正在嘗試複製所有文件):

rsync -a /backup/cpbackup/daily/user* /home/

如果你只想要 index.html 而沒有別的:

rsync -av --include=*/ --include=*public_html/index.html --exclude=* /backup/cpbackup/daily/user* /home/

這將是一種方法:

for user in user1 user2 user3 user4 user5 user6; do
 cp /backup/cpbackup/daily/$user/public_html/index.html /home/$user/public_html/
done

引用自:https://serverfault.com/questions/543414