Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Can You please explain me why:
'cat < file.txt > file.txt '
makes file.txt empty ?
cat <file.txt >>file.txt
Because it opens and truncates the file before reading the data — it being shell, the redirections are processed by shell before even starting cat.
The > redirection happens first and opens file.txt for writing which clears any existing content.
Required, but never shown