Single command to create multiple empty files(no trailing lines as well).

Hi,

i need a single command to create multiple empty files(no trailing lines as well) and empty the files if already existing.

please let me know or if this has been ansered, if some ocan share the link please, thanks

> newfile.txt
or
:> newfile.txt

do not work

It depends on what file names you would like to have but for files 1-9 you could go with:

for i in `seq 1 9`; do echo "" > ./$i; done

You might have heard of touch command,

You can use

touch empty_file.txt

this will craete the file , if already exists it wont create the file or empty the file, you may create the same in anywhere of your script.

Thanks,
Regards,
karthikram

touch, cat will not be working for me.. however, i am trying some options with the echo -n actually..

---------- Post updated at 03:45 AM ---------- Previous update was at 03:40 AM ----------

the thing is,
i want to create multiple files without any trailing spaces at all, but script may fail in between and in that case , it would be run again, then i want the old contents to be flushed out of the created files so they are empty again(no trailing spaces) .. now ofcourse i can do it by some code snippet but what i am looking for is a Unix command only to remove older contents if already existing or create new one if not(without any trailing spaces).

It's strange that you cannot use cat touch >, I'm not sure what type of environment you are using that disallow you to use those typical commands. Use perl if you can

seq 1 5 | perl -lne '{ open(F, ">$_"); close(F); }'