Hi my fist time trying to write a bash script so im kinda bad at it.
I need help with locating a file in a home dir( this file contains a list of files i want to backup). After this i want to loop all lines in the file and make copies of the files.
this is what i have tryed but it dont seem to work:
find /home$n -name .file_with_backup_register | while read line ;
do cp "$line" /var/backup/temp;
done
when im trying to make my tar backup in the script with tar-czvf $(date +%m_%d_%Y)
il get:
tar: Cowardly refusing to create an empty archive.
So im guessing its the find /home$n... line that dosent work
You could use this:
$ find $HOME -name file_with_backup_register | xargs cat | xargs -I % cp % /var/backup/temp
If you're unsure whether find
succeeds in locating your register file, just invoke:
$ find $HOME -name file_with_backup_register
and see if outputs its valid location.
EDIT see @Barmar's comment under your question, he's probably right. Nevertheless, above answer could be useful as well, since it simplifies your solution.
如果将“ -T”选项与“ tar”一起使用,则可以指定文件名,其中包含要备份的文件名。
tar -cv -T filelist -f tarball.tar
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.