0

I have recently added a Qnap (Linux) NAS to my Mac OS environment, as the main file server.

I realized many of the Mac OS files have / characters, that do not behave well in Linux, as they disappear when seen from Macs (they actually are being renamed in Linux and becoming invisible from the Macs... dunno why).

Example: a file named image/b.jpg should be renamed as image_b.jpg to avoid problems on the Qnap Linux NAS.

Anyway, I'd like to build a script from Mac OS Terminal to access the Linux NAS and perform a "search and change" of the / character to something else like: _.

I have begun by writing this:

ssh admin@192.168.2.2
for f in $(find /share/Public/ -name "*:*"); do mv $f ${f/:/_}; done

I can log on the remote NAS, but seems not to work... I am not a tech guy, and tried to collect some code samples from the internet.

What are options to automate or script file renames for a NAS share?

  • 1
    Could you provide an example of how a filename looks like in macOS and Linux ? And in which directory or directories does it happen? Also, let us know if those files are visible in Finder. Please update the question once you have an answers for us. – Rakib Fiha Jan 11 at 17:20
  • Also, please be more specific about the "but seems not to work": what happens if you run the command? – nohillside Jan 11 at 19:21
  • 1
    How do you see the / in mac file names. I thought macOS hid that from all the user viewable information – mmmmmm Jan 11 at 19:32
  • How do you know that image/b.jpg is a filename to begin with ? It means, b.jpg is located inside image folder. Please, post an example output of ls -lai. Also, please see here: stackoverflow.com/questions/9847288/… – Rakib Fiha Jan 12 at 17:41
  • The / in filenames on macOS is a HFS legacy, you can include them in filenames when renaming in Finder. In Terminal the filename will include a : instead of the /, the conversion is handled transparently by Finder (or whatever library call it uses). – nohillside Jan 12 at 19:48
1

Running for over the results of a find is not recommended, it will break on filenames with spaces, newlines etc.

You can use the following instead once you are logged into your NAS:

find /share/Public/ -depth -name '*:*' -exec sh -c 'mv -- "$1" "${1//:/_}"' _ {} \;

To be on the save side, run

find /share/Public/ -depth -name '*:*' -exec sh -c 'echo mv -- "$1" "${1//:/_}"' _ {} \;

and check the output for anything unexpected.

PS: The duplicated // in ${1//:/_} is intentional to ensure that all occurrences of : are replaced.

0

Apparently, you can do this right from the Finder.

You can also use Automator to do so.

If that's not your thing, there are a few different tools that are available (yes, I'm aware you can write a *NIX script to do so). A Better Finder Rename is one.

  • From my understanding, OP wants to rename files over ssh. How can OP mount those files in Finder ? – Rakib Fiha Jan 11 at 17:16
  • He says he's added it as a file server to his environment. Unless OP says otherwise, I'm assuming that a file server is visible in Finder. It'd be really weird if it wasn't. – FeliniusRex Jan 11 at 17:20
  • There is some filename conversion between / and : at work here, not sure how well renaming from the macOS side of things actually works. – nohillside Jan 11 at 19:22
  • Is there some evidence that renaming files on a network share from MacOS on whatever version the OP is on, is not recommended, or is known not to work? I think we have to assume it does work unless there's evidence otherwise. – FeliniusRex Jan 11 at 20:37
  • 1
    Renaming does work. As a matter of fact many files containing "/" when moved on Linux NAS, apparently disappear. I think they're renamed by Linux to conform to its naming standard, thus becoming invisible when seen from a Mac OS machine. I discovered that by accessing these files from the NAS... – Paolo Bartoli Jan 13 at 22:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .