0

What can I add to this command to append the current date and time to the file name?

find . -maxdepth 1 -type f ! -name "*.*" -exec cp -p -t /new/location {} \+
  • filename only. Not content – JT-66 Mar 29 '18 at 13:57
1

find . -maxdepth 1 -type f ! -name "*.*" -exec cp -p {} /new/location/{}-$(date +%Y-%m-%d) \;

I have removed the target (-t) parameter from the cp command and described the path and filename.

{} is used as a placeholder for the file name, to which we append a date in the desired format.

The example formatting +%Y-%m-%d should be self-explanatory.

0

I have used below method to do same Task. As tested it worked fine for me

i=`date +%d-%m-%y`; z=`date +%H-%M-%S`;find . -maxdepth 1 -type f -iname "filename" | sed "s/\.\///g" | awk -v i="$i" -v z="$z" '{print "cp -rvfp" " "  $1 " " $1"_"i"_"z}'

Where variable "i" ===> Contains date
Variable z ===>Contains Current time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.