Downloading data files from certain web sites, the data files usually either are already named after their creation timestamp, or they end with subsequent numbering (1), (2), … in their names.
To rename such numbered files, I found that the date -r
command displays a file’s modification timestamp, which can be formated with the +format
option:
date -r somefilename.txt +%Y%m%d
To iterate over all downloaded files, I use
for f in file*name*pattern* do
Putting it all together, I came up with the one-liner
for f in pattern*; do mv $f `date -r $f +filename_%Y%m%d`.csv; done