1

The command is:

find $HOME -path $HOME/$dir_name -prune -o -name "*$file_suffix" -exec cp {} $HOME/$dir_name/ \;

The variables dir_name and file_suffix are assigned a path to a directory and an arbitrary word earlier in the script.

I do not understand what the purpose of -path $HOME/$dir_name is, or how it affects how the rest of the command is interpreted.

oguz ismail
  • 1
  • 16
  • 47
  • 69

2 Answers2

2
-path $HOME/$dir_name -prune

excludes $HOME/$dir_name from the search; which makes sense because otherwise

-name "*$file_suffix" -exec cp {} $HOME/$dir_name/ \;

would select files copied to $HOME/$dir_name before and attempt to copy them again.

oguz ismail
  • 1
  • 16
  • 47
  • 69
2

The -path predicate allows you to specify a condition on what patterns to match. It's vaguely similar to the -name predicate, but applies to the full path, not just the file's name (basename).

Your specific command applies -prune to a specific subpath, so it will avoid scanning that particular subdirectory. If this predicate fails, it will proceed with the predicates after -o (as in "or").

You should still quote your variables.

tripleee
  • 175,061
  • 34
  • 275
  • 318