1

I want to know about the "filter-command" which are available in Unix. I am confused regarding this:

  1. What is the purpose of "Filter-Command" ?
  2. Which are the Filter-commands available in Unix?

I have read some books/articles on web, in some books i found few filter commands and in some books i found some other.

2
  • 1
    Is this a question from some kind of exam or what is the context?
    – echox
    Sep 10 '10 at 10:17
  • @echox no it was not for any exam...but i just wants a list of Filter commands which are being used in shell-script because i was confused about the total Filter commands...in some books i found some and in another i found some other Sep 11 '10 at 5:02
6

I'm not sure what you're asking without context. "Traditional" Unix tools read from standard input and write to standard output, so you can chain them together using a pipe, which is the | command:

 ls | grep "banana" | more

Things which read from standard input and write to standard output are filters.

There is an article here: http://en.wikipedia.org/wiki/Filter_(Unix)

1
  • ya exactly what i was looking for....i just wants a list of Filter commands which are being used in shell-script becoz i was confused about the total Filter commands...in some books i found some and in another i found some other..but this link provides All filter commands...thanx Sep 11 '10 at 5:01
3

A filter command is almost any command line program on UNIX, really.

Every program that can read from STDINand output to STDOUT can be used as filter.

There are exceptions, though. One such exception is cpio, which takes a list of files from STDIN to create an archive on output.

There are some commands, that seem not to be able to read from STDIN, though you should check whether those commands use - as file parameter to read from STDIN or write to STDOUT, like cat:

$ cat f - g

Output f’s contents, then standard input, then g’s contents.

But even when your program does not use that, you can still usually force a program to act as a filter:

For instance take wget and you want to make that program output to STDOUT:

$ wget -O /dev/stdout http://stackoverflow.com/ | less

i.e.: You can use /dev/stdin, /dev/stdout, and /dev/stderr, as files to force a program to read, or output into the standard-IO descriptors.

Another side note: The length of your pipe, can be as long as you wish, so you can pipe from one program to another, basically making it a long chain of filters:

$ cat file | xz | ccrypt &>/dev/null
2
  • 1
    The last example doesn't make too much sense, I give you that. It's just used as a valid example.
    – polemon
    Sep 10 '10 at 19:15
  • +1, the last example is kinda like goverments... a lot of effort and boha that goes nowhere...
    – Stefan
    Sep 14 '10 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.