I got a large photo collection as nested directory consisting of jpg files and html files linking to them groupwise.

The filenames of the photos look all like


and within the html files these names occur eg as

<title>Image: 2014-11-22T13:41:33_IXUS95_IMG_0880.jpg (9/796)</title>


<img src="slides/slide_2014-11-22T13:41:33_IXUS95_IMG_0880.jpg" width=933 height=700 border=1>

The directory layout looks something like

2014/ - 2014.01/ - 100.html
                   thumbs/thumb_ 2014-11-22T13:41:33_IXUS95_IMG_0880.jpg
      - 2014.02/
2015/ - 2015.01/

....and so on....

How can i get rid of the colons in both, filename of the images and the links to them within the html-files?

  • You want to simply replace the colons in all file names of the images and all textual representations of those file names in the html files with e.g. a -? Or remove them without replacement? – Byte Commander Dec 13 '16 at 20:45
  • Split the problem in half: How can I rename the .jpg files to "get rid of the colons", and How can I apply the SAME change as textual alteration to the contents of the *.html files. – waltinator Dec 13 '16 at 20:58
  • It doesn't matter whether they are replaced or deleted without any replacement. I want to do this because when I copy this whole directory tree onto a USB drive (with vfat filesystem) the filesystem will allow filenames with the colon in them, but any windows system will not be able to display the image gallery. – Jonas Delingue Dec 13 '16 at 20:59

This part will rename your files.
for file in $(find . -name "*T??:??:??*")
     mv -i "${file}" "${file//:/}"

This part will replace filename in your *.html files
for file in $(find . -type f -name "*.html")
    sed -i -re 's/([[:digit:]]{2}):/\1/g' $file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.