Have you ever realized a situation where you had to copy a very large file to a flash drive but it failed after some time? though initially the data copying process starts but it halts abruptly and shows an error like “File Too Large” or “Unable to Copy”. Don’t worry, you have come to the right place. If Linux is your main operating system then follow the steps below to learn how to copy a Very large file to a flash drive in Linux. To do this we will assume a situation (more like an example and then explain the process)
Say that you have a very large file (.txt file) say 6GB and you want to copy the entire file into a flash drive with FAT32 file system where the maximum size of each file can be around 4 GBs ((2^32) – 1 bytes). If you want to copy them then you have got two choices :-
- Format the USB with some other file system which will allow files of size greater than 4 GB to be copied. An example for such filesystem would be NTFS.
- Split the large file into smaller sized files, copy to USB and then concatenate them into a single file.
I prefer the second method and so we will learn how to do this. In this article, I will teach you how to do it using the Linux terminal.
Split the file into smaller sizes and write it to flash drive. (Make sure your flash drive is already mounted)
split --bytes=2G VeryLargeFile.txt /media/38B9-D21F/VeryLargeFile.txt.
In the above command, we are splitting a text file (it could be any file) into smaller files of size 2GB and storing in the location where our flash drive was mounted. (Make sure you’re using the right file extension)
Now if look into your mounted drive folder you will see smaller files with sequential extensions were created like VeryLargeFile.txt.aa, VeryLargeFile.txt.ab and so on. Sequential extensions make it easier to concatenate or identify the parts later.
Now we concatenate the smaller files into a single file. We can do this by using the cat command in Linux. Simply copy the three smaller files from USB to another location on a different PC (Do whatever you want). Open the terminal in the location where you copied the three files and then execute the following command.
cat VeryLargeFile.txt.aa VeryLargeFile.txt.ab VeryLargeFile.txt.ac > VeryLargeFile.txt
Now the above cat command (catenate) takes all the three files and sequentially reads them and finally puts the content in one single file. It is important to note that for whatever type of file you’re applying this technique on you should always maintain the right extension. Here in this example, we have used .txt but if you want to copy a .iso file then the extensions throughout must be .iso