Linux-运维基础

绝对路径:从根目录开始的路径,例如/etc/passwd,在任何情况下都可以使用绝对路径来找到我们想要的文件

相对路径:不从根目录开始写起的路径,例如 首先用户进入到 /home,然后再进入到test,执行的命令为 “#cd /home,#cd test”。此时用户所在的路径为 /home/test。第一个cd命令后紧跟/home,前面有斜杠;而第二个cd命令后紧跟test,前面没有斜杠。这个test是相对于/home目录来讲的,所以称为相对路径

 

输出重定向

>或1>     标准输出重定向:,先把原文件的内容清空,然后把新的内容放到文件中

>>或1>> 追加输出重定向:,把前面输出的东西输入到后边的文件中,不会清除文件原有内容,只是追加到文件的最后一行

[root@core-codes-1 ~]# echo "hahaha" >> test.txt 
[root@core-codes-1 ~]# cat test.txt 
hahaha
[root@core-codes-1 ~]# echo "delete some thing" > test.txt 
[root@core-codes-1 ~]# cat test.txt 
delete some thing

2>>  错误追加输出重定向,把命令执行错误的信息追加存放在文件中

2>   错误输出重定向,先把原文件的内容清空,然后把错误信息放到文件中

[root@core-codes-1 ~]# echa "any thing" 2>> test.txt 
[root@core-codes-1 ~]# cat test.txt 
delete some thing
-bash: echa: command not found
[root@core-codes-1 ~]# echa "any thing" 2> test.txt 
[root@core-codes-1 ~]# cat test.txt 
-bash: echa: command not found

将错误的内容和正确的信息都放在一个文件中

[root@core-codes-1 ~]# echo "any thing" >> test.txt 2>> test.txt 
[root@core-codes-1 ~]# cat test.txt 
any thing
[root@core-codes-1 ~]# echa "any thing" >> test.txt 2>> test.txt 
[root@core-codes-1 ~]# cat test.txt 
any thing
-bash: echa: command not found

简写:2>&1

[root@core-codes-1 ~]# echa "any thing" >> test.txt 2>&1
[root@core-codes-1 ~]# cat test.txt 
any thing
-bash: echa: command not found
-bash: echa: command not found
[root@core-codes-1 ~]# echo "any thing" >> test.txt 2>&1
[root@core-codes-1 ~]# cat test.txt 
any thing
-bash: echa: command not found
-bash: echa: command not found
any thing

 

输入重定向

<或0< 输入重定向,输入重定向重定向用于改变命令的输入。 当前仅与xargs联用

[root@core-codes-1 ~]# cat test.txt 
1 2 3 4 5
[root@core-codes-1 ~]# xargs -n2 <test.txt 
1 2
3 4
5

 

<<   追加输入重定向,使用到的地方不多,目前与cat 一起使用。

想向文件里面放入多行 (end of file)

cat >>/data/newfile.txt<<EOF
I
am
a
stduent
EOF

 

posted @ 2019-08-01 23:20  虫儿飞_mustartk  阅读(73)  评论(0)    收藏  举报