Linux find command and copy and rename them same time Linux find command and copy and rename them same time shell shell

Linux find command and copy and rename them same time


You can do:

find /src -type f -name '*.log' -size +2G -exec cp {} /dest/{}-$(date -I) \;

Additions/Modifications i made:

  • -name '*.log' searches only for log files, as we are only interested in those. You can look for files with any names too if unsure, just omit -name '*.log in that case

  • $(date -I) is command substitution the output will be today's date in format YYYY-mm-dd, you can also define a custom format, check man date

  • End the -exec action of find with \;