I have this command:

tar -cf - input/* | split --bytes=1m 

Which splits my huge gz files into small ones. This works fine.

However I want the output (the small files) to be created in the input/ directory. How to achieve?

  • 1
    A simple question, why are you splitting the archive into such small parts? Apart from putting them onto floppy drives, I don't see much reason for this. This may be a XY problem, there may be a much better solution for what you are trying to do.
    – orion
    Commented Jan 26, 2015 at 10:11

1 Answer 1


You can pipe into a subshell and call cd in there:

tar -cf - input/* | ( cd input; split --bytes=1m )

Just be careful to not call this twice, because the next time, the small files will be part of the tar archive too. It's generally not a good idea to put the archive back into the original directory.

Also, your tar command is currently not compressing, you are just putting files together and splitting them apart again into same-sized chunks.

  • Thanks, thats exactly what I want to do. I do not want to compress at all. Anything against using this tehcnique as subprocess call in a python script?
    – user46399
    Commented Jan 26, 2015 at 11:03
  • It should work with os.system if your $SHELL is set to bash or something similar. However, it's much cleaner to put this into a shell script that takes a directory for an argument, and use from subprocess import call.
    – orion
    Commented Jan 26, 2015 at 12:07

You must log in to answer this question.