c 不换行
n 换行
echo "abcn"
转义符,使shell忽略特殊含义。也可以表示命令尚未输入完毕
t 跳格
f 进纸
echo ""abc"" 得到结果为 "abc"
重定向符号 >
echo "abc"> file 得到的file中内容为abc
$echo "abcd">> file $cat file abc abcd二、read命令
read 变量1 变量2 ……
有一个变量名,则回车之前所有内容都赋予变量1(name1) $read name1 1st 2nd $echo $name1 1st 2nd
输入文本过长时,超长部分赋予最后一个变量 $read name1 name2 name3 1st 2nd 3rd 4th $echo $name1 1st $echo $name2 2nd $echo $name1 3rd 4th $echo $name1 $name3 1st 3rd 4th三、cat命令
cat生成文件
$cat > file1 123 输入内容 ctrl+d结束
$cat file1 file2 查看文件file1 file2中内容
$cat file1 file2 > file3 将file1 file2中内容重定向到file3,并生成file3四、管道符 |
将一个命令的输出传送给另一个命令作为输入
$df -g | awk '{print$1}'
/dev/hd4
/dev/hd2
五、tee命令
将输出的一个副本送到标准输出,另一个副本拷贝到相应文件中。
即看到输出结果的同时,将其存入一个文件。联想字母“T”
$df -g | awk '{print$1}' | tee df.out
/dev/hd4
/dev/hd2
$cat df.out
/dev/hd4
/dev/hd2
tee -a file1 将内容追加到file1原有内容的后面
六、标准输入、标准输出和标准错误1、文件描述符
系统共有12个文件描述符,其中
0 标准输入
1 标准输出
2 标准错误
2、文件重定向
(1)重定向标准输出
$cat /etc/passwd |awk -F: '{print$1}'|sort 1>sort.out 重定向符号一定要离开sort命令两个空格
$cat sort.out 否则该命令会把它当作输入文件
adm
bin
daemon
也可以使用如下的表达方式,结果和上面一样
$cat /etc/passwd |awk -F: '{print$1}'|sort >sort.out
$cat sort.out
adm
bin
daemon
(2)重定向标准输入
$sort < name.txt sort命令的输入是采用重定向的方式给出的
$sort < name.txt >name.out 为sort命令的输出指定输出文件name.out
(3)重定向标准错误
$grep abc No such file or directory $grep abc 2>error.out 将错误输出到error.out里
3、标准输出和标准错误相结合使用
$cat > file1 123 $cat file1 file2 1>file.out 2>file.error 结果输出到file.out中,错误输出到file.error中 $cat file.out 123 $cat file.error cat:0652-050 Cannot open file2
$cat file1 file2 > file.out 2>&1 将结果输出重定向到file.out中,错误也重定向到file.out $cat file.out 123 cat:0652-050 Cannot open file2



