Split huge files to small chunks

What if you have a huge file and want to store this file on a CD/DVD; say a file of size 5GB and you want to store this on a DVD or multiple DVD’s. Linux comes with a built in command ‘split’ which can be used to split any kind of huge file into small size chunks. This is achieved as follows:

I am creating a huge file using ‘seq’ command:

seq 1 10000000 myseq_file.txt

Now I am going to split this huge file into chunks:

split –byte=700m myseq_file.txt seq_small_

The underscore (_) at the end is mandatory as the file will be split as seq_small_aa, seq_small_ab etc. The output of the above command is as follows:

[soj@centos ~]$ ll seq*
-rw-r–r–. 1 soj root 734003200 Feb 5 16:24 seq_small_aa
-rw-r–r–. 1 soj root 734003200 Feb 5 16:25 seq_small_ab
-rw-r–r–. 1 soj root 734003200 Feb 5 16:25 seq_small_ac
-rw-r–r–. 1 soj root 734003200 Feb 5 16:26 seq_small_ad
-rw-r–r–. 1 soj root 734003200 Feb 5 16:27 seq_small_ae
-rw-r–r–. 1 soj root 653045760 Feb 5 16:27 seq_small_af

Now, you can use the command ‘cat’ to restore the chunks back to original size so you can use it.

[soj@centos ~]$ cat seq_small_a* > seq_restore.txt

Split command can be used to split video, mp3 or any kind of huge files.

Have fun!!!

Advertisements

Simple way to Password protect and Encrypt a file

Here is a simple way to password protect a file using gpg encryption. This is not the proper way to encrypt file using gpg, but this is the easiest method to do it and I use it often.

I have a file named dmesg.txt
-rw-rw-r–. 1 soj soj 63311 Dec 11 10:03 dmesg.txt

Now, I am going to encrypt with a one liner gpg command:

gpg -c dmesg.txt

The above command will prompt you for a new passphrase and once the password is provided, it will encrypt the file dmesg.txt. Now, you will have a new encrypted file named dmesg.txt.gpg. If you try to display this file using ‘cat’ command, you will see it has got garbage characters which means it’s encrypted. But, there is another better way to encrypt a file and displaying in ASCII character. It’s neat and tidy and this can be achieved with the same command, but with an extra option ‘-a’ (armor) as follows:

gpg -c -a dmesg.txt

Now, we will have an encrypted file ‘dmesg.txt.asc’ which is more tidier when displayed. You can now share this file with your friend or intended recipient and the friend can open it using the same password that you provided at the time of encryption. If you are on a GUI, you just need to double click the encrypted file which will prompt you for the password, but if you are on a shell, you just need to issue the following command which will prompt you for a password at the shell:

gpg dmesg.txt.asc

Using the above method, you can backup a folder and encrypt at the same time.

tar -cvzf dmsg.tar.gz dmsg
The above command will create a tar file dmsg.tar.gz. Now, we can encrypt using gpg/armor command as follows:
gpg -c -a dmsg.tar.gz
An encrypted armored file is created as dmsg.tar.gz.asc

If you double click the file, it will prompt for that password that we have provided when we created the gpg encrypted file.