tail a.txt > a.txt 会怎么样
时间: 2024-05-23 12:13:04 浏览: 4
执行命令 `tail a.txt > a.txt` 后,会将文件 a.txt 的末尾内容输出到标准输出,并将标准输出的内容覆盖写入文件 a.txt 中,也就是说,a.txt 文件被截断为空文件。这是因为在执行命令时,shell 会先打开文件 a.txt,然后将标准输出重定向到文件 a.txt,再执行 tail 命令,而 tail 命令是从文件 a.txt 的末尾开始读取内容,因此当标准输出被重定向到 a.txt 后,a.txt 中原有的内容就被清空了,然后 tail 命令再从空文件中读取内容,因此不会输出任何内容。
相关问题
popen("tail -F a.txt", "r");
This line of code uses the popen() function to open a file stream to the output of the "tail -F a.txt" command. The "r" flag indicates that the file stream should be opened in read mode.
The "tail" command is used to display the last few lines of a file, and the "-F" flag tells it to continue displaying new lines that are added to the file in real-time.
Overall, this line of code will open a file stream that reads the output of the "tail -F a.txt" command, allowing the program to monitor changes to the "a.txt" file in real-time.
将profile的前20行和后20行复制到a.txt
您可以使用命令行工具来完成这个操作。在终端中,进入到包含profile文件的目录,然后运行以下命令:
```
head -n 20 profile > a.txt
tail -n 20 profile >> a.txt
```
这个命令将会把profile文件的前20行覆盖写入到a.txt中,然后将profile文件的后20行追加到a.txt的末尾。