Find and rename forward slash in directory name (Linux / OmniOS)?

On a fileserver at work, we have a bunch of old directories made on macOS (that was previously on an AFP share) that has / in the name. I would like to replace / with -, but am having a hard time doing that. Also some of the directories also contain <space> that complicates things even further.

Example directories with forward slash:

  • Brief/Debrief (shows up as Brief:Debrief in Linux cli)
  • Til/fra kunde (shows up as Til:Fra kunder in Linux cli)

I would like to rename them to be Brief-Debrief and Til-Fra kunde, i.e replacing / with -

I have tried with find and -exec mv … on OmniOS, but I have not managed to get the forward slash (and especially not when there is a <space> in the name also.

I can use an Ubuntu VM that access the share via NFS, and there I have access to rename, etc., but I'm still having issues.

Any input on how to solve this?

EDIT:

As per @Kamil Maciorowski suggestion, all I needed to look for was :, and presto.

Final command:

find . -name "*:*" -type d -execdir rename -n 's/:/-/g' "{}" \;

(remove the -n flag if you copy this, -n = dry run)

4

1 Answer

As per @Kamil Maciorowski suggestion, all I needed to look for was :, and presto.

Final command:

find . -name "*:*" -type d -execdir rename -n 's/:/-/g' "{}" \;

(remove the -n flag if you copy this, -n = dry run)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like