As far as I know, you can have the ability to make pipes between applications, such as this one:

$ step1 < input_file | step2 | step3 > result_file

And you can access devices such as /dev/urandom, /dev/zero. /dev/null, etc:

$ cat /dev/urandom > "output_file"
$ someprog > /dev/null

My question is, is it possible to make a pipe with a block device both input and output at the same time? For example, I want to read a input_file, send to /dev/example (which is rw), and then read its output into output_file. Can be achieved on a single command just like this:

$ cat input_file | /dev/example > output_file


$ /dev/example < input_file > output_file

or is it advised to do in two commands?

PS: Maybe I'm misspelling the commands or making syntax errors, please let me know how to get it. I use sh or bash, I don't know how to use other consoles. If I'm not clear, let me know as English is not my mother tongue.

1 Answer 1


What you wrote makes no sense: /dev/example is a file, not a program or a pipe. If you write data to a device, it doesn't go through the device and out to another program.

For example, data written to /dev/audio is played on loudspeakers. If you read data from /dev/audio, you get data recorded on the microphone. There's no relationship between what is played on the loudspeakers and what is recorded with the microphone.

  • Suppose the device (e.g. a dedicated crypto device connected via USB to the PC) processes data like a program and I can access the device from the /dev folder. As I can redirect stdin and stdout at the same time with applications (app < input > output), can be done the same with the crypto device (or any device)? BTW: thanks about the info of /dev/audio, I really didn't knew that.
    – SonicARG
    Mar 28, 2014 at 3:26
  • Usually such a device is there so that ioctl() calls can be made to control it, it's not necessarily how to get data in or out. I have seen hardware crypto use a separate process and a socket for data transfer. Mar 28, 2014 at 9:54
  • 1
    @SonicARG It wouldn't work like this. There's no type of device file that acts like a pipe. There isn't a single way to implement this, but I've seen it done in two different ways under Linux: as a character device where data is exchanged through ioctl (so you can't do anything directly from the shell, you need a helper program), or with Linux's kernel sockets (sockets that communicate with a part of the kernel rather than over a network) (so, again, you need a helper program, but there only to open, after than you can get something pipe-like). Mar 28, 2014 at 9:57
  • Thanks for the data Gilles, will become more useful in the future. Question solved; closing and accepting your answer.
    – SonicARG
    Mar 28, 2014 at 12:22

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.