Re: moving files with embedded whitespace using find -exec

joe_at_invalid.address
Date: 09/07/03


Date: Sun, 07 Sep 2003 15:02:45 GMT

Shelly <shellguy@nowhere.com> writes:

> Hi shell gurus,
>
> (I've turned off word wrap so the code lines don't get wrapped to
> improve readability. Sorry if it screws up the rest of the message)
>
> Maybe you can help me understand why the following find command with
> -exec fails. This is executed from the bash shell
> (2.05.0(1)-release package) on OpenBSD 3.0.
>
> Also, I've reset IFS to just a newline to try and force mv to keep
> the filename together as the first argument. This failed with the
> default IFS setting and when it's just set to \n
>
> I've also tried using single quotes and double quotes in various
> combinations around the source and destination, to no avail :(
>
> root@ob30-8g:/tmp > set|grep IFS
> IFS=$'\n'
>
> root@ob30-8g:/tmp > ls -l
> total 2
> -rw-r--r-- 1 root wheel 64 Sep 6 16:31 space1
> -rw-r--r-- 1 root wheel 0 Sep 6 17:27 third file
>
> The "ok" output appears to seem like it should work...
>
> root@ob30-8g:/tmp > find . -name '* *' -ok -exec mv \'{}\' \'/maxtor/misc/{}\' \;
> "-exec mv './third file' '/maxtor/misc/./third file'"? y
> find: -exec: No such file or directory

This works for me with GNU find. It looks like it's complaining that
it can't find mv though. If it was complaining about the file name, I
would have expected the error to be "find: -exec: mv: No such file or
directory". Is the environment in the script the same as from your
command line?

I'm not sure why you want to use exec though. If you don't have some
requirement to use it, try something like

find . -name '* *' | while read f;do mv "$f" /maxtor/misc;done

Reading filenames through the pipe will delimit them with newlines. As
long as there are no newlines in the file names themselves that should
work.

Joe



Relevant Pages

  • Re: Mysterious missing newlines ...
    ... So I'm having a problem with disappearing newlines. ... newlines from a file into my shell script fine. ... text and the url_encode comes out the other end with linefeeds intact ... I can live without the single quotes, but I need newlines in my output. ...
    (comp.lang.php)
  • Mysterious missing newlines ...
    ... So I'm having a problem with disappearing newlines. ... newlines from a file into my shell script fine. ... text and the url_encode comes out the other end with linefeeds intact ... I can live without the single quotes, but I need newlines in my output. ...
    (comp.lang.php)