SHELL编程概念之: 管道, 重定向和反短斜线backtick
- December 12th, 2010
- Posted in 学以致用
- Tags: bash : shell
- Write comment
他们不是系统命令,但是他们真的很重要。
管道 (|) 将一个命令的输出作为另外一个命令的输入。
比如有一个命令
grep "hello" file.txt | wc -l
在这里grep命令的输出作为wc命令的输入。当然您可以使用多个命令
重定向:将命令的结果输出到文件,而不是标准输出(屏幕)。
> 写入文件并覆盖旧文件
>> 加到文件的尾部,保留旧文件内容。
比如 ls > files.txt
反短斜线:使用反短斜线可以将一个命令的输出作为另外一个命令的一个命令行参数。
比如:
命令: find . -mtime -1 -type f -print
用来查找过去24小时(-mtime –2则表示过去48小时)内修改过的文件。
如果您想将所有查找到的文件打一个包,则可以使用以下脚本:
#!/bin/sh
# The ticks are backticks (`) not normal quotes ('):
tar -zcvf lastmod.tar.gz `find . -mtime -1 -type f -print`
反短斜线(backtick)在哪里?请看下图:


No comments yet.