linux 命令好多都是默认将 查询出来的数据,输出到屏幕上面的。

如果不想输出到屏幕,想要输出到指定的文件的时候, 就需要用到  重定向的功能。

 

重定向使用的几个符号:

  >  重定向输入 (如果文件中有数据,会将数据清除,重新输入新的数据)

  >> 重定向追加 (这个就是追加的输入,在文件的最后 输入内容)

  < 重定向输出

  << 重定向追加输出

 

linux 中使用:

  0 代表标准输入  stdin

  1 代表标准输出 stdout

  2 代表标准错误输出 stderr

so:   2>&1 的意思就是,“把标准错误传送到标准输出要去的任何位置”

 例:(  fdisk -l > /dev/null 2>&1 ) 

输入: 

[root@python opt]# sort -n -t ':' -k3 passwd |grep 'python' > test1
[root@python opt]# cat test1
python_web:x:1000:1000:python_web:/home/python_web:/bin/bash

[root@python opt]# sort -n -t ':' -k3 passwd |grep 'root' >> test1
[root@python opt]# cat test1
python_web:x:1000:1000:python_web:/home/python_web:/bin/bash
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin

 


wc - 显示文件中的行数、单词数、字节数
  -l   多少行

  -w  多少单词

  -c  多少字节

[root@python opt]# wc test1
  3   3 138 test1

3行, 3个单词, 138个字

 

输出:

[root@python opt]# wc -c < test1
138

< 这个符号就是,输出到内存了。将这个结果

例子:比如我要添加分区:

[root@python ~] # fdisk /dev/sdb <<EOF
>n
>p
>4
>
>+10G
>w
>EOF

如此 给虚拟机添加  10个G 的磁盘。

 

posted on 2019-07-04 17:47  rookiehbboy  阅读(492)  评论(0编辑  收藏  举报