Bash script - how to use output from diff and find in context with cpio
Hey.
What i want to do is use the output from find, diff and then pipe it to cpio. Somewhat like this Code:
find . -print > homefolderMonday example: 2684a2685 > ./.kde/share/apps/kopete/msnpictures/someuserblabla-com.png So how do i remove the "2684a2685" and ">" part from diff output? I'm also open for other ways to do this so if you have sugestions tell me. I've made a basic backup utility that backups every users /home folders to a specified mounted partition. It works somewhat like this. PS, this is not the complete code. I can provide it if necesary. Code:
#!/bin/bash Any help and pointers will be gladly taken sorounding different ways to do this. Thanks for the help in advance. |
You can pipe the output through egrep, using a regex to match only the filenames. Something like:
Code:
diff homefolderMonday homefolderTuesday | egrep -o "\./.+$" | cpio --create --format=newc > /mnt/backup/backup.cpio Edit: It seems that "diff -n" will print the lines without the leading > character, so you could make the grep expression even simpler; something like egrep -o "^\." (matches any line starting with a period) would probably be all you need, to filter out non-file lines. |
I think diff is simply the wrong tool for the job. Either comm or cmp would probably be more suited, but there are surely still better ways to compare the contents of two directories, such as dircomp:
http://sourceforge.net/projects/dircomp |
diff, the way you are trying to use it, is going to show you files that have been removed, and these are going to be difficult to backup. find, on the other hand, should be able to directly report those files which are new or modified in the most recent minutes or days:
Code:
find . -ctime -1 -print --- rod. |
Thank you for the suggestions.
I knew that diff would output folders that has been removed to so that's a blunder from my side. I'll look closer into the find -ctime function since that would make my script easier to work with. Thank you for your time. |
All times are GMT -5. The time now is 08:22 AM. |