Shriramana, On Tuesday 04 October 2005 18:02, Shriramana Sharma wrote:
Tuesday 04 Oct 2005 20:44 samaye Catimimi alekhiit:
I think that it is not recommended to write in the folder which you are compressing, since you would compress the new file too !!!
This is crazy! If I understand the command
ls | cpio -ov > ../message
right, you are giving the output of ls as input for cpio, which is to output to the file specified after >. Well first ls is executed, at which time the new CPIO archive is not yet created, and then cpio is executed with what ls provided it, which does not include the not-yet-created CPIO archive, and after that the CPIO archive is created.
More or less. First of all, the processes in a pipeline all execute concurrently. The Unix (OK, Linux) kernel's pipe mechanism interacts with the process schedulers to interleave their execution so the amount of data queued in the pipe is bounded (and almost never has to be written to disk). Because of this, it is impossible to say with certainty whether the output file will exist when "ls" executes and hence whether it's included in its output. That's why the output is sent to a different directory, eliminating the possibility that "cpio" will try to include its output in itself.
How is there a possibility of infinite looping here?
No, but only because the output file is place up one level in the file system hierarchy. If for some reason the cpio output had to be in the same directory as the files to be placed in the archive, then the list of files would have to be created first: % ls >/tmp/cpio-files % cpio </tmp/cpio-files >cpio-output But even this is not safe, since simply executing the above two commands twice in a row will guarantee that cpio will try to include one of its inputs in its output. Randall Schulz