I’ve messed up a number of folders by using the wrong ID numbers on downloading from the camera. I need to rename the files as follows -
for each file in a given folder
if filename begins “_6D_0” then
rename file changing the zero to a one
E.g. _6D_00347-happy-new-year.CR2 becomes _6D_10347-happy-new-year.CR2
I can see ls foldername | grep '_6D_0' produces the relevant files, and mv -T oldname newname renames a file,
but I’ve no idea how to send the list of candidates to be renamed.
There are no sub-folders beginning “_6D_0” to complicate things.
If anyone can supply the commands I’d be most grateful. Please keep it simple! I’m thinking I could hardcode the folder as I work on each one in turn.
Thanks for reading.
's/^_6D_0/_6D_1/' this is a simple regular expression, in plain English: search (the s/) for _6D_0 at the beginning of the filename (the ^) and replace with _6D_1.
To test run with -n, remove -n to actually rename.
-n, --nono
No action: print names of files to be renamed, but don't rename.
The -d is needed to only match against the filename, not the full path.
-d, --filename, --nopath, --nofullpath
Do not rename directory: only rename filename component of path.
Thanks for the info folks, that’s great, most helpful. @K-1, I think I’ll start with yours. The files are also jpg and xmp, so would I just leave off the “CR2”, i.e. the last char would be the asterisk?
Thanks, it’s done. The d option doesn’t exist on my system (Ubuntu 18.04, the desktop it came with). And I must have been confused about parent directory, ended up doing rename 's/^_6D_0/_6D_1/' _6D_*.*
and it was fine.
@priort, thanks for the warning. I don’t use dt’s database so I escaped that complication.