in reply to chdir and security

I guess this depends on what you mean by "safe side". There are usually better ways to do this than using this old idiom. For remote machine copies think seriously about using rsync or scp. For local/nfs copies, you can consider using 'cp -r' which is supported by many of the newer OSs. Of course, you could write a perl solution using a CPAN module...

One problem I have with pipelines is that it is generally hard to check for and handle errors that occur. They are fine for quick and dirty things, but tend to break down if you really care about something working right (or handling errors right) each time.

For example, what happens if you don't have write access to the target directory or read access to all of the files in the source tree, or you run out of disk space, or you are writing to an soft-mounted NFS filesystem and you have a network problem? If you are using a single command (like 'cp -r), you can examine one error code. In your case it is harder (though not impossible) to check for errors.

Now if you are talking about security when you mention "safe side" the answer is "it depends". The only general thing I can think of offhand is that you need to be sure you are the only one able to write to the source tree or target directory during the actual copy operation. Of course there could be 100 other issues you have to worry about here (e.g. you are copying the files over a non-encrypted NFS mount between two machines and you decide you can't trust your network).

bluto