Your command has a few problems:
for f in /path ; do mv -n ""$f"_RBS_(date -r "$f" +"%Y%M%D")"; done
for f in /path
will only go once around the loop (with f
= /path
). You probably want for f in /path/*
to consider every file in the /path/
directory (if you want to consider files in subdirectories, that's a whole nother question).
mv
needs two arguments. The source is obviously "$f"
. The destination needs to be the transformed name.
You missed the $
in the $(...)
command substitution.
The format string for date
doesn't match your description (and you probably want month and day rather than minute and short-date)
You're using date of modification, not creation date (which isn't kept, on most filesystem types). I'll leave this as-is.
Your description implies that you want the filename to be in lower case.
With the above corrected (apart from the choice of which date to use), we end up with
for f in /path/* ; do mv -n "$f" "${f,,}_rbc_$(date -r "$f" +'%d%m%Y')"; done
Another thing to consider is that if you're doing this more than once in the same place, you might want to move the files to a different directory or test to see if they already have a plausible suffix (either remove it before adding the new one, or just leave such files untouched).
$(somecmd...)
, see here and here – ilkkachu Mar 22 '17 at 13:48""$f"_…
? The first two quotes cancel out, leaving$f"_…
. – G-Man Says 'Reinstate Monica' Mar 24 '17 at 02:44