Jon*_*eet 244
你的意思是
tail -f logfile.log
Run Code Online (Sandbox Code Playgroud)
?
(尾部的手册页)
小智 62
inotifywait如果您想在每次文件(或目录中的任何文件)更改时运行命令,则来自inotify-tools很有用。例如:
inotifywait -r -m -e modify /var/log |
while read path _ file; do
echo $path$file modified
done
Run Code Online (Sandbox Code Playgroud)
Jon*_*son 38
我更喜欢使用less +FG1,tail -f因为我发现自己需要在日志文件中搜索特定错误或 ID。如果我需要搜索某些内容,我会输入^C以停止跟踪文件并?开始向后搜索。
键绑定与vi. 可以使用以下+选项在启动时初始化任何命令:
+cmd Causes the specified cmd to be executed each time a new file is
examined. For example, +G causes less to initially display each
file starting at the end rather than the beginning.
Run Code Online (Sandbox Code Playgroud)
对于非常长的日志,我发现使用-n关闭行编号的选项很方便。从联机帮助页:
-n or --line-numbers
Suppresses line numbers. The default (to use line numbers) may
cause less to run more slowly in some cases, especially with a
very large input file. Suppressing line numbers with the -n
option will avoid this problem. Using line numbers means: the
line number will be displayed in the verbose prompt and in the =
command, and the v command will pass the current line number to
the editor (see also the discussion of LESSEDIT in PROMPTS
below).
Run Code Online (Sandbox Code Playgroud)
1.感谢 rgmarcha在评论中指出这一点。
小智 21
Tail 很棒... less 也可以用于 start less 文件,即 less myfile 然后按Shift+ F。这较少充当尾巴。
小智 18
我正在编辑一个 LaTeX 文件,并希望监视它是否在中间的某个地方发生变化。我编写了以下证明对我有用的小 shell 脚本。我希望它也能对其他人派上用场。
#!/bin/bash
FILE="$1"
CMD="$2"
LAST=`ls -l "$FILE"`
while true; do
sleep 1
NEW=`ls -l "$FILE"`
if [ "$NEW" != "$LAST" ]; then
"$CMD" "$FILE"
LAST="$NEW"
fi
done
Run Code Online (Sandbox Code Playgroud)
将其另存为watch.sh并执行chmod u+x watch.sh。然后我按如下方式执行它:
./watch.sh file.tex pdflatex
如果您只想在发生实际修改时运行该命令,则可以使用`md5sum "$FILE"`代替`ls -l "$FILE"`.
您还可以使用 inotifywatch/inotifywait 挂钩到内核 inotify 子系统。通过这种方式,您还可以查看“打开”、“关闭”或“访问”等内容。
但是,如果您只是想将附加行添加到标准输出,我同意尾部。
| 归档时间: |
|
| 查看次数: |
324950 次 |
| 最近记录: |