dimanche 8 mars 2015

Bash: Find, copy and rename files


Vote count:

0




I am trying to copy files (on the same server) created in the last 24 hours using the filename which is a Unix timestamp.



find /srv/docs/files/ -type f -iname '*.pdf' -mtime -1 -exec cp {} /srv/docs/pdf \;


However, I would like to extend this further.



  1. All files are named in this manner 1425787200.pdf. I would like to rename the file Sunday-0400.pdf

  2. I would would like to create a new directory /srv/docs/pdf/day/time/ .


So a file named 1425787200.pdf would end up in /srv/docs/pdf/Sunday/0400/Sunday-0400.pdf


Additionally, if the file already exists, an incremental number should be added to the file. eg Sunday-0400-1.pdf, Sunday-0400-2.pdf


Any help is appreciated.



asked 1 min ago







Bash: Find, copy and rename files

Aucun commentaire:

Enregistrer un commentaire