Usage of the split command in Linux, specific code examples
In the Linux system, the split command is a very useful tool. It can be used to split a large file into multiple small files, and can be Split by the specified size, number of lines, or number of bytes. This article will introduce the usage of split command and provide specific code examples.
The basic syntax of the split command is as follows:
split [选项] 文件名 [输出文件名前缀]
Next, we will introduce the various options and usage examples of the split command in detail.
Split the file according to the specified size
Use option "-b" to split the file according to the specified size. Size can be specified in bytes (default), KB, MB, GB, etc.
split -b 100M largefile.zip smallfiles
The above code splits largefile.zip into multiple small files prefixed with smallfiles according to the size of 100MB.
Split the file according to the specified number of lines
Use the option "-l" to split the file according to the specified number of lines.
split -l 1000 logfile.txt smallfiles
The above code divides logfile.txt into multiple small files prefixed with smallfiles according to the number of lines of 1000.
Split the file according to the specified number of bytes
Use option "-C" to split the file according to the specified number of bytes.
split -C 10k data.txt smallfiles
The above code splits data.txt into multiple small files prefixed with smallfiles according to the number of bytes of 10KB.
Split files by file prefix
Use option "-d" to use numbers as file prefixes instead of the default letter prefix.
split -b 100M largefile.zip smallfiles -d
The above code splits largefile.zip into multiple small files prefixed with numbers according to the size of 100MB.
Specify the suffix of the split file name
Use option "-a" to specify the suffix length of the split file name, the default is 2.
split -b 100M largefile.zip smallfiles -a 3
The above code splits largefile.zip into multiple small files with a prefix of smallfiles and a suffix length of 3 according to the size of 100MB.
Through the above examples, we can see that the split command is very flexible in actual use and can split files according to different needs. Please note that the split command will modify the original file, so be sure to back up the file before using it.
In daily work, the split command can help us better handle large files and improve operating efficiency. I hope this article will help you understand the usage of the split command.
The above is the detailed content of How to use split command in Linux. For more information, please follow other related articles on the PHP Chinese website!