linux tee
linux tee 命令详解
功能说明:读取标准输入的数据,并将其内容输出成文件。
语 法:tee
[-ai][--help][--version][文件...]
补充说明:tee指令会从标准输入设备读取数据,将其内容输出到标准输出设备,同时保存成文件。
参 数:
-a或--append
附加到既有文件的后面,而非覆盖它.
-i-i或--ignore-interrupts
忽略中断信号。
--help
在线帮助。
--version
显示版本信息。
用‘grep’搜索文本文件
如果您要在几个文本文件中查找一字符串,可以使用‘grep’命令。‘grep’在文本中搜索指定的字符串。
假设您正在‘/usr/src/linux/Documentation’目录下搜索带字符串‘magic’的文件:
$ grep magic /usr/src/linux/Documentation/*
默认情况下,‘grep’只搜索当前目录。如果此目录下有许多子目录,‘grep’会以如下形式列出:
grep: sound: Is a directory
这可能会使‘grep’的输出难于阅读。这里有两种解决的办法:
明确要求搜索子目录:grep -r
或忽略子目录:grep -d skip
当然,如果预料到有许多输出,您可以通过 管道 将其转到‘less’上阅读:
$ grep magic /usr/src/linux/Documentation/* | less
有一点要注意,您必需提供一个文件过滤方式(搜索全部文件的话用 *)。如果您忘了,‘grep’会一直等着,直到该程序被中断。如果您遇到了这样的情况,按 <CTRL c> ,然后再试。
下面是一些有意思的命令行参数:
grep -i pattern files :不区分大小写地搜索。默认情况区分大小写,
grep -l pattern files :只列出匹配的文件名,
grep -L pattern files :列出不匹配的文件名,
grep -w pattern files :只匹配整个单词,而不是字符串的一部分(如匹配‘magic’,而不是‘magical’),
grep -C number pattern files :匹配的上下文分别显示[number]行,
grep pattern1 | pattern2 files :显示匹配 pattern1 或 pattern2 的行,
grep pattern1 files | grep pattern2 :显示既匹配 pattern1 又匹配 pattern2 的行。
这里还有些用于搜索的特殊符号:
\< 和 \> 分别标注单词的开始与结尾。
例如:
grep man * 会匹配 ‘Batman’、‘manic’、‘man’等,
grep '\<man' * 匹配‘manic’和‘man’,但不是‘Batman’,
grep '\<man\>' 只匹配‘man’,而不是‘Batman’或‘manic’等其他的字符串。
'^':指匹配的字符串在行首,
'$':指匹配的字符串在行尾,
如果您不习惯命令行参数,可以试试图形界面的‘grep’,如 reXgrep 。这个软件提供 AND、OR、NOT 等语法,还有漂亮的按钮 :-) 。如果您只是需要更清楚的输出,不妨试试 fungrep
Error:
Like “mkdir: cannot create directory `test': Read-only file system”
check the /etc/fstab to see if it is mounted read only (ro)
You can change the owner and group of a file or a directory with the chown command. Please, keep in mind you can do this only if you are the root user or the owner of the file.
Set
the file's owner:
$
chown
username somefile
After
giving this command, the new owner of a file called somefile
will be the user username.
The file's group owner will not change. Instead of a user name, you
can also give the user's numeric ID here if you want.
You
can also set the file's group at the same time. If the user name is
followed by a colon and a group name, the file's group will be
changed as well.
$
chown
username:usergroup somefile
After
giving this command, somefile's
new owner would be user username
and the group usergroup.
You
can set the owner of a directory exactly the same way you set the
owner of a file:
$
chown
username somedir
Note
that after giving this command, only the owner of the directory
will change. The owner of the files inside
of the directory won't change.
In
order to set the ownership of a directory and all the files in that
directory, you'll need the -R
option:
$
chown
-R username somedir
Here,
R stands for recursive
because this command will recursively change the ownership of
directories and their contents. After issuing this example command,
the user username
will be the owner of the directory somedir,
as well as every file in that directory.
Tell what happens:
$
chown
-v username somefile
changed
ownership of 'somefile' to username
Here, v stands for verbose. If you use the -v option, chown will list what it did (or didn't do) to the file.
The verbose mode is especially useful if you change the ownership of several files at once. For example, this could happen when you do it recursively:
$
chown
-Rv username somedir
changed
ownership of 'somedir/' to username
changed ownership of
'somedir/boringfile' to username
changed ownership of
'somedir/somefile' to username
As you can see, chown nicely reports to you what it did to each file.

浙公网安备 33010602011771号