LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-06-2007, 05:55 AM   #1
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215
Blog Entries: 2

Rep: Reputation: 49
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.

Last edited by lugoteehalt; 09-06-2007 at 06:00 AM.
 
Old 09-06-2007, 06:29 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
$ 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".
 
Old 09-06-2007, 06:49 AM   #3
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
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
 
Old 09-07-2007, 11:56 AM   #4
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215

Original Poster
Blog Entries: 2

Rep: Reputation: 49
Thanks b0uncer and acid_kewpie. Perhaps I''m looking for sophistication where none exists.

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


Reply

Tags
bash, pipe, pipes, redirection, shell



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between su and su - royeo Linux - Newbie 2 09-20-2006 03:01 PM
tell me the difference wood Programming 8 01-31-2004 02:17 AM
What is the difference? pearsonx4 Linux - Newbie 4 10-05-2003 10:34 PM
What is the difference? drewski *BSD 5 05-21-2003 03:13 PM
What's the Difference New2Linux1978 Linux - Newbie 4 05-14-2003 06:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration