I understand all of this but lose it when i get to the 7th line starting with find
.
i don't understand the -exec cp {}
. I understand that this is executing
the copy
command but I don't understand what the brackets{}
are doing, especially if they are empty?
This entire snippet is from a book im reading.
# This script prompts to backup files and location
# The files will search on $HOME dir and will only backup files to same $HOME dir.
read -p "Which file types would you like to backup? >>: " file_suffix
read -p "Which directory would you like to backup to? >>: " dir_name
# creates a directory if it does not currently exist
test -d $HOME/$dir_name || mkdir -m 700 $HOME/$dir_name
# search criteria ie .sh . The -path, -prune and -o options are to exclude the back directory from the backup.
find $HOME -path $HOME/$dir_name -prune -o -name "*$file_suffix" -exec cp {} $HOME/$dir_name/ \;
exit 0