Learn some linux-cutting command split every day.

Source: Internet
Author: User
Tags stdin

 A common requirement is that there is a larger file that needs to be cut into smaller files, and you can use the split command in a Linux system. The split command cuts a large file into small files by file size or number of lines. The split command is used in the following ways:

plit [-bl] file prefix options and parameters:  -B: The size of the file that can be divided into later, can be added units, such as B, K, m, etc.-L  : divided by the number of rows. PREFIX: Represents the leader character and can be used as the leading text for the split file.

 Example one: My/etc/termcap has more than 700 k, if want to divide into 300K a file?

[Email protected] ~]# cd/tmp; Split-b 300k/etc/termcap termcap[[email protected] tmp]# ll-k termcap*-rw-r--r--1 root root  7 16:39 TERMCA paa-rw-r--r--1 root root  7 16:39 termcapab-rw-r--r--1 root root 189 Feb  7 16:39 Termcapac

 As shown above, the segmented file is Xxxaa, Xxxab, Xxxac and other ways to create small files!
Example two: How to synthesize the three small files above a file named Termcapback

[email protected] tmp]# cat termcap* >termcapback

 With the cat command, you can redirect the data stream.
Example three: Using Ls-al/output information, every 10 lines are recorded as one file

[[email protected] tmp]# Ls-al/| Split-l 10-lsroot[[email protected] tmp]# wc-l lsroot*  ten lsrootaa lsrootab   6 Lsrootac  

Note: In a pipeline command, the stdout of the previous command is often used as the stdin, and some commands need to be processed using a file name (for example, tar), and the stdin and stdout can be replaced by a minus sign "-", for example:

[Email protected] ~]# TAR-CVF-Home | TAR-XVF-

 Note that the above example uses ' > ', ' > ' will stream the data to a file or device, so you can use > to write the command output to a file or device. Of course, after writing to the device, you cannot continue to use this data stream. If you need to continue using this data flow, you can use the tee command to stream bidirectional redirects. The tee command resembles the following:

Tee will also send the data stream to the file to go with the screen, and output to the screen, is actually stdout, can continue processing.

Tee [-A] file options and Parameters:-a  : Add data to file in a cumulative (append) way!

The specific use is as follows:

[Email protected] ~]# Last | Tee Last.list | Cut-d ""-f1# This example allows us to save the last output to a last.list file; [email protected] ~]# ls-l/Home | Tee ~/homefile | more# This example is to save the LS data to a ~/homefile, while the screen also has output information! [[email protected] ~]# Ls-l/| Tee-a ~/homefile | more# to pay attention! The files after the tee are overwritten, and if you add the-a option, the information will be accumulated.

Tee allows standard output to be transferred to a file and the same data will continue to be sent to the screen for processing! In addition to allowing us to analyze a piece of data and record it, it can also be used as an intermediate cache disk for processing a single piece of data!

Learn some linux-cutting command split every day.

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.