1.> 将目标文件清空后输出
Example
$ set -o noclobber # 防止覆盖文件
$ date > whofile
whofile: file already exists
$ date >| whofile
$ cat whofile
Thu Feb 1 13:38:36 EST 1998
$ set +o noclobber # clear noclobber
$ date > whofile
$ cat whofile
Thu Feb 1 14:22:17 EST 1998
2.>> 追加输出到目标文件
Example
$ ls >> lsfile
如果lsfile不存在,则会创建新的
3.重定向错误输出
$ cat nonexistantfile 2> problem
$ cat problem
file1: Permission denied
4.重定向标准输出和错误输出
$ cmd.ksh > combo 2>&1 # 标注输出和错误输出都到combo
5.重定向输入
$ mail john < message
6.消去输出
$ shell_command > /dev/null
本文深入探讨了Shell中文件操作与输出重定向的使用技巧,包括清空文件、追加内容、错误输出重定向及消除输出等核心功能。通过实例解析,帮助开发者高效地进行文件管理和命令执行。
849

被折叠的 条评论
为什么被折叠?



