1

I’ve got log files that are created as log.2015-09-28T13-36-29 and I’m trying to change the names of the log files to better suit logrotate.

The following command works to display the file I need renamed:

ls log.$(date -d 'today' +'%Y-%m-%d')*

But this command gives me errors saying it can’t find the files.

mv "log.$(date -d 'today' +'%Y-%m-%d')*" "(date -d 'today' +'%Y-%m-%d').log"

Any ideas on how to fix this command? Or a better way to do it?

0

1 Answer 1

2

The problem you are experiencing is related to the syntax of your mv command. If you forget for a minute you are trying to work with date files, your command is equivalent to:

mv file.a file.b file.c file.d

In this case, its not clear which file should be renamed what.

A solution to the problem may be to use a command to iterate through each file and rename it - maybe something like:

for each in log.$(date -d 'today' +'%Y-%m-%d')*; do mv $each $(date -d
'today' +'%Y-%m-%d').log;done
2
  • @JakeGould - Thank you for your attempted edit, however I've reverted it as it changes my intent. While laying it out as a multi-line command as you did is certainly more readable, my variant (ie all on one line) is, I feel, a better "drop-in" replacement for the previous command and thus a more useful answer.
    – davidgo
    Oct 6, 2015 at 18:09
  • Thanks for your help @davidgo. I had originally set it up like that for another task and it worked in that scenario so it was weird for me that it wouldn't work in this. Your solution works much appreciated! Oct 6, 2015 at 19:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .