Introduction to splitting and splitting of files and cat

Source: Internet
Author: User
Article Title: Introduction to file splitting and splitting combined with tool cat. Linux is a technology channel of the IT lab in China. Including desktop applications, Linux system management, kernel research, embedded systems and open source, and other basic classification 1. File splitting and integration tools;

We may encounter this situation, sometimes the file is relatively large and we want to upload it to the server. However, the server administrator restricts the upload space for security reasons, for example, only 20 mb of files can be uploaded, if the size of our files is MB, sometimes compression cannot meet the Server Upload restrictions. Now we need to split the file, split the M file into several parts, and then upload it to the server. Each split file is part of the original file. To obtain the entire file, we need a combination of tools for the file.

Therefore, we introduced the file splitting tool split and csplit, the file combination tool cat;

  
2. File splitting tools split and csplit;

Split is a tool used to split a file into several files of the same length or size;


2.1 split tool;

Split is a tool used to split a file into several files of the same length or size;


2.11 syntax format;

Split [Parameter options] infile [outfile]

Split splits the input file into several files of the same size or length. The input file remains unchanged, but the results are only written to files such as outfileaa and outfileab. If outfile is not specified, the split file will be written to xaa, xab .......
Parameters

-L n splits infile into segments with n rows. The default value is 1000.
-B n [bkm]: size of each file after each split. B Indicates 512B, k indicates 1KB, and m indicates 1 MB.
-C bytes [bkm]: place the maximum value of bytes into the file and add the complete row;
-Read from standard input;
-- Help;


2.12 split an instance application;

Example 1: Split a file named linuxdoc.txt into a new file.

[Root @ localhost ~] # More linuxdoc.txt Note: view the content of the linuxdoc.txt file;
111111111
222222222
333333333
444444444
555555555
666666666
777777777
888888888
999999999
000000000
[Root @ localhost ~] # Split-l 2 linuxdoc.txt linuxdocsp Note: split the linuxdoc.txt file and start with linuxdocsp.
[Root @ localhost ~] # Ls linuxdocspa * Note: view all split files;
Linuxdocspaa linuxdocspab linuxdocspac linuxdocs3linuxdocspae
[Root @ localhost ~] # More linuxdocspa * Note: Check the content of these files. Is there two lines for each file?
Linuxdocspaa
::::::::::::::
111111111
222222222
::::::::::::::
Linuxdocspab
::::::::::::::
333333333
444444444
::::::::::::::
Linuxdocspac
::::::::::::::
555555555
666666666
::::::::::::::
Linuxdocs3
::::::::::::::
777777777
888888888
::::::::::::::
Linuxdocspae
::::::::::::::
999999999
000000000

Example 2: split by file volume;

[Root @ localhost ~] # Ls-lh linuxdoc.txt
-Rw-r -- 1 root 100 04-27 15:56 linuxdoc.txt
[Root @ localhost ~] # More linuxdoc.txt
111111111
222222222
333333333
444444444
555555555
666666666
777777777
888888888
999999999
000000000
[Root @ localhost ~] # Split-B 30 linuxdoc.txt linuxdocwsp if no unit is attached after the specified split volume, the default value is B;
[Root @ localhost ~] # Ls-lh linuxdocwspa *
-Rw-r -- 1 root 30 04-27 16:10 linuxdocwspaa
-Rw-r -- 1 root 30 04-27 16:10 linuxdocwspab
-Rw-r -- 1 root 30 04-27 16:10 linuxdocwspac
-Rw-r -- 1 root 10 04-27 16:10 linuxdocws3
[Root @ localhost ~] # More linuxdocwspa *
::::::::::::::
Linuxdocwspaa
::::::::::::::
111111111
222222222
333333333
::::::::::::::
Linuxdocwspab
::::::::::::::
444444444
555555555
666666666
::::::::::::::
Linuxdocwspac
::::::::::::::
777777777
888888888
999999999
::::::::::::::
Linuxdocws3
::::::::::::::
000000000

Description of split volume: If no unit is specified, the default unit is B. There are other units, such as B, k, and m. See the following example;

[Root @ localhost ~] # Ls-lh morw.l.txt
-Rw-r -- 1 root 13 K 04-27 morw.l.txt note: the file size is 13 K;
[Root @ localhost ~] # Split-B 3 k morw.l.txt morw.lwsp Note: after splitting, the size of each file is 3 K;

Example 3: instances read from standard input;

[Root @ localhost ~] # Ls-lh/etc | split-l 40-etcfilelist
[Root @ localhost ~] # Ls etcfilelista *
Etcfilelistaa etcfilelistab etcfilelistac etcfilelistad etcfilelistae etcfilelistaf etcfilelistag

Note: This command uses ls to list/etc directory files in long format (not including. files in file format, that is, hidden files), pass the input content to the split, let the split to split every 40 actions into a file, the name starts with etcfilelist. Note that-after 40 indicates reading from the standard input. Here it indicates that the keyboard is input, that is, reading the content of the ls-lh/etc command. Split and split.

[1] [2] Next page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.