3

I have this command locally:

 nc localhost 3440 | tar -x -O > ores.tgz 

if I receive one file from the server, it will be written to ores.tgz in my pwd.

However, if I receive multiple files from the server, it looks like only the last file I receive will be saved to the file, probably overwriting all of the previous ones.

So my question is - is there some way to save multiple files to different filenames in my pwd, using a similar command?

1 Answer 1

2

You can save it with timestamp suffix in this manner:

nc localhost 3440 | tar -x -O > ores-$(date +%s.%N).tgz 

It will produce files with names like this:

ores-1526341128.393345176.tar.gz ores-1526341129.366798510.tar.gz ores-1526341332.305878646.tar.gz ores-1526341332.545975256.tar.gz ores-1526341332.786026292.tar.gz 

Of cause you can remove nanosecond precision (%N) if your intensity of download isn't high.

2
  • wow I never would have thought that would be the way to do it! Commented May 15, 2018 at 0:04
  • I wonder how why this works under the hood Commented May 15, 2018 at 0:33

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.