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.

3 Answers
3

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.