LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   what's the difference between | and > ? (https://www.linuxquestions.org/questions/linux-newbie-8/whats-the-difference-between-%7C-and-582641/)

lugoteehalt 09-06-2007 05:55 AM

what's the difference between | and > ?
 
Err.... that's it.

Having said that, why isn't
$ ls Directory|less
the same as
$ ls Directory > less for example?

They would give diferrent outputs but it is not at all clear to me why, and I'd have to try both to find out.

Both things are said to send std output to less. Thanks any help.

acid_kewpie 09-06-2007 06:29 AM

$ ls Directory|less

will send the output for the "ls" command to the "less" command

$ ls Directory > less

will send the output for the "ls" command to a file in the current directory called "less".

b0uncer 09-06-2007 06:49 AM

More information available at linuxcommand.org (if you're interested, read the pages there)

A pipe mark (|) causes the output of the first command (on the left) to be sent to the second program (on the right) just as if the 1st program output would be regular stdin (for example written with a keyboard) for the 2nd program.

A greater-than mark (>) causes the output of the program on the left to be sent to a file described on the right side of the mark.

A less-than mark (<) works the other way around, it causes the contents of the file described on the right side of the mark to be fed to the program on the left side as if the file contents would be regular stdin for the program (like you would write the file contents for the program yourself)

You can combine the above markings to achieve different kinds of situations, where intput and output is redirected to where ever you want. You can also use special files, stdout and stderr (normal output goes to stdout, usually to screen, and error messages to stderr which may also forward them to screen), by referring to them with numbers; number 2 means the special file stderr, so a
Code:

cat somefile 2>error_output
would try to cat somefile, and write potential errors to the file error_output (2>filename means "redirect 2, which is stderr, to the file 'filename').

This and a lot more is explained at linuxcommand.org and a lot of other sites. Also check out the other piping marks, with which you can make several programs run with one command, so that the following commands are only run if the first program succeeds, or if it fails, or in any case (&&, || and ;)

lugoteehalt 09-07-2007 11:56 AM

Thanks b0uncer and acid_kewpie. Perhaps I''m looking for sophistication where none exists.

http://linuxcommand.org/lts0060.php . Seems the thing.


All times are GMT -5. The time now is 03:27 AM.