[root@localhost ~]# cd /proc/$$/fd //$$代表进程id号 fd为文件描述符
接下来ll一下,看一下信息
[root@localhost fd]# ll
total 0
lrwx------. 1 root root 64 Oct 26 02:25 0 -> /dev/pts/2 //文件描述符:输入
lrwx------. 1 root root 64 Oct 26 02:25 1 -> /dev/pts/2 //文件描述符:输出
lrwx------. 1 root root 64 Oct 26 02:25 2 -> /dev/pts/2 //文件描述符:错误信息
lrwx------. 1 root root 64 Oct 26 02:25 255 -> /dev/pts/2
继续
[root@localhost fd]# exec 8<> /dev/tcp/www.baidu.com/80
8代表创建一个文件描述符8
<>代表输入输出两个方向
执行后结果如下:
可以看到,现在我们已经与百度建立连接
继续 …
[root@localhost fd]# echo -e 'GET / HTTP/1.0\n' >& 8
> 代表重定向
>& 代表重定向到文件描述符
继续 …
[root@localhost fd]# cat 0<& 8
执行后结果如下: