Adilli Adil
Adilli Adil

Reputation: 1261

Append a Command to the file in Unix

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

Answers (1)

HXCaine
HXCaine

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

Related Questions