首頁  >  文章  >  運維  >  詳解Linux下文件的切分與合併方法

詳解Linux下文件的切分與合併方法

巴扎黑
巴扎黑原創
2017-08-17 10:14:221808瀏覽

linux下文件分割可以透過split指令來實現,可以將一個大文件拆分成指定大小的多個文件,並且拆分速度非常的快,可以指定按行數分割和安大小分割兩種模式。 Linux下檔案合併可以透過cat指令來實現,非常簡單。

在Linux下用split進行檔案分割

先看下說明文檔

Usage: split [OPTION]... [INPUT [PREFIX]]

Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default

size is 1000 lines, and default PREFIX is `x'.  With no INPUT, or when INPUT

is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.

  -a, --suffix-length=N   use suffixes of length N (default 2 ) 指定分割檔案的後綴長度

  -b, --bytes=SIZE        put SIZE bytes per output file 以位元組拆分,預設單位位元組

  -C, --line -bytes=SIZE   put at most SIZE bytes of lines per output file  指定單行的最大大小,預設單位位元組

  -d, --numeric-suffixes  use numeric suffixes instead of alphabetic 以數字分割為分割檔案的字尾

  -l, --lines=NUMBER      put NUMBER lines per output file  按行數分割

#      --verbose                  output file is opened

      --help     display this help and exit

      --version  output version information and exit

一:指定後檔案模式一:指定後檔案行數

對與txt文字文件,可以透過指定分割後文件的行數來進行文件分割。

指令:

split -l 300 large_file.txt new_file_prefix

切分後預設產生加上後綴aa, ab, ac...以此類推, 當然也可以自訂後綴。

模式二:指定分割後檔案大小

split -b 10m server.log waynelog

對二進位檔案我們同樣也可以按檔案大小來分隔。

在Linux下用cat進行檔案合併

指令:

cat small_files* > large_file

以上是詳解Linux下文件的切分與合併方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn