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

Zhentiw發表於2024-05-22

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

相關文章