- 标准输入(stdin): 代码为0, 使用<或者<<
- 标准输出(stdout): 代码为1, 使用>(覆盖)或者>>(累加)
- 标准错误输出(stderr): 代码为2,使用2>或者2>>
#列出根目录下的各目录和文件
mali@mali:~$ ll /
total 108
drwxr-xr-x 24 root root 4096 7月 14 20:42 ./
drwxr-xr-x 24 root root 4096 7月 14 20:42 ../
drwxr-xr-x 2 root root 4096 7月 21 13:33 bin/
drwxr-xr-x 3 root root 4096 7月 21 13:48 boot/
drwxrwxr-x 2 root root 4096 7月 14 20:06 cdrom/
drwxr-xr-x 18 root root 3920 7月 29 06:47 dev/
drwxr-xr-x 131 root root 12288 7月 29 06:46 etc/
drwxr-xr-x 3 root root 4096 7月 14 20:37 home/
lrwxrwxrwx 1 root root 33 7月 14 20:42 initrd.img -> boot/initrd.img-4.10.0-28-generic
drwxr-xr-x 22 root root 4096 7月 14 20:43 lib/
drwxr-xr-x 2 root root 4096 7月 21 13:29 lib64/
drwx------ 2 root root 16384 7月 14 20:03 lost+found/
drwxr-xr-x 3 root root 4096 7月 14 20:48 media/
drwxr-xr-x 2 root root 4096 8月 1 2017 mnt/
drwxr-xr-x 3 root root 4096 7月 14 20:48 opt/
dr-xr-xr-x 179 root root 0 7月 29 06:46 proc/
drwx------ 3 root root 4096 7月 15 19:03 root/
drwxr-xr-x 26 root root 820 7月 29 06:51 run/
drwxr-xr-x 2 root root 12288 7月 21 13:34 sbin/
drwxr-xr-x 2 root root 4096 7月 21 13:45 snap/
drwxr-xr-x 2 root root 4096 8月 1 2017 srv/
dr-xr-xr-x 13 root root 0 7月 29 22:39 sys/
drwxrwxrwt 10 root root 4096 7月 29 22:40 tmp/
drwxr-xr-x 11 root root 4096 8月 1 2017 usr/
drwxr-xr-x 14 root root 4096 8月 1 2017 var/
lrwxrwxrwx 1 root root 30 7月 14 20:42 vmlinuz -> boot/vmlinuz-4.10.0-28-generic
#ll /的输出的数据被导向到~/testfile中
mali@mali:~$ ll / > ~/testfile
mali@mali:~$ ll ~/testfile
-rw-rw-r-- 1 mali mali 1432 7月 29 22:44 /home/mali/testfile
mali@mali:~$ cat ~/testfile
total 108
drwxr-xr-x 24 root root 4096 7月 14 20:42 ./
drwxr-xr-x 24 root root 4096 7月 14 20:42 ../
drwxr-xr-x 2 root root 4096 7月 21 13:33 bin/
drwxr-xr-x 3 root root 4096 7月 21 13:48 boot/
drwxrwxr-x 2 root root 4096 7月 14 20:06 cdrom/
drwxr-xr-x 18 root root 3920 7月 29 06:47 dev/
drwxr-xr-x 131 root root 12288 7月 29 06:46 etc/
drwxr-xr-x 3 root root 4096 7月 14 20:37 home/
lrwxrwxrwx 1 root root 33 7月 14 20:42 initrd.img -> boot/initrd.img-4.10.0-28-generic
drwxr-xr-x 22 root root 4096 7月 14 20:43 lib/
drwxr-xr-x 2 root root 4096 7月 21 13:29 lib64/
drwx------ 2 root root 16384 7月 14 20:03 lost+found/
drwxr-xr-x 3 root root 4096 7月 14 20:48 media/
drwxr-xr-x 2 root root 4096 8月 1 2017 mnt/
drwxr-xr-x 3 root root 4096 7月 14 20:48 opt/
dr-xr-xr-x 179 root root 0 7月 29 06:46 proc/
drwx------ 3 root root 4096 7月 15 19:03 root/
drwxr-xr-x 26 root root 820 7月 29 06:51 run/
drwxr-xr-x 2 root root 12288 7月 21 13:34 sbin/
drwxr-xr-x 2 root root 4096 7月 21 13:45 snap/
drwxr-xr-x 2 root root 4096 8月 1 2017 srv/
dr-xr-xr-x 13 root root 0 7月 29 22:39 sys/
drwxrwxrwt 10 root root 4096 7月 29 22:40 tmp/
drwxr-xr-x 11 root root 4096 8月 1 2017 usr/
drwxr-xr-x 14 root root 4096 8月 1 2017 var/
lrwxrwxrwx 1 root root 30 7月 14 20:42 vmlinuz -> boot/vmlinuz-4.10.0-28-generic
#使用>重定向,若文件已存在,则文件之前的内容被清空
mali@mali:~$ ll /home > ~/testfile
mali@mali:~$ cat ~/testfile
total 12
drwxr-xr-x 3 root root 4096 7月 14 20:37 ./
drwxr-xr-x 24 root root 4096 7月 14 20:42 ../
drwxr-xr-x 18 mali mali 4096 7月 29 22:44 mali/
#使用>>,若文件已存在,新的数据会追加到原文件数据后面
mali@mali:~$ ll /usr >> ~/testfile
mali@mali:~$ cat ~/testfile
total 12
drwxr-xr-x 3 root root 4096 7月 14 20:37 ./
drwxr-xr-x 24 root root 4096 7月 14 20:42 ../
drwxr-xr-x 18 mali mali 4096 7月 29 22:44 mali/
total 132
drwxr-xr-x 11 root root 4096 8月 1 2017 ./
drwxr-xr-x 24 root root 4096 7月 14 20:42 ../
drwxr-xr-x 2 root root 61440 7月 21 22:30 bin/
drwxr-xr-x 2 root root 4096 8月 1 2017 games/
drwxr-xr-x 35 root root 16384 7月 21 13:33 include/
drwxr-xr-x 138 root root 4096 7月 21 22:30 lib/
drwxr-xr-x 10 root root 4096 8月 1 2017 local/
drwxr-xr-x 3 root root 4096 8月 1 2017 locale/
drwxr-xr-x 2 root root 12288 7月 21 22:30 sbin/
drwxr-xr-x 288 root root 12288 7月 21 22:30 share/
drwxr-xr-x 4 root root 4096 7月 14 20:48 src/
#利用cat命令创建文件catfile1
mali@mali:~$ cat > catfile1
hello world #从键盘输入,ctrl+d结束
mali@mali:~$ cat catfile1
hello world
#用文件catfile1的内容替代键盘输入
mali@mali:~$ cat > catfile2 < catfile1
mali@mali:~$ cat catfile2
hello world #内容和catfile1相同
#<<右侧的控制字符,可以终止一次输入,这样就不必输入ctrl+d来结束
mali@mali:~$ cat > catfile << "eof"
> this is a test
> ok now stop
> eof
mali@mali:~$ cat catfile
this is a test
ok now stop
mali@mali:~$