Sunday, May 5, 2024
9
rated 0 times [  9] [ 0]  / answers: 1 / hits: 3772  / 3 Years ago, sun, august 1, 2021, 4:35:56

I was wondering if it was possible have a command that creates one file, but every time the command is executed, it wouldn't overwrite the file created in the previous execution.



For example: touch test1.txt would create 1 file called test1.txt. But the next time I execute it, I would like the new file to be called test2.txt, or something like that. So without overwriting the already existing file. In a way it could be executed multiple times without problems.



Don't misunderstand me, I'm not trying to create multiple files with one command.



Thanks in advance!


More From » command-line

 Answers
7

The easiest solution would be to add a timestamp to the filename and not use a single digit.



The easiest method to create an empty file would be touch test$(date +%Y%m%d-%H%M%S) and that would result in a file named test20110802-170410. A 2nd time test* will get a newer timestamp so it will result in 2 files.


[#44024] Monday, August 2, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
itteast

Total Points: 291
Total Questions: 123
Total Answers: 104

Location: Tuvalu
Member since Wed, Mar 29, 2023
1 Year ago
itteast questions
;