Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The target of the following code ( commands ) is to rename files/directories and also support files/directories with a special characters as "@" or "." etc

those commands are run fine on Linux without any problems ,

 export NEW_NAME='@google'
 find /tmp -name '*.com*' -print0 | xargs -0  ./rename.pl   's/\Q$ENV{NAME_THAT_WE_WANT_TO_CHANGE}\E/$1$ENV{NEW_NAME}$2/'

for example the files


will replaced after running the below command to


so now I am tring to covert the find syntax to support Solaris machines ( Solaris 10 )

and this what I write for Solaris:

  export NEW_NAME='@google'

  find /tmp -name '*.com*' -exec ./rename.pl  {} + 's/\Q$ENV{NAME_THAT_WE_WANT_TO_CHANGE}\E/$1$ENV{NEW_NAME}$2/'

but when I run the find line ... ( I get the following errors )

find: paths must precede expression
Usage: find [-H] [-L] [-P] [path...] [expression]

please advice what I need to fix in my syntax in order to support solaris machines ?

  • About the rename.pl script I took it from ( http://docstore.mik.ua/orelly/perl/cookbook/ch09_10.htm )

     more /tmp/rename.pl
     # rename script examples from lwall:
     #       rename 's/\.orig$//' *.orig
     #       rename 'y/A-Z/a-z/ unless /^Make/' *
     #       rename '$_ .= ".bad"' *.f
     #       rename 'print "$_: "; s/foo/bar/ if <stdin> =~ /^y/i' *
     $op = shift;
     for (@ARGV) {
     $was = $_;
     eval $op;
     die $@ if $@;
     rename($was,$_) unless $was eq $_;
share|improve this question
Install and use the GNU utilities. That way you get to use the same command line as in Linux, and avoid pitfalls like names with spaces and other junk in them. In my experience, Solaris utilities are archaic or just too POSIXly correct for their own good. – vonbrand Mar 11 '13 at 14:05
I can't to install because some internal issues , so the single solution is fit the "find" syntax for solaris ... – yael Mar 11 '13 at 14:11
@vonbrand - it is possible to migrate my question to starckoverflow ? – yael Mar 11 '13 at 14:14
I believe it is fine here, it is a Unix/Linux problem after all. – vonbrand Mar 11 '13 at 14:16
I see you are confortable with Perl, perhaps File::Find (also documentation for newbies) is your best bet? – vonbrand Mar 11 '13 at 17:32
up vote 1 down vote accepted

The {} \; and {} + parameters only work at the end of the command, the way xargs works.

This is not a Solaris problem.

The examples within rename.pl clearly show the filenames go on the end of the command.


find /tmp -name '*.com*' -exec ./rename.pl  \

"@" and "." do not count a special characters in this context. You need find -print0 and xargs -0 to robustly handle all filenames (e.g. with embedded newlines in the name). You can also use the same find ...| xargs ... method on Solaris, though without the "0" options, unless you install the GNU findutils and use gfind and gxargs as also suggested by @vonbrand.

share|improve this answer
what do you mean ""@" and "." do not count a special characters in this context" , I tested your solution and it replaced the special characters so I not see any problem here , – yael Mar 11 '13 at 22:06
They are not shell meta-characters (| & > < etc), are not white-space, are not control-characters (^G etc) -- so they don't strictly need a -print0 or special handling. It's good practise to quote, escape and use -print0 where possible, especially with unknown/untrusted filenames. – mr.spuratic Mar 11 '13 at 22:50
ok so I also tested your solution on linux , and your solution fit also for linux so I not need two diff commands , I can use your solution for linux & solaris to replace files/dirs with uniq characters , am I right here ? – yael Mar 12 '13 at 7:03
spuratic - did you read my last quastion ? – yael Mar 12 '13 at 14:59
I believe it is a good solution for both platforms. – mr.spuratic Mar 13 '13 at 9:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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