Reputation: 1261
how do we append a command to the first line of the file? for example a command to display date?Thank in advance for your answer
Upvotes: 0
Views: 112
Reputation: 4258
It is not possible to prepend directly to a file without overwriting the file.
This may work for you instead.
mv file1.txt file1.txt.tmp # Move file temporarily
date > file1.txt # Add your command
cat file1.txt.tmp >> file1.txt # Append original content
rm file1.txt.tmp # Remove temporary file
Upvotes: 1