0

I am using Wordpress Eazyest gallery to create 2000 galleries. Some files have double or triple dashes in filenames. For instance: abc---def.jpg

On Wordpress admin and front end they get replaced, this file gets the name abc-def.jpg so they become broken links / sources.

Is there a way I can replace all ---'s or --'s in a folder with a single - character using SSH? I am on Ubuntu 12.04. Any other fix for this on Wordpress core is also welcome. Tried commenting out this line on /wp-includes/formatting.php but did not work:

$static_characters = array_merge( array( '---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)' ), $cockney );
Robin Green
  • 32,079
  • 16
  • 104
  • 187
  • 1
    `ssh` is only useful to get a command line remotely. The real work is done by some shell (often `bash`) on the remote computer. – Basile Starynkevitch Jan 02 '14 at 20:46
  • There's probably a bash command for this, but if you want to do it yourself in PHP, look up `RecursiveDirectoryIterator`, and apply a regexp to each item it finds using `preg_replace`, and then use `move` to do the magic. – halfer Jan 02 '14 at 21:11
  • i have root access, what I meant was a bash command. I think doing with PHP may cause problems after upgrades etc, so I'm still really interested in the bash command, if anyone can generate such regexp. – user3155044 Jan 02 '14 at 21:19

2 Answers2

1

I found this some place else and it seems like it worked

find . -depth -name '*foo*' -execdir bash -c 'mv -i "$1" "${1//foo/bar}"' bash {} \;

Used as:

find . -depth -name '*---*' -execdir bash -c 'mv -i "$1" "${1//---/-}"' bash {} \;

The funny thing is I accidentally ran the 1st example command and screwed everything up. Lucky got a full image backup yesterday.

0

Perhaps you could try this bash command in the remote machine to replace the multiple dashes in filenames to filenames with single dashes?

for file in `ls *\-\-*`; do mv $file `echo $file | sed 's/\-\{1,5\}/\-/'`; done

This command replaces upto 5 continuous dashes to single dashes.

sufinawaz
  • 3,623
  • 1
  • 25
  • 24