"> file" versus "cp /dev/null file"

"> file" versus "cp /dev/null file"

Post by Michael Wa » Thu, 03 Sep 1998 04:00:00



"> file" is better than "cp /dev/null file"
because it does not fork another process.

So I should do
find file -exec > {} \;
instead
find file -exec cp /dev/null {} \;
right?

But it does not do what I want it to do. I even tried
find file -exec \> {} \;
what is the story? Thank you.
--
unix programs: niftp (non-interactive recursive ftp), hide (hide command args),
submit (replace nohup), etc from ftp://ftp.mindspring.com/users/mwang/unix-prog

 
 
 

"> file" versus "cp /dev/null file"

Post by Allen Kirb » Thu, 03 Sep 1998 04:00:00


This is just a guess, but "> file" is really a shell built-in.  When find uses the
-exec command it will try to fork and exec a program.  But "> file" isn't an
executable.  You may be stuck with the cp - executing a shell just to use the
redirection is probably worse than cp.  If you're obsessed with speed there may be
a faster executable out there.  So, I think you're stuck, but at least you know
why.


> "> file" is better than "cp /dev/null file"
> because it does not fork another process.

> So I should do
> find file -exec > {} \;
> instead
> find file -exec cp /dev/null {} \;
> right?

> But it does not do what I want it to do. I even tried
> find file -exec \> {} \;
> what is the story? Thank you.
> --
> unix programs: niftp (non-interactive recursive ftp), hide (hide command args),
> submit (replace nohup), etc from ftp://ftp.mindspring.com/users/mwang/unix-prog


--
Allen Kirby
AT&T Information Technology Services
Alpharetta, GA.
The views expressed here are mine, not my employers.

 
 
 

"> file" versus "cp /dev/null file"

Post by sysadmi » Thu, 03 Sep 1998 04:00:00


On aix 3.2.5 I have found cp fails; so I pipe the find output to cpio

find . -name "filename" -print | cpio -pd [path]


>"> file" is better than "cp /dev/null file"
>because it does not fork another process.

>So I should do
>find file -exec > {} \;
>instead
>find file -exec cp /dev/null {} \;
>right?

>But it does not do what I want it to do. I even tried
>find file -exec \> {} \;
>what is the story? Thank you.
>--
>unix programs: niftp (non-interactive recursive ftp), hide (hide command
args),
>submit (replace nohup), etc from

ftp://ftp.mindspring.com/users/mwang/unix-prog
212-449-4414
 
 
 

"> file" versus "cp /dev/null file"

Post by Niall Smar » Fri, 04 Sep 1998 04:00:00



> "> file" is better than "cp /dev/null file"
> because it does not fork another process.

Uh-huh.

Quote:> So I should do
> find file -exec > {} \;
> instead
> find file -exec cp /dev/null {} \;
> right?
> But it does not do what I want it to do. I even tried
> find file -exec \> {} \;
> what is the story? Thank you.

I don't see why you were expecting this to work, -exec executes
a program, it does not do sh -c "<args to exec>" and there is no
program named ">" it will not work.

You would have to use:

        find . -type f -exec sh -c "> {}" \;

However this is actually worse then using cp, since a process is
still forked for each file, but in this case its the whole shell.
Better:

        find . -type f | sed 's/^/> /' | sh

Niall