3

I am a very beginner of unix, and working on putty shell environment.

I know standard input, output, and error are streams and related to file descriptors, but I did not understand clearly what /dev/stdin does.

  1. What is '/dev/stdin/ and how to use?

  2. Is it a special (block or character) file of a device?

Godpoong
  • 39
  • 5
  • What have you done for this question? – 炸鱼薯条德里克 Apr 21 '19 at 01:32
  • I did `$ echo hello | cp /dev/stdin /dev/stdout` and `$ cat /dev/stdin >resultfile` to figure out what is the role of /dev/stdin – Godpoong Apr 21 '19 at 02:39
  • For the 2nd question, do `file /dev/stdin`. Your path is wrong, the trailing slash is redundant. – Weijun Zhou Apr 21 '19 at 04:30
  • If you want to copy the content of `/dev/stdin` to `/dev/stdout`, you should use `dd if=/dev/stdin of=/dev/stdout`, `cp` copies the special file itself, it requires superuser privilege to do this `cp`. After all, it does not make sense to copy the file itself and you should not try `sudo cp /dev/stdin /dev/stdout`. Please also check `man dup2`. – Weijun Zhou Apr 21 '19 at 04:39
  • 1
    @WeijunZhou `cp /dev/stdin /dev/stdout` works fine. example: `echo yup | cp /dev/stdin /dev/stdout`. And this works with both BSD's dup-like `/dev/std{in,out}` and with Linux's fake symlinks and quirks. Where did you get that superuser privilege idea from? –  Apr 21 '19 at 16:26
  • I get the idea from the permission of `/dev/`, but now I realize it's wrong. Also I have an aliased `cp` when I did the tests. – Weijun Zhou Apr 21 '19 at 16:37

0 Answers0