Originally Posted by
Mickser_52
Could you please explain the other parts e.g the -exec dirname "{}" \; and how I might copy these files to a new (hopefully more reliable) external hard drive
Code:
find Pictures/ -iname "*.jpg" -exec dirname "{}" \; |sort -u
find = find command, get more information with the terminal command "man find" (no quotes)
Pictures/ = folder to search (replace as suitable)
-iname = search file"name" "i"nsensitive to case (UPPER,lower,Mixed)
"*.jpg" = what to search
-exec = execute the following command for each file found
dirname "{}" = get directory name for file found ("{}" indicates file currently found by find)
\; = terminator; indicates that exec command ends here
|sort -u = send results to the "sort" command, which then only outputs unique results (-u).
To copy "found" files, you can probably try something like this; this is not bulletproof, it's just a off-the-top-of-my-head suggestion:
Code:
find ~/Pictures/ -iname "*.jpg" -exec cp --parents -v -t /backup/laptop1/ "{}" \;
The breakup for this (only changed parts explained):
cp = copy command
--parents = when copying source file to destination, include and create full path of source file in destination (explained further below)
-v = verbose (show what's being done)
-t = target directory; location to copy file to; make sure this path exists and is writeable
you need the "--parents" to prevent files with same names (but in different directories) from being overwritten. Eg if you have DSC00345.jpg in /Pictures/Holidays and the same filename DSC00345.jpg in /Pictures/Parties, one will overwrite the other if all files are copied to the same target directory. "--parents" will help prevent this by creating the directories "Holidays" and "Parties" under the target location, and copying each file to it's relevant location under the target location. (Sorry, can't explain it any clearer; just re-read it a couple of times, it will get clearer).
as for your target directories, I suggest you create a seperate backup path for each laptop (eg /backup/laptop1, /backup/laptop2, etc), again to prevent overwriting in case of same file names.
I hope this is clear; please post back if you need further explanations.
Bookmarks