standard output(>) and Pipe(|)

Hi ,
what are the differences between  "|" and ">" ?
Can you bring A Example For differing these two Case?

Best Regards
Who is Participating?
The redirectors > and < are used for redirecting input from/to a file or other filesystem-based object.  I.e. to write the output of a command to a file, or to read in the contents of a file.

Pipes are used to redirect the output of one process (from stdout) to another process without the need to place it in a file first.  The output of an infinite number of processes can be "chained" using pipes, either for text processing or structured command sequences.

For pipes, something can be done such as:

cat /etc/passwd (read file /etc/passwd) | awk -F : '{print $1}' (print the first field) | sort (sort the list alphabetically) | uniq -c (remove any duplicate entries, showing how many times each entry occurred)

For redirects, you may wish to send the stdout or stderr output of a command to a file, for later review, e.g.: date > current-time

Redirects can be used in three common ways:

date > current-time
Write the output of the "date" command to the file "current-time", overwriting it if it currently exists

date >> current-time
Append the output of the "date" command to the file "current-time", creating it if it doesn't already exist

date > current-time 2> /dev/null
Same as first example, but if there's any errors (or any output written to stderr), write it to /dev/null, where it will disappear

/dev/null is a special character device.  Any data sent to it will be discarded.  Reading from it will produce a "null" character.  Other interesting character devices are /dev/zero (zero's), /dev/random (random characters), and /dev/urandom (greater level of randomness, but slower).

You can also use redirects to read in from a file, e.g. "more < /etc/passwd" would read the file /etc/passwd and pass it to stdin (standard input) of the more command, as if you had typed the text yourself, and is functionally equivalent to "cat /etc/passwd | more" (and "more /etc/passwd")
Actualy that's called a redirector (>), basically what this does is to redirect output to somewhere else like a file
ps -A > procs.txt
The pipe operator is used to pass output to another process
ps -A | grep apache
hope that clears up the differences

$ echo "foo" > file
$ cat file
$ cat file | sed 's/foo/bar/' > file1
$ cat file1
$ cat file*
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

pipe connects stdout of the process on the left to the stdin of the process on the right.
Important thing to note here is 'process'. As files are not processes, they hae no stdouts/stdins.

> redirects the filedescriptor on its left (1 by default) to the file specified on the right
The process on the left must be capable of generating something on its STDOUT. The process on the right must be capable of feeding on its STDIN.
redirection (>, >>) only works when the program creates a output to the stdout or stderr (standard output or standard error).

Pipes only works when the program to the right of the pipe obtains its input from the standard input, this kind of programs are called "filters".

For example:

Cat is a filter

$ echo "hello" | cat | cat | cat | cat

But echo is not a filter

$ echo "hello" | echo | echo | echo

Some common filters are:

cat, cut, sort, tr, tee, etc.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.