This question already has an answer here:
- IO redirection and the head command 5 answers
Given a file, foo.txt:
1 2 3 4 5
Say we want to change it to contain:
1 2 3
head -n3 foo.txt > foo.txt leave foo.txt empty?
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
This happens because the