[Bash] Append the content at the beginning of the file

Write to a file >, >>

Append content at the beginning of the file.

echo whatever > hello.txt
echo Hello world >> hello.txt
cat hello.txt
# whatever
# Hello world
(echo at the beginning; cat hello.txt) > hello.txt_ && mv hello.txt{_,}
cat hello.txt
# at the beginning
# whatever
# Hello world

read from a file <

# count how many words in hello.txt
wc -c < hello.txt
posted @ 2024-05-22 02:33  Zhentiw  阅读(2)  评论(0编辑  收藏  举报