Command Line Survival Guide: Split and Merge|Linux China

2020/11/2211:56:08 technology 2996

Command Line Survival Guide: Split and Merge|Linux China - DayDayNews

Guide: This section will introduce file splitting and merging operations under Linux command line.

article Word Count: 2706, long read about: 3 minutes

Author: Psiace

As an engineer, we often deal with the command line, but except for the command to work with, you tried to make command to replace every aspect of your life?

In order to allow more fans to use the command line as an effective tool for themselves, Linux China specially invited three authors to write the "Command Line Survival Guide". I hope that through this series of articles, you can change your perspective. Look at the existence of the command line. If you want to experience a different command line, then take a look at today's "Command Line Survival Guide".

This content is a trial reading, and you are welcome to put forward your own opinions and suggestions on today's content. Overview of

operations

often involves large file transmission problems when backing up files. Poor network quality or other problems often cause transmission interruptions and have to be retransmitted. If a large file is split into multiple small files for transmission, and all files are merged after all transmissions are completed, the transmission experience can often be improved.

This section will introduce file splitting and merging operations under Linux command line. The concept of

and the term

split, as the name suggests, is to split a large file into several smaller files, and these small files can be restored after being spliced ​​in order. Under normal circumstances, it is a common way to split according to file size; but because text files have the characteristics of the number of lines, in addition to splitting by size, you can also split by number of lines. Z2z

merge is to splice several smaller files into one larger file. Usually only need to connect in order, which is relatively simple.

Generally, to ensure that the two files before splitting and after the merge are the same, verification is required.

Operation Actual Combat

Scenario 1: Use split to split files

split

is a file splitting utility provided by the Linux environment, which supports both binary files and text files. Normally, it is already built into the system and no additional installation is required.

split by size

binary file and text file split by size use different options:

◈ Binary file use option to specify the file size after splitting.

◈ For text files, use the option to specify the file size after division. The usage of

is similar, only need:

split (about 2.4 GB) into 100MB size as an example:

can see that the original file is split into 25 smaller files, from aa to ay:

scene Two: Use cat to merge files

cat

is a file connection utility provided by the Linux environment, which can connect files and output them to standard output. Normally, it is already built into the system and no additional installation is required. It is worth noting that

, in order to ensure that the merged file is consistent with the original file, the diff command can be used to verify if conditions permit.

merge and split files

can use cat to merge files in the format of cat [file...]> [file name after merge]. This method is valid for both binary files and text files.

takes the previous debian-live-aa to debian-live-ay as an example. You can use this command when merging:

can see that the merged file will be generated in the directory.

uses diff to verify the file

only needs to execute in the format of diff [original file] [current file]. If there is no output, it proves that there is no difference between the two files.

Take comparison and as an example:

small exercise

◈ Try to split the log files in the system in different ways.

technology Category Latest News