Don't ask me. I just make this up as I go.

a.k.a. Jed's fridge door notes and ideas of boredom.

Why you don't need HJSplit for Linux —

HJSplit is famous in the DOS/Windows world as a way to split/join large files for easy network transfer. I’m just confused why they bothered to make an HJSplit version for linux. This HJSplit for Linux even requires you to install a separate library which add to the garbage for such a useless app (for nix). If you’re on linux and you encounter a file split via HJSplit, just use the venerable `cat` and you’d be fine.

1
cat split-files.rar.* > split-files.rar

Categorised as: Unix One-Liners


43 Comments

  1. Sam says:

    Thanks for the tip!

  2. Ofer says:

    the best tip I’ve got

  3. Arc says:

    Didn’t know this – thanks for pointing it out :-)

  4. Arc says:

    Now I’m just wondering how to easily split the file in linux so something like HJsplit in windows can join it together again.

    Messing about with the split command but the closest I’ve gotten is to have the files output starting at .000, instead of .001

  5. jedrm says:

    Arc:

    $ i=1;for file in splitfiles*; do mv $file $(printf “newfiles.%03i” $i);i=$((i+1)) ; done

    Didn’t bother re-using the old filename because it would just clobber the next file name if I do it like

    file.000 –> file.001 # will write over the original file.001

    so making a new filename is the best I can come up with in 5 minutes :)

  6. Brinley says:

    Cant get any easier. Cheers for this!

  7. Clair says:

    Nifty! I used it and it works fine. Thanks :D

  8. [...] to the blog post of Jed about why you don’t need HJSplit for Linux. I’ve never really had the need to split files nor join files until [...]

  9. jedrm says:

    @Clair: Glad to help :)

  10. Rishabh says:

    Can’t belive that there is no cat equivalent in Windows… Cant this be done in DOS?

  11. jedrm says:

    You have the choice of installing cygwin.com. But why install cygwin when you can install hjsplit for windows.

    This is just for linux users who don’t want to install hjsplit for linux on their machines.

    You can try the “type” command in the command propt but I’m not sure if that will work.

    We’d like to hear if you are successful.

  12. Chuck says:

    One of the best tips I have come across. THANK YOU!

  13. Dimas says:

    Claps your hands and say yeahhh. Great tips.

  14. great tip. i rate this as one from a “guru”. thanks. but i can not figure out the script that would split the file. where are we specifying the number of parts we would like to split the file into ?

  15. jedrm says:

    @aman: that’s easy. to split the file use bash’s split command.

    split -da 3 bigfile.pdf splitfiles

    (‘man split’ for more info on the useful split command)

    the command:

    i=1;for file in splitfiles*; do mv $file $(printf “newfiles.%03i” $i);i=$((i+1)) ; done

    is just used to rename the files so the first splitfile has .001 has its extension instead of .000 which is the default for the split command.

    Because HJSplit only detect files starting with .*1 as its first file (which is weird in computerland where everything should start with 0).

    I guess you can make a better version using Perl/Python/Ruby/etc that will split files into HJSPlit named formats but I’m lazy so the above will work anytime, everytime without you breaking a sweat.

  16. thanks a million. i honestly feel “enlightened” :) this is a really neat feature that i can use. i was not aware of the split command and the script makes sense (to me) now.

  17. dooh says:

    I figured the files were just literally split and renamed, just shows how stupid people are that try to make you download this closed source HJSplit crap probably full of virii. Shh, don’t show them this page or they will insert headers and obfuscation in the split files!

  18. Zac says:

    I’m new to Linux, and I just don’t get it, I guess. Joining split files is one of the first things I want to be able to do, and three weeks after upgrading to Linux, I still can’t.

    -I have the files SHANE.avi.001, SHANE.avi.002… SHANE.avi.007 in my home folder
    -I open a terminal
    -I type what, exactly?

  19. cat SHANE.avi.* > SHANE.avi

  20. ofcourse the terminal will have opened into the ~> directory, and you will have to do an “ls” to make sure the files are in the current directory. if not you will have to go to the directory where the files reside, using the “cd ” command

  21. jedrm says:

    @Zac: Aman’s right. Basically you just throw all the files at once to a single file.

    Read more about Bash output redirection.

    Like when you want to capture the directory listing into a single file, on the terminal you do:

    ls > dirlisting.txt

    That captures the output of the ‘ls’ command into a text file called ‘dirlisting.txt’.

    Now the great thing about redirection is it respects the file’s properties. It does not care if it’s binary or text.

    Split files are binary and when you ‘cat’ them (meaning you want to display their output) they remain binary. Just try “catting” a video file and you’ll hear all the beeps of the terminal.

    Another thing is that ‘cat’ if used with globbing (asterisks to denote “all-characters”) then it makes sure to do it in proper succession. Meaning, you don’t get the middle part into the first part and the last part into the middle part of the split file. It follows the name in succession to create the whole file (I hope you understood that because I don’t know how else to explain it :) ).

    Bash is a beautiful scripting language. It will open more possibilities for you to explore other scripting languages and are quite good for 30-second hacks.

    I suggest learning the language via the legendary “Advanced Bash Scripting Guide” by Mendel Cooper.

  22. Konfounded says:

    Can someone explain in laymans what the poster jedrm is trying to say with.

    “It follows the name in succession to create the whole file (I hope you understood that because I don’t know how else to explain it :) ).”

    Also, I’ve tried cat before but it ended up not working (or maybe I did it wrong), one day on my desktop I eventually downloaded lxsplit and it was a single binary, I dont recall it requiring another library.

    Anyhow, I normally would use Peazip archive browser on my laptop, as it has a built-in splitter and joiner that uses pea, and it works superbly with split files. Though now that I’ve read that the cat command works I will try again.

    • jedrm says:

      @Konfounded, not trying to sound snob but sometimes it’s worth trying to learn the basics first.

      What I was explaining with “It follows the name in succession…” is this:

      You have a file split into 5 parts.

      File.001
      File.002
      File.003
      File.004
      File.005

      If you know and read about Unix globbing and regular expressions, if you put an asterisk (*) in something it could mean anything an everything.

      So by doing a

      cat File.* > File

      You are simply doing

      cat File.001 File.002 File.003 File.004 File.005 > File

      without the need for redundant typing. And knows to follow it in succession without mixing up the arrangement of what part comes first.

      hope this helps

      • Konfounded says:

        jedrm,

        Oh, if that’s all you were saying then I understand that then, I guess it was a mix of your choice of diction and how that sentence was constructed, that confused me. English is not my primary language, excuse the confusion.

  23. Zac says:

    Sorry, I just don’t get it. How do I make sure the terminal is open in a particular directory? I’ve never read a book on Linux, and I knew practically nothing about it until my computer all but crashed a month and a half ago, and as a last-ditch effort, I saved my files on an external drive, wiped the hard disk and installed Ubuntu.

    • Konfounded says:

      You can make sure the Linux terminal is open by using commands.

      pwd
      cd

      individually the first command when typed into the terminal will (p)rint (w)orking (d)irectory…that is the directory your currently working in.

      the second command will (c)hange (d)irectory. So if you wanted to change directory use something like:

      cd /home/downloads/

      also, if you have a space in a title you are going to need to specify it….. the easiest method to overcome this for a newbie is to enclose the directory in quotes. such as:

      cd “/home/this directory has a lot of spaces”

      I suggest you google for a book on Linux or Unix tutorials there are so many free ones out there.

  24. Zac says:

    Thanks. How much of an expert do I have to be to use and enjoy Linux? I really just want to pick up women on the internet, and download Western movies and MILF foot fetish videos.

  25. junker says:

    There is an ms-dos concatenate command…

    Use:
    copy /b junk.mpg.001+junk.mpg.002 junk.mpg

    The /b flag uses binary concatenation, the default (/a) flag will end “assembly” if it encounters an EOF character – it was used to concatenate text files.

  26. wayne says:

    why does avi.001 files change to avi.001.txt when i’m downloading movies from the internet when having .txt makes it a useless file for hjsplit??

  27. sonny says:

    Great !! it’s working….

  28. gregbob says:

    awesome!

  29. nord0 says:

    If its as simple as using cat, this should work.
    cat file.iso.00{1..8} >> file.iso (or whatever)

    Tried using cat on “HJSplitted” files, but didnt work out well. Strangely.

    Windows is a toy OS that is fine for toy computers and toy tasks. For real tasks, a real OS is needed.

    World should use open and free standards and throw HJSplit into the fire.. Crapware in my opinion.

  30. nord0 says:

    Well actually. Some broken file it seems, downloaded again, and merged it beautifully with cat.

    Fired up HJSplit with wine and did a md5sum to compare. And they are equal :)

    Then I have to retract the crapware statement. Id call it bloatware instead. Since it just complicates a simple task that no one needs dedicated program for. Not even windows users needs it, and that says a lot lol

    • Jed says:

      I guess a lot of people feel more comfy when they can see a GUI and click on buttons.

      For a normal computer user, HJSplit fills a certain niche. But if you have any archiving tool (7-zip, WinRAR, WinZip, etc) then you can also split files using that.

      Of course `cat` would be for us folks who are too lazy to grab the mouse and let go of our keyboards :)

  31. Anton says:

    How if I split large file on Linux to be multiple small files, then I join them using HJSplit on Windows, is that possible?

Leave a Reply

Your email address will not be published. Required fields are marked *

Connect with Facebook

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>