Wednesday, August 22, 2007

find and overwrite a file

i had a need to find all files of a certain name, 'file1.file' and a certain size, greater than 20k, and overwrite every occurence with a different file 'file2.file'.

find ./ -type f -iname 'file1.file' -size +20k -exec cp ~/trunk/file2.file '{}' \;
./ == start find from the current directory
-type f == search for files
-iname 'file1.file' == insensitive case of the file named file1.file
-size +20k == search for files 20k in size or greater
-exec cp ~/trunk/file2.file '{}' \; == for each file found in the find, copy ~/trunk/file2.file and overwrite

No comments: