这些是我在终端中输入的命令
echo -e "First Line" | tee ~/output.log
echo -e "Second Line" | tee ~/output.log
Run Code Online (Sandbox Code Playgroud)
当我查看文件 output.log 时,我只看到“第二行”。如何确保 tee 附加(而不是清除文件)?
我希望能够在文件中看到这一点:
First Line
Second Line
Run Code Online (Sandbox Code Playgroud)
我应该以另一种方式接近这个吗?
为什么是它关于文本追加到系统文件一样,几乎所有的指令fstab和/etc/apt/sources.list.d/<name>.list涉及使用tee 与 echo所述文本追加?
以以下示例为例,它们以 root 身份运行:
## 1
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee -a file1
## 2
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' >> file2
Run Code Online (Sandbox Code Playgroud)
运行diff -u file1 file2没有任何回报;运行md5sum file1 file2显示他们的校验和是相同的,这让我回到我原来的问题:
为什么| tee <FILENAME>在 Ubuntu 文档中如此普遍,这只是一种很好的做法,否则仅使用示例 2 而不是将输出从echoto传递会不会更容易tee?
我有一个脚本执行命令,如:
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH;./some_app -i $INDEX | tee $LOG
echo "Number of errors: $(grep "ERROR" $LOG | wc -l)"
Run Code Online (Sandbox Code Playgroud)
问题可能出在到tee. 它似乎没有得到整个输出。当应用程序退出时,输出的最后几行(通常是那些包含致命错误的)丢失了。当我在没有管道的情况下运行应用程序时,tee我将它们放入输出中。
如何强制脚本等待 tee 完成所有输出的处理?
众所周知,像这样的命令:
cat filename | some_sed_command >filename
Run Code Online (Sandbox Code Playgroud)
擦除文件文件名,因为在命令之前执行的输出重定向会导致文件名被截断。
可以通过以下方式解决问题:
cat file | some_sed_command | tee file >/dev/null
Run Code Online (Sandbox Code Playgroud)
但我不确定这在任何情况下都有效:如果文件(和 sed 命令的结果)非常大,会发生什么?操作系统如何避免覆盖一些尚未读取的内容?我看到还有一个海绵命令在任何情况下都应该起作用:它比 tee 更“安全”吗?
Ubuntu 有 lint 实用程序吗?它是如何安装的?
在计算机编程中,lint 是一种 Unix 实用程序。
https://en.wikipedia.org/wiki/Lint_%28software%29
thufir@mordor:~$
thufir@mordor:~$ gcc program.c -o prog
program.c:5:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
main()
^
thufir@mordor:~$
thufir@mordor:~$ ./prog
Hello World
thufir@mordor:~$
thufir@mordor:~$ lint program.c
No command 'lint' found, did you mean:
Command 'line' from package 'util-linux' (main)
Command 'jlint' from package 'jlint' (universe)
Command 'link' from package 'coreutils' (main)
Command 'dlint' from package 'dlint' (universe)
Command 'lift' from package 'lift' (universe)
Command 'tint' from package 'tint' (universe)
Command 'hlint' from …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 ubuntu 16.04 服务器机器上运行以下预置文件(在打包程序构建期间):
d-i preseed/late_command string \
in-target mkdir -v -p -m 0440 "/etc/sudoers.d"; \
in-target echo "%vagrant ALL=(ALL) NOPASSWD: ALL" | tee -a /etc/sudoers.d/vagrant; \
in-target echo "Defaults:vagrant !requiretty" | tee -a /etc/sudoers.d/vagrant; \
in-target chmod 440 /etc/sudoers.d/vagrant;
Run Code Online (Sandbox Code Playgroud)
在 /var/log/installer/syslog 中,我可以看到以下错误:
log-output: sh:
log-output: tee: not found
Run Code Online (Sandbox Code Playgroud)
当我像这样将“| tee -a”部分更改为“>>”时:
d-i preseed/late_command string \
in-target mkdir -v -p -m 0440 "/etc/sudoers.d"; \
in-target echo "%vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant; \
in-target echo "Defaults:vagrant !requiretty" >> /etc/sudoers.d/vagrant; \ …Run Code Online (Sandbox Code Playgroud) 在 Ubuntu 上,我的亮度键不起作用。因此,我想编写一个 shell 脚本在我的 .bashrc 中使用,而不是每次都打开 Ubuntu 设置。现在我完全不明白为什么下面一行中的 tee 命令似乎是必要的!谢谢!
sudo echo "937" | sudo tee /sys/class/backlight/intel_backlight/brightness
Run Code Online (Sandbox Code Playgroud) 为什么不使用三通?因为输出的终端渲染使应用程序运行速度变慢。
出于某种原因,这不起作用:
application 2>&1 >"$logFile"
Run Code Online (Sandbox Code Playgroud)
输出一直到终端..
我只想将 find 命令的非空输出保存到文件中。如果没有输出文件则不应创建。
$ ls folder
aa
$ find . -name 'bb' | tee file
$ cat file
$ ls folder
aa file
Run Code Online (Sandbox Code Playgroud)
怎么做?