Re: rename vs rename -- was Re: Renaming files
On Tue, Oct 08, 2019 at 09:45:49AM +1100, luv-main wrote: > > Dunno if slackware has it packaged, but the perl-based rename command is > available from https://metacpan.org/release/File-Rename Thanks but no thanks. Slackware rename is part of util-linux. > > On Ubuntu, "apt-get install rename". > Tried that, don't like it. For a beginner, the util-linux one is much simpler, this from the man page: > EXAMPLES >Given the files foo1, ..., foo9, foo10, ..., foo278, the commands > > rename foo foo0 foo? > rename foo foo0 foo?? > >will turn them into foo001, ..., foo009, foo010, ..., foo278. And > > rename .htm .html *.htm > >will fix the extension of your html files. No need to understand sed :) Cheers ... Duncan. ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: rename vs rename -- was Re: Renaming files
On Tue, Oct 08, 2019 at 09:28:05AM +1100, Duncan Roe wrote: > Under Slackware: > > > 09:03:07$ file $(type -p rename) > > /usr/bin/rename: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), > > dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, stripped Dunno if slackware has it packaged, but the perl-based rename command is available from https://metacpan.org/release/File-Rename > Checked my Ubuntu VM (debian-based): no rename command. On Ubuntu, "apt-get install rename". Or, for very old versions of ubuntu (<= trusty 14.04): apt-get install libfile-rename-perl For details, see https://askubuntu.com/questions/956010/whats-the-difference-between-the-different-rename-commands craig -- craig sanders ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: Renaming files
On Tue, Oct 08, 2019 at 12:47:15AM +1100, Andrew McGlashan wrote: > I've been "reprimanded" in the past for doing something like > >for filex in $(ls 6H9*) >... > > > Everyone says, don't use "ls", it isn't needed. It's true that ls isn't needed, but the real problem is that parsing the output of ls is unreliable and potentially dangerous. And it can't deal with filenames which have completely valid characters like spaces, tabs, newlines, and shell meta-characters. The **ONLY** characters that are not valid in a unix filename are forward-slash and NUL. **ALL** other characters are valid. If you write your scripts without taking that into account then your scripts are broken. The output of ls should never be used for anything other than viewing in a terminal. See https://unix.stackexchange.com/questions/128985/why-not-parse-ls-and-what-to-do-instead In short, use shell globbing (aka "wildcard" characters). If globs can't do what you want, use find rather than ls. Either with 'find ... -exec' or, if you need to process find's list of filenames (with grep or sed or something) make sure you use NUL separated output and tools that can handle NUL-separated input (e.g. 'find ... -print0 | grep -z ... | head -z -n 10 | xargs -0r') Most GNU tools these days have a '-z' option for that. some others do too. and perl has '-0', as does 'xargs'. With awk you can set the input (and/or output) record separator with RS="\0" (or ORS="\0"). craig -- craig sanders ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: rename vs rename -- was Re: Renaming files
On Mon, Oct 07, 2019 at 09:48:37PM +1100, luv-main wrote: > FWIW there is rename and there is rename ... on Debian (and Devuan in my > case) at least, further information: > > TL/DR; > > NB: the Debian provided version of rename that comes with perl is a > "deprecated program in use:" ... but there is a replacement version > (perhaps exactly the same) from a standalone package. > > > # aptitude show rename > Package: rename > Version: 0.20-4 > State: not installed > Priority: optional > Section: perl > Maintainer: Debian Perl Group > Architecture: all > Uncompressed Size: 36.9 k > Depends: perl > Conflicts: libfile-rename-perl > Replaces: libfile-rename-perl > Provides: libfile-rename-perl > Description: Perl extension for renaming multiple files > This package provides both a perl interface for renaming files > (File::Rename) and a command line tool 'rename' which is intended to > replace the version currently supplied by the perl package. > Homepage: https://metacpan.org/release/File-Rename > > > > $ rename 's/H/J/' 6H9A00* > Deprecated program in use: rename as shipped with the Debian perl > package will be removed after the release of stretch. Please install the > separate 'rename' package which will provide the same command. > > > $ which rename > /usr/bin/rename > > > $ file /usr/bin/rename > /usr/bin/rename: symbolic link to /etc/alternatives/rename > > > $ ls -lart /etc/alternatives/rename > lrwxrwxrwx 1 root root 16 May 12 08:57 /etc/alternatives/rename -> > /usr/bin/prename > > > $ file /usr/bin/prename > /usr/bin/prename: Perl script text executable > > > # apt-get install rename > Reading package lists... Done > Building dependency tree > Reading state information... Done > The following NEW packages will be installed: > rename > 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. > Need to get 12.5 kB of archives. > After this operation, 36.9 kB of additional disk space will be used. > Get:1 http://ftp.au.debian.org/debian stretch/main amd64 rename all > 0.20-4 [12.5 kB] > Fetched 12.5 kB in 0s (65.0 kB/s) > Selecting previously unselected package rename. > (Reading database ... 283269 files and directories currently installed.) > Preparing to unpack .../archives/rename_0.20-4_all.deb ... > Unpacking rename (0.20-4) ... > Setting up rename (0.20-4) ... > update-alternatives: using /usr/bin/file-rename to provide > /usr/bin/rename (rename) in auto mode > Processing triggers for man-db (2.7.6.1-2) ... > > > > # which rename > /usr/bin/rename > > > # ls -lart /usr/bin/rename > lrwxrwxrwx 1 root root 24 May 12 08:57 /usr/bin/rename -> > /etc/alternatives/rename > > > # ls -lart /etc/alternatives/rename > lrwxrwxrwx 1 root root 20 Oct 7 21:01 /etc/alternatives/rename -> > /usr/bin/file-rename > > > # file /usr/bin/file-rename > /usr/bin/file-rename: Perl script text executable > > That's the problem with my proposed solution then (which was almost straight from the man page): Under Slackware: > 09:03:07$ file $(type -p rename) > /usr/bin/rename: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), > dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, stripped Checked my Ubuntu VM (debian-based): no rename command. Cheers ... Duncan. ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: Renaming files
On Mon, Oct 07, 2019 at 07:46:50PM +1100, Andrew Greig wrote: > Rename 6H9A0001.CR2 6J9A0001.CR2 > Rename 6H9A0002.CR2 6J9A0002.CR2 > Rename 6H9A0003.CR2 6J9A0003.CR2 > Rename 6H9A0004.CR2 6J9A0004.CR2 > to > Rename 6H9A0085.CR2 6J9A0085.CR2 Use the perl rename utility (aka prename or file-rename), **NOT** the rename aka rename.ul util in the util-linux package, which has completely different command-line options and capabilities. e.g. rename -n 's/6H/6J/' *.CR2 The '-n' makes it a dry-run, showing what it would change if you let it. To actually rename files, remove the '-n' or change it to '-v' for verbose output. BTW, perl rename is far more capable than trivial sed-like renames like this. any perl code that modifies $_ can be used as the rename script. If you're running a recent debian or similar, 'apt-get install rename' to make sure you have the perl rename instead of rename.ul (on older versions of debian, package was called libfile-rename-perl). It's packaged for other distros too. craig -- craig sanders ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: Renaming files
On 8/10/19 1:00 am, Andrew Greig via luv-main wrote: > > > On 8/10/19 12:55 am, Andrew McGlashan via luv-main wrote: >> Oh and IF the file names had spaces, there would be more considerations. >> ___ >> luv-main mailing list >> luv-main@luv.asn.au >> https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main >> > > I learned long ago on this list, to avoid spaces in file names. You can deal with spaces, but it can be extra work depending on the how the task is done. $ touch aaa\ H\ bbb bbb\ H\ ccc ddd\ H\ ddd $ ls -1 aaa H bbb bbb H ccc ddd H ddd $ for x in *H*;do mv -vi "${x}" "${x/H/J}";done 'aaa H bbb' -> 'aaa J bbb' 'bbb H ccc' -> 'bbb J ccc' 'ddd H ddd' -> 'ddd J ddd' $ ls -1 aaa J bbb bbb J ccc ddd J ddd A. ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: Renaming files
On 8/10/19 12:55 am, Andrew McGlashan via luv-main wrote: Oh and IF the file names had spaces, there would be more considerations. ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main I learned long ago on this list, to avoid spaces in file names. A ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: Renaming files
On 8/10/19 12:47 am, Andrew McGlashan via luv-main wrote: On 8/10/19 12:08 am, Andrew Greig via luv-main wrote: On 7/10/19 8:37 pm, Andrew McGlashan via luv-main wrote: for x in 6H9*;do mv -v "${x}" "${x/H/J}";done Hi Andrew, That is a very elegant one liner. So this one just changed the H to a J Let's see if some light is entering the brain at this late hour So this - for x in 6H9* - is saying for the input 6H9* (all files in the directory with 6H9as a prefix) then do the exchange of the J for the H using the move command mv which is another way to rename; -v for verbose will print the outcome on screen and after that it looks like the swap but I am lost from this point. But grateful. So, in plain bash for your data files, it could be as simple as follows: for x in *H*;do mv -vi "${x}" "${x/H/J};done and to reverse the changes: for x in *J*;do mv -vi "${x}" "${x/J/H};done A. Thanks Andrew, I will be paying more attention in future to the impending , and I will, if I remember, stop the session, quickly change the user option to do 6K9A and drop in a new SD card. Tonight, after doing that the camera set the counters to 6J9A0001, so I just fired off 85 black frames and formatted the card, so now the numbering system is coherent. BUT if I am asleep at the wheel, or so busy that I sale past then I will use your one liner to bail myself out, again, Thanks Andrew ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: Renaming files
Oh and IF the file names had spaces, there would be more considerations. ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: Renaming files
On 8/10/19 12:08 am, Andrew Greig via luv-main wrote: > > > On 7/10/19 8:37 pm, Andrew McGlashan via luv-main wrote: >> for x in 6H9*;do mv -v "${x}" "${x/H/J}";done > > > Hi Andrew, > That is a very elegant one liner. So this one just changed the H to a J > > Let's see if some light is entering the brain at this late hour > So this - for x in 6H9* - is saying for the input 6H9* (all files in the > directory with 6H9as a prefix) then do the exchange of the J for the H > using the move command mv which is another way to rename; -v for > verbose will print the outcome on screen and after that it looks like > the swap but I am lost from this point. But grateful. Fix missing " chars So, in plain bash for your data files, it could be as simple as follows: for x in *H*;do mv -vi "${x}" "${x/H/J}";done and to reverse the changes: for x in *J*;do mv -vi "${x}" "${x/J/H}";done A. signature.asc Description: OpenPGP digital signature ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: Renaming files
On 8/10/19 12:08 am, Andrew Greig via luv-main wrote: > > > On 7/10/19 8:37 pm, Andrew McGlashan via luv-main wrote: >> for x in 6H9*;do mv -v "${x}" "${x/H/J}";done > > > Hi Andrew, > That is a very elegant one liner. So this one just changed the H to a J > > Let's see if some light is entering the brain at this late hour > So this - for x in 6H9* - is saying for the input 6H9* (all files in the > directory with 6H9as a prefix) then do the exchange of the J for the H > using the move command mv which is another way to rename; -v for > verbose will print the outcome on screen and after that it looks like > the swap but I am lost from this point. But grateful. I've been "reprimanded" in the past for doing something like for filex in $(ls 6H9*) ... Everyone says, don't use "ls", it isn't needed. And yes, "for filex in 6H9*" ... or any variable name in place of filex for that matter works just fine to collect all files that match in the current directory. If you need directory traversal, then there are other considerations (one option is at the end of this email). Then there is the use of /other/ programs instead of just using bash builtin string processing; no need for perl, sed or awk (or variants) for instance And because the file names in question only ever had H in them once to start with, it wasn't necessary to match with 6H9 for the variable substitute; therefore "for filex in *H*" would have been fine for the loop. "/bin/mv -v" or if you trust your path and don't have aliases to interfer, you simply use "mv -v" which will give you verbose, saves doing any echoes before hand; in testing I would echo the mv command instead of doing t until I was happy with the result. Use Bash variable substitution, as in: ${variable_name/find/replace} - works fine for a single occurrence of a match If it was more occurrences, then a double slash is needed as follows: ${variable_name//find/replace} The use of the "rename" perl script is better in one way in that it doesn't clobber files, but there is also an option with mv for that as well, you can use the "i" option in order to prompt before overwriting; the "i" option will not prompt you unless there is going to be an overwrite situation. The perl script also doesn't need the for loop. Using external programs as little as possible is also more efficient, but you need at least mv or replace ... but replace works well with the perl like expression too and no for loop. So, in plain bash for your data files, it could be as simple as follows: for x in *H*;do mv -vi "${x}" "${x/H/J};done and to reverse the changes: for x in *J*;do mv -vi "${x}" "${x/J/H};done All that just uses basic BASH functionality with ONE external program, being /bin/mv in this instance; if you wanted to be anal and be more sure that you are using the proper mv command, then use /bin/mv It is entirely possible though that some "external" programs have internal bash versions as well, but I'm pretty sure that is the case for mv. If you do need to traverse directories, then something like the following might be your solution: for filex in $(find . -xdev -name '*H*') do echo mv -vi "${filex}" "${filex/H/J}" done The "-xdev" option of find keeps it in the same file system. Cheers A. signature.asc Description: OpenPGP digital signature ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: Renaming files
On 7/10/19 8:37 pm, Andrew McGlashan via luv-main wrote: for x in 6H9*;do mv -v "${x}" "${x/H/J}";done Hi Andrew, That is a very elegant one liner. So this one just changed the H to a J Let's see if some light is entering the brain at this late hour So this - for x in 6H9* - is saying for the input 6H9* (all files in the directory with 6H9as a prefix) then do the exchange of the J for the H using the move command mv which is another way to rename; -v for verbose will print the outcome on screen and after that it looks like the swap but I am lost from this point. But grateful. Thanks Andrew Greig ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: Renaming files- thanks to all, excellent outcomes
Andrew Voumard Thank you for the script and the guidelines to save it, it was, as you said successful. I like that Linux has so many options to solve a problem. And I am grateful for this community which has always been willing to assist. Thank you Andrew Greig On 7/10/19 8:16 pm, Duncan Roe via luv-main wrote: rename 6H9A 6J9A 6H9A* Thanks Duncan, I got this ... andrew@andrew:~/Working/20191007-DuchessDank/Rename-1$ rename 6H9A 6J9A 6H9A* Bareword found where operator expected at (eval 5) line 1, near "#line 1 6H9A" (Missing operator before H9A?) syntax error at (user-supplied code) line 3, near "6H9A" andrew@andrew:~/Working/20191007-DuchessDank/Rename-1$ I don't understand the fault, but I am sure that it would trivial to fix Thank you Andrew Hi Andrew McG Thank you for this #!/bin/bash for filex in 6H9* do mv -v "${filex}" "${filex/6H9/6J9}" done It worked well, just ran it in the directory where the files were. Very grateful Andrew Hi Kim, I understand the time stamping thing is a great way to ensure each file is unique in name, but I upload files of the models I shoot to a Google drive folder and then send them a link, without prejudice, I suspect that many would have trouble with the long file names. If they want to discuss a shot they just quote the 4 digits on the end. I thank you for your substantial and excellent proposition, which would have me renaming all of my files. Just renaming as above allows me to correct the few files that need it (in this case 85) and the camera numbering scheme can be changed every 10,000 images in camera. Thank you Andrew Greig ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: Renaming files
Renaming photos based on exif data and adjusting exif date and time offsets are some of the things that the "jhead" command can do. On 7/10/19 8:19 pm, Petr Baum via luv-main wrote: On Mon, 7 Oct 2019 07:46:50 PM Andrew Greig via luv-main wrote: Hi Andrew, I am using python script written for me twenty years ago. The current version is 3.8 KiB. Script changes all camera originated file names for given directory to the format similar to the following example: 20190925_162322-pmb-G7X.jpg where the first part is date and time (from exif if available), the second part is based on the name of directory, where image files are located. If raw file exists it is renamed to the same string: 20190925_162322-pmb-G7X.CR2 While it may solve your problem, it also allows to easily mix images from various cameras and phones if date/time in the camera is correctly set (if not it can be adjusted by this script). It also helps with various searches etc. Let me know if you are interested... Petr Baum ___ > Hi all, > My camera has just ticked over 10,000 images in around 8 months, and so > another folder has opened up on the SD card, prior to today the file > folder was 100EOS5D, the new folder is 101EOS5D, but the counter has > reset from 6H9A to 6H9A0001. At this rate I cannot afford to have > the same file numbers repeating in the same calendar year. I can go into > the Camera and change the file numbering to 6J9A, but how can I run > a bulk renaming of my Raw Files - not being a scripter I am at a (self > imposed) disadvantage, > > I have tried to understand the several ways to achieve this,but I have > not grasped it. > > Rename 6H9A0001.CR2 6J9A0001.CR2 > Rename 6H9A0002.CR2 6J9A0002.CR2 > Rename 6H9A0003.CR2 6J9A0003.CR2 > Rename 6H9A0004.CR2 6J9A0004.CR2 > to > Rename 6H9A0085.CR2 6J9A0085.CR2 > > Any help would be gratefully received. > > Andrew Greig > ___ > luv-main mailing list > luv-main@luv.asn.au > https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main -- Petr Baum, P.O.Box 2364, Rowville 3178 fax +61-3-97643342 This message was created in naturally virus-free operating system: Linux ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
rename vs rename -- was Re: Renaming files
FWIW there is rename and there is rename ... on Debian (and Devuan in my case) at least, further information: TL/DR; NB: the Debian provided version of rename that comes with perl is a "deprecated program in use:" ... but there is a replacement version (perhaps exactly the same) from a standalone package. # aptitude show rename Package: rename Version: 0.20-4 State: not installed Priority: optional Section: perl Maintainer: Debian Perl Group Architecture: all Uncompressed Size: 36.9 k Depends: perl Conflicts: libfile-rename-perl Replaces: libfile-rename-perl Provides: libfile-rename-perl Description: Perl extension for renaming multiple files This package provides both a perl interface for renaming files (File::Rename) and a command line tool 'rename' which is intended to replace the version currently supplied by the perl package. Homepage: https://metacpan.org/release/File-Rename $ rename 's/H/J/' 6H9A00* Deprecated program in use: rename as shipped with the Debian perl package will be removed after the release of stretch. Please install the separate 'rename' package which will provide the same command. $ which rename /usr/bin/rename $ file /usr/bin/rename /usr/bin/rename: symbolic link to /etc/alternatives/rename $ ls -lart /etc/alternatives/rename lrwxrwxrwx 1 root root 16 May 12 08:57 /etc/alternatives/rename -> /usr/bin/prename $ file /usr/bin/prename /usr/bin/prename: Perl script text executable # apt-get install rename Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: rename 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 12.5 kB of archives. After this operation, 36.9 kB of additional disk space will be used. Get:1 http://ftp.au.debian.org/debian stretch/main amd64 rename all 0.20-4 [12.5 kB] Fetched 12.5 kB in 0s (65.0 kB/s) Selecting previously unselected package rename. (Reading database ... 283269 files and directories currently installed.) Preparing to unpack .../archives/rename_0.20-4_all.deb ... Unpacking rename (0.20-4) ... Setting up rename (0.20-4) ... update-alternatives: using /usr/bin/file-rename to provide /usr/bin/rename (rename) in auto mode Processing triggers for man-db (2.7.6.1-2) ... # which rename /usr/bin/rename # ls -lart /usr/bin/rename lrwxrwxrwx 1 root root 24 May 12 08:57 /usr/bin/rename -> /etc/alternatives/rename # ls -lart /etc/alternatives/rename lrwxrwxrwx 1 root root 20 Oct 7 21:01 /etc/alternatives/rename -> /usr/bin/file-rename # file /usr/bin/file-rename /usr/bin/file-rename: Perl script text executable ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: Renaming files
Hi, On 7/10/19 7:46 pm, Andrew Greig via luv-main wrote: > I have tried to understand the several ways to achieve this,but I have > not grasped it. > > Rename 6H9A0001.CR2 6J9A0001.CR2 > Rename 6H9A0002.CR2 6J9A0002.CR2 > Rename 6H9A0003.CR2 6J9A0003.CR2 > Rename 6H9A0004.CR2 6J9A0004.CR2 > to > Rename 6H9A0085.CR2 6J9A0085.CR2 Or simpler, just this short one liner: for x in 6H9*;do mv -v "${x}" "${x/H/J}";done Cheers A ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: Renaming files
On Mon, 7 Oct 2019 07:46:50 PM Andrew Greig via luv-main wrote: Hi Andrew, I am using python script written for me twenty years ago. The current version is 3.8 KiB. Script changes all camera originated file names for given directory to the format similar to the following example: 20190925_162322-pmb-G7X.jpg where the first part is date and time (from exif if available), the second part is based on the name of directory, where image files are located. If raw file exists it is renamed to the same string: 20190925_162322-pmb-G7X.CR2 While it may solve your problem, it also allows to easily mix images from various cameras and phones if date/time in the camera is correctly set (if not it can be adjusted by this script). It also helps with various searches etc. Let me know if you are interested... Petr Baum ___ > Hi all, > My camera has just ticked over 10,000 images in around 8 months, and so > another folder has opened up on the SD card, prior to today the file > folder was 100EOS5D, the new folder is 101EOS5D, but the counter has > reset from 6H9A to 6H9A0001. At this rate I cannot afford to have > the same file numbers repeating in the same calendar year. I can go into > the Camera and change the file numbering to 6J9A, but how can I run > a bulk renaming of my Raw Files - not being a scripter I am at a (self > imposed) disadvantage, > > I have tried to understand the several ways to achieve this,but I have > not grasped it. > > Rename 6H9A0001.CR2 6J9A0001.CR2 > Rename 6H9A0002.CR2 6J9A0002.CR2 > Rename 6H9A0003.CR2 6J9A0003.CR2 > Rename 6H9A0004.CR2 6J9A0004.CR2 > to > Rename 6H9A0085.CR2 6J9A0085.CR2 > > Any help would be gratefully received. > > Andrew Greig > ___ > luv-main mailing list > luv-main@luv.asn.au > https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main -- Petr Baum, P.O.Box 2364, Rowville 3178 fax +61-3-97643342 This message was created in naturally virus-free operating system: Linux ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: Renaming files
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 Hi, On 7/10/19 7:46 pm, Andrew Greig via luv-main wrote: > Hi all, My camera has just ticked over 10,000 images in around 8 > months, and so another folder has opened up on the SD card, prior > to today the file folder was 100EOS5D, the new folder is 101EOS5D, > but the counter has reset from 6H9A to 6H9A0001. At this rate I > cannot afford to have the same file numbers repeating in the same > calendar year. I can go into the Camera and change the file > numbering to 6J9A, but how can I run a bulk renaming of my Raw > Files - not being a scripter I am at a (self imposed) > disadvantage, > > I have tried to understand the several ways to achieve this,but I > have not grasped it. #!/bin/bash for filex in 6H9* do mv -v "${filex}" "${filex/6H9/6J9}" done Cheers A. -BEGIN PGP SIGNATURE- iHUEAREIAB0WIQTJAoMHtC6YydLfjUOoFmvLt+/i+wUCXZsDBAAKCRCoFmvLt+/i +/IZAP9tH1TUOs4w/npeCsb0JTf+L2ZmUEqpbvS2PgBm14JgRgD+Py670eqZy4K/ kVVw3lLo7PuA4j+K7M3PleDsQZVwjoY= =feQX -END PGP SIGNATURE- ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: Renaming files
Hi Andrew, On Mon, Oct 07, 2019 at 07:46:50PM +1100, luv-main wrote: > Hi all, > My camera has just ticked over 10,000 images in around 8 months, and so > another folder has opened up on the SD card, prior to today the file folder > was 100EOS5D, the new folder is 101EOS5D, but the counter has reset from > 6H9A to 6H9A0001. At this rate I cannot afford to have the same file > numbers repeating in the same calendar year. I can go into the Camera and > change the file numbering to 6J9A, but how can I run a bulk renaming of > my Raw Files - not being a scripter I am at a (self imposed) disadvantage, > > I have tried to understand the several ways to achieve this,but I have not > grasped it. > > Rename 6H9A0001.CR2 6J9A0001.CR2 > Rename 6H9A0002.CR2 6J9A0002.CR2 > Rename 6H9A0003.CR2 6J9A0003.CR2 > Rename 6H9A0004.CR2 6J9A0004.CR2 > to > Rename 6H9A0085.CR2 6J9A0085.CR2 > > Any help would be gratefully received. > > Andrew Greig I think this will do it: rename 6H9A 6J9A 6H9A* This will rename *all* file starting with 6H9A - is that what you want? Cheeers ... Duncan. ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Re: Renaming files
Hi Andrew, This works: #!/bin/bash typeset PATH_TO_FILE_DIR=/tmp/somedir typeset oldPattern='6H9A([0-9]+)\.CR2' typeset newPattern='6J9A\1\.CR2' for f in ${PATH_TO_FILE_DIR}/*; do typeset oldName=$f typeset newName=`echo "$f"|sed -r "s#$oldPattern#$newPattern#g"` if [ "$oldName" != "$newName" ]; then echo mv $oldName $newName mv $oldName $newName fi done You just need to change /tmp/somedir to the directory where the files are, then save the text above as a script, say renamefiles and then do a: chmod u+x renamefiles then run it via: ./renamefiles It will print out all the files it finds and changes. Hope that helps Andrew Voumard From: luv-main on behalf of Andrew Greig via luv-main Sent: Monday, 7 October 2019 7:46 PM To: luv-main@luv.asn.au Subject: Renaming files Hi all, My camera has just ticked over 10,000 images in around 8 months, and so another folder has opened up on the SD card, prior to today the file folder was 100EOS5D, the new folder is 101EOS5D, but the counter has reset from 6H9A to 6H9A0001. At this rate I cannot afford to have the same file numbers repeating in the same calendar year. I can go into the Camera and change the file numbering to 6J9A, but how can I run a bulk renaming of my Raw Files - not being a scripter I am at a (self imposed) disadvantage, I have tried to understand the several ways to achieve this,but I have not grasped it. Rename 6H9A0001.CR2 6J9A0001.CR2 Rename 6H9A0002.CR2 6J9A0002.CR2 Rename 6H9A0003.CR2 6J9A0003.CR2 Rename 6H9A0004.CR2 6J9A0004.CR2 to Rename 6H9A0085.CR2 6J9A0085.CR2 Any help would be gratefully received. Andrew Greig ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
Renaming files
Hi all, My camera has just ticked over 10,000 images in around 8 months, and so another folder has opened up on the SD card, prior to today the file folder was 100EOS5D, the new folder is 101EOS5D, but the counter has reset from 6H9A to 6H9A0001. At this rate I cannot afford to have the same file numbers repeating in the same calendar year. I can go into the Camera and change the file numbering to 6J9A, but how can I run a bulk renaming of my Raw Files - not being a scripter I am at a (self imposed) disadvantage, I have tried to understand the several ways to achieve this,but I have not grasped it. Rename 6H9A0001.CR2 6J9A0001.CR2 Rename 6H9A0002.CR2 6J9A0002.CR2 Rename 6H9A0003.CR2 6J9A0003.CR2 Rename 6H9A0004.CR2 6J9A0004.CR2 to Rename 6H9A0085.CR2 6J9A0085.CR2 Any help would be gratefully received. Andrew Greig ___ luv-main mailing list luv-main@luv.asn.au https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main