一.split說明
split可以用來切割一個記錄檔,這樣便於處理日誌。比如有一個12G的日誌,需要刪除某一行資料,知道行號,但用sed和vi比較慢,
就可以先用 split 切割 ,然後再刪除那行,最後再重組合
二.使用說明
[root@bogon Desktop]# split --help
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 print a diagnostic to standard error just
before each output file is opened
--help display this help and exit
--version output version information and exit
SIZE may have a multiplier suffix: b for 512, k for 1K, m for 1 Meg.
-a 切割後的檔案名稱的後幾位,用幾位元字表示。預設是兩位-b 切割後的檔案的大小-C 切割後的檔案每行多少位元組數-d 切割後的檔案名稱的後幾位用數字代替字母。預設是字母xx-l 切割後的檔案,每個檔案都少行
三.舉例說明
1.產看檔案
[root@bogon Desktop]# lltotal 388-rw-r--r-- 1 root root 4803 Feb 26 2009 gnome-terminal.desktop-rw-r--r-- 1 root root 349027 May 5 04:06 mysql_data.gz-rw------- 1 root root 1108 Apr 25 19:23 new filedrwxrwxrwx 2 root root 4096 Apr 24 06:39 NFS-rw-r--r-- 1 root root 285 May 5 22:02 split.log
2.切割後檔案名稱尾碼為3個字母
[root@bogon Desktop]# split -a 3 split.log [root@bogon Desktop]# lltotal 396-rw-r--r-- 1 root root 4803 Feb 26 2009 gnome-terminal.desktop-rw-r--r-- 1 root root 349027 May 5 04:06 mysql_data.gz-rw------- 1 root root 1108 Apr 25 19:23 new filedrwxrwxrwx 2 root root 4096 Apr 24 06:39 NFS-rw-r--r-- 1 root root 285 May 5 22:02 split.log-rw-r--r-- 1 root root 285 May 5 23:16 xaaa
3.切割後檔案名稱尾碼為3個字母,切割後的檔案,每個檔案兩行內容,
[root@bogon Desktop]# split -a 3 -l 2 split.log[root@bogon Desktop]# lltotal 412-rw-r--r-- 1 root root 4803 Feb 26 2009 gnome-terminal.desktop-rw-r--r-- 1 root root 349027 May 5 04:06 mysql_data.gz-rw------- 1 root root 1108 Apr 25 19:23 new filedrwxrwxrwx 2 root root 4096 Apr 24 06:39 NFS-rw-r--r-- 1 root root 285 May 5 22:02 split.log-rw-r--r-- 1 root root 76 May 5 23:17 xaaa-rw-r--r-- 1 root root 109 May 5 23:17 xaab-rw-r--r-- 1 root root 100 May 5 23:17 xaac
4.切割後檔案名稱尾碼為3個(位)數字,切割後的檔案,每個檔案兩行內容,
[root@bogon Desktop]# split -a 3 -l 2 -d split.log[root@bogon Desktop]# lltotal 436-rw-r--r-- 1 root root 4803 Feb 26 2009 gnome-terminal.desktop-rw-r--r-- 1 root root 349027 May 5 04:06 mysql_data.gz-rw------- 1 root root 1108 Apr 25 19:23 new filedrwxrwxrwx 2 root root 4096 Apr 24 06:39 NFS-rw-r--r-- 1 root root 285 May 5 22:02 split.log-rw-r--r-- 1 root root 76 May 5 23:17 x000-rw-r--r-- 1 root root 109 May 5 23:17 x001-rw-r--r-- 1 root root 100 May 5 23:17 x002-rw-r--r-- 1 root root 76 May 5 23:17 xaaa-rw-r--r-- 1 root root 109 May 5 23:17 xaab-rw-r--r-- 1 root root 100 May 5 23:17 xaac
四.參考man split
聲明:本文檔可以隨意更改,但必須署名原作者
作者:鳳凰舞者 qq:578989855