学习使用 cat
命令连接文件
在这一步中,你将学习如何使用 cat
命令来连接多个文件,这些文件包含从地球总部接收到的消息片段。由于星际异常干扰,消息被分成了多个部分发送,你的任务是将它们按正确的顺序拼接在一起。
首先,在你的默认工作目录 /home/labex/project
中创建三个单独的文本文件:
message_part1.txt
message_part2.txt
message_part3.txt
你可以使用任何你喜欢的文本编辑器,或者使用以下命令:
echo "This is the first part of the message." > ~/project/message_part1.txt
echo "Followed by the second segment." > ~/project/message_part2.txt
echo "And this concludes the third and final part." > ~/project/message_part3.txt
文件创建完成后,使用 cat
命令将它们连接起来:
cat ~/project/message_part1.txt ~/project/message_part2.txt ~/project/message_part3.txt > ~/project/complete_message.txt
该命令将创建一个名为 complete_message.txt
的新文件,其中包含按连接顺序排列的所有三个部分的内容。
当你使用 cat
查看 complete_message.txt
时,应该会看到以下结果:
This is the first part of the message.
Followed by the second segment.
And this concludes the third and final part.