Sunday, April 28, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 757  / 1 Year ago, wed, december 7, 2022, 9:47:38

I am using:



command > ~/Desktop/file.txt


My problem is that I need to execute this command multiple times, and each time It will give me different outputs, in this moment each time I run it It erases everything and saves the new output in the file, obviously this doesn't work for me since I need to add the new output along the current output.



I will really appreciate any help.


More From » command-line

 Answers
0

Use >> instead of >:



command >> ~/Desktop/file.txt


While you were using command > ~/Desktop/file.txt, the file ~/Desktop/file.txt was opened by shell for writing the content of STDOUT (file descriptor 1). So the file's content will get overwritten every time you run the command.



On the other hand, shell will open the file for appending if you use >> operator. As a result the outputs of the command will get appended every time you run it.



I would suggest you to go through this manual on bash redirections.


[#20168] Thursday, December 8, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
humbire

Total Points: 55
Total Questions: 93
Total Answers: 113

Location: Oman
Member since Fri, Dec 23, 2022
1 Year ago
humbire questions
Thu, May 13, 21, 02:28, 3 Years ago
Sun, Oct 24, 21, 14:23, 3 Years ago
Wed, May 17, 23, 22:16, 1 Year ago
;