In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use split to split files under Linux. It is very detailed and has certain reference value. Friends who are interested must finish reading it.
Split can split a large file into multiple small files, and sometimes it is necessary to split the questionnaire into smaller fragments, such as improving readability and generating logs.
If we stay together for a long time, we must divide.
First, use the dd command to generate a 700MB file as our split object:
[root@roclinux] $dd if=/dev/zero bs=1024 count=700000 of=king_of_ring.avi700000+0 records in700000+0 records out716800000 bytes (717 MB) copied, 12.9189 s, 55.5 MB/s [root@roclinux] $ls-l king_of_ring.avi-rw-r--r-- 1 root root 716800000 Apr 12 13:01 king_of_ring.avi
The file size of American blockbusters is 700MB, while the only two flash drives I have on hand are 512MB-sized. I intend to split the file with 400MB as a split unit. The-b option of split is used here to specify the size of each split file:
[root@roclinux] $split-b 400M king_of_ ring.avie [root @ roclinux ~] $ls-ltotal 1400008 Mustang Rakoto-1 root root 716800000 Apr 12 13:01 king_of_ring.avi-rw-r--r-- 1 root root 419430400 Apr 12 13:04 xaa-rw-r--r-- 1 root root 297369600 Apr 12 13:04 xab
Look! Split up! Why, why are there such strange names as xaa and xab?
Yes, you read it correctly, in the case of not clearly specifying the naming of the split file, split will default to the x character as the file prefix, using strings such as aa, ab and ac as the file suffix. As a result, there are the xaa and xab we saw above.
In terms of file size, as we expected, the movie file was indeed cut into a 400MB file and a 300MB file, which can finally be loaded into two flash drives.
Know what it is, know why.
Now that you know the split command, let's learn about the command format and common options of split.
The role of split is well described, which is to split files according to certain rules. In general, we can split according to the file size, or if it is a text file, we can split it by the number of lines, which defaults to 1000 lines as a split unit.
By default, the name of the split file is prefixed with x and suffixed with two-letter formats such as aa, ab, and ac to form name formats such as xaa and xab.
Let's take a look at the command format of split:
Split [- b] [- C] [-] [- l] [file to be cut] [output file name prefix] [- a]
The most commonly used options are here:
-b: specifies the number of bytes to split, or you can specify K, M, G, T, and so on. -or-l: specifies how many lines to split into a file. Output file name prefix: sets the name prefix of the split file. Split will automatically add a number after the prefix, starting with aa by default. -a: the default suffix length is 2, which means numbering according to the format aa, ab, ac and so on. If you divide for a long time, you will come together.
After completing the split of the American blockbuster, I rushed to my friend's house, opened his computer, plugged in the flash drive, and used the cat command to merge the split files xaa and xab into one file. We can see that the size of the merged file is the same as that of the source file:
[root@roclinux ~] $cat xaa xab > king_of_ring_ merge.avi.Root @ roclinux ~] $ls-ltotal 2100012 king_of_ring_merge.avi-rw-r--r---1 root root 716800000 Apr 12 13:01 king_of_ring.avi-rw-r--r-- 1 root root 716800000 Apr 12 13:07 king_of_ring_merge.avi-rw-r--r-- 1 root root 419430400 Apr 12 13:04 xaa-rw-r--r-- 1 root root 297369600 Apr 12 13:04 xab
By the way, if we are under Windows, we will first run cmd, and then use the copy command to merge the files:
Copy / b xaa + xab king_of_ring.avi
The format is somewhat different from that of Linux, but the principle is the same.
Set the name prefix for the split file
In the above example, we did not specify the name prefix of the split file, and as a result, the split file names are all names such as aa and ab, which is neither desirable nor beautiful.
In the following example, we try to prefix the name of the split file with king_of_ring_part_:
# We specified the king_of_ring_part_ prefix [root@roclinux ~] $split-b 400m king_of_ring.avi king_of_ring_part_# can see The readability of file names improves a lot [root@roclinux] $ls-l king*-rw-r--r-- 1 root root 716800000 Feb 25 18:29 king_of_ring.avi-rw-r--r-- 1 root root 419430400 Feb 25 19:24 king_of_ring_part_aa-rw-r--r-- 1 root root 297369600 Feb 25 19:24 king_of_ring_part_ab
The readability of the file name has not improved a lot. It can be seen from the file name that it is the split document of the American blockbuster.
Set numeric suffix
If you don't like using letters like aa and ab as file suffixes, we can also use the-d option to specify a numeric file suffix:
# the-d option [root@roclinux ~] $split-b 400m-d king_of_ring.avi king_of_ring_part_# suffix has been changed from aa, ab to 00, [root@roclinux ~] $ls-l king*-rw-r--r-- 1 root root 716800000 Feb 25 18:29 king_of_ring.avi-rw-r--r-- 1 root root 419430400 Feb 25 19:24 king_of_ring_part_00-rw-r--r-- 1 root root 297369600 Feb 25 19:24 king_of_ring_part_01
For Chinese, the suffix in digital form increases the readability of the file name.
Split by the number of rows
We talked about the method of splitting files by file size (such as 400MB), but not all cases are suitable for using file size as a split unit. For example, what if we want to split the / etc/passwd file into 10 lines of records in a single file?
# use-N to specify the number of rows to be split. In this case, it is-10 [root@roclinux ~] $split-d-10 / etc/passwd my_passwd_#. You can see that the check after a successful split [root@roclinux ~] $wc-l my_passwd_* 10 my_passwd_00 10 my_passwd_01 5 my_passwd_02 25 total is indispensable.
It should be noted that when transferring large files over the network, or copying large files between devices, there may be data inconsistencies before and after the transfer.
Using split to split large files is only the beginning of the story, after the operation is finished, the perfect ending is to break up into pieces and return to Zhao in a perfect way. Therefore, it is necessary to check the integrity of the files after merging the files. It is recommended to use md5sum to calculate and compare the md5 values of the two large files before and after.
# calculate the MD5 value for the original file [root@roclinux ~] $md5sum king_of_ring.avieacff27bf2db99c7301383b7d8c1c07c king_of_ring.avi# calculate the MD5 value for the merged file, and compare it with the original value [root@roclinux ~] $md5sum king_of_ring_merge.avieacff27bf2db99c7301383b7d8c1c07c king_of_ring_merge.avi is all the contents of the article "how to use split to split a file under Linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.