Linux Ï´óÎļþÇиîÓëºÏ²¢
ÍùÍùÊÇÓÉÓÚÍøÂç´«ÊäµÄÏÞÖÆ£¬µ¼ÖÂÐí¶àʱ¼ä£¬ÎÒÃÇÐèÒªÔÚ Linux ϵͳϾÙÐдóÎļþµÄÇиÕâÑù½«Ò»¸ö´óÎļþÇиî³ÉΪ¶à¸öСÎļþ£¬¾ÙÐд«Ê䣬´«ÊäÍê±ÏÖ®ºó¾ÙÐкϲ¢¼´¿É¡£
ÎļþÇÐ¸î – split
ÔÚ Linux ϵͳÏÂʹÓà split ÏÂÁî¾ÙÐдóÎļþÇиîºÜÀû±ã
ËÑË÷ÃñÖÚºÅGitHubÔ³ºǫ́»Ø¸´¡°´ò·É»ú¡±£¬»ñÈ¡Ò»·Ý¾ªÏ²Àñ°ü¡£
ÏÂÁîÓï·¨
-a: #Ö¸¶¨Êä³öÎļþÃûµÄºó׺³¤¶È(ĬÒÔΪ2¸ö:aa,ab...) -d: #Ö¸¶¨Êä³öÎļþÃûµÄºó׺ÓÃÊý×ÖÈ¡´ú -l: #ÐÐÊýÖ§½âģʽ(Ö¸¶¨Ã¿¼¸¶àÐÐÇгÉÒ»¸öСÎļþ;ĬÈÏÐÐÊýÊÇ1000ÐÐ) -b: #¶þ½øÖÆÖ§½âģʽ(Ö§³Öµ¥Î»:k/m) -C: #Îļþ¾Þϸ֧½âģʽ(Çиîʱֻ¹Üά³ÖÿÐеÄÍêÕûÐÔ) split [-a] [-d] [-l <ÐÐÊý>] [-b <×Ö½Ú>] [-C <×Ö½Ú>] [ÒªÇиîµÄÎļþ] [Êä³öÎļþÃû]
µÇ¼ºó¸´ÖÆ
ʹÓÃʵÀý
# ÐÐÇиîÎļþ $ split -l 300000 users.sql /data/users_ # ʹÓÃÊý×Öºó׺ $ split -d -l 300000 users.sql /data/users_ # °´×Ö½Ú¾Þϸ֧½â $ split -d -b 100m users.sql /data/users_ ```bash **×ÊÖúÐÅÏ¢** ```bash # ×ÊÖúÐÅÏ¢ $ split --help Usage: split [OPTION]... [FILE [PREFIX]] Output pieces of FILE to PREFIXaa, PREFIXab, ...; default size is 1000 lines, and default PREFIX is 'x'. With no FILE, or when FILE is -, read standard input. Mandatory arguments to long options are mandatory for short options too. -a, --suffix-length=N generate suffixes of length N (default 2) ºó׺Ãû³ÆµÄ³¤¶È(ĬÒÔΪ2) --additional-suffix=SUFFIX append an additional SUFFIX to file names -b, --bytes=SIZE put SIZE bytes per output file ÿ¸öÊä³öÎļþµÄ×Ö½Ú¾Þϸ -C, --line-bytes=SIZE put at most SIZE bytes of records per output file ÿ¸öÊä³öÎļþµÄ×î´ó×Ö½Ú¾Þϸ -d use numeric suffixes starting at 0, not alphabetic ʹÓÃÊý×Öºó׺ȡ´ú×Öĸºó׺ --numeric-suffixes[=FROM] same as -d, but allow setting the start value -e, --elide-empty-files do not generate empty output files with '-n' ²»±¬·¢¿ÕµÄÊä³öÎļþ --filter=COMMAND write to shell COMMAND; file name is $FILE дÈëµ½shellÏÂÁîÐÐ -l, --lines=NUMBER put NUMBER lines/records per output file É趨ÿ¸öÊä³öÎļþµÄÐÐÊý -n, --number=CHUNKS generate CHUNKS output files; see explanation below ±¬·¢chunksÎļþ -t, --separator=SEP use SEP instead of newline as the record separator; ʹÓÃÐÂ×Ö·ûÖ§½â '\0' (zero) specifies the NUL character -u, --unbuffered immediately copy input to output with '-n r/...' ÎÞÐ軺´æ --verbose print a diagnostic just before each ÏÔʾ֧½â½ø¶È output file is opened --help display this help and exit ÏÔʾ×ÊÖúÐÅÏ¢ --version output version information and exit ÏÔʾ°æ±¾ÐÅÏ¢ The SIZE argument is an integer and optional unit (example: 10K is 10*1024). Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000). CHUNKS may be: N split into N files based on size of input K/N output Kth of N to stdout l/N split into N files without splitting lines/records l/K/N output Kth of N to stdout without splitting lines/records r/N like 'l' but use round robin distribution r/K/N likewise but only output Kth of N to stdout GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Full documentation at: <http://www.gnu.org/software/coreutils/split> or available locally via: info '(coreutils) split invocation'
µÇ¼ºó¸´ÖÆ
ÎļþºÏ²¢ – cat
ÔÚ Linux ϵͳÏÂʹÓà cat ÏÂÁî¾ÙÐжà¸öСÎļþµÄºÏ²¢Ò²ºÜÀû±ã
ÏÂÁîÓï·¨
-n: #ÏÔʾÐкŠ-e: #ÒÔ$×Ö·û×÷ΪÿÐеÄ×îºó -t: #ÏÔʾTAB×Ö·û(^I) cat [-n] [-e] [-t] [Êä³öÎļþÃû]
µÇ¼ºó¸´ÖÆ
ʹÓÃʵÀý
# ºÏ²¢Îļþ $ cat /data/users_* > users.sql ×ÊÖúÐÅÏ¢ # ×ÊÖúÐÅÏ¢ $ cat --h Usage: cat [OPTION]... [FILE]... Concatenate FILE(s) to standard output. With no FILE, or when FILE is -, read standard input. -A, --show-all equivalent to -vET -b, --number-nonblank number nonempty output lines, overrides -n -e equivalent to -vE -E, --show-ends display $ at end of each line -n, --number number all output lines -s, --squeeze-blank suppress repeated empty output lines -t equivalent to -vT -T, --show-tabs display TAB characters as ^I -u (ignored) -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB --help display this help and exit --version output version information and exit Examples: cat f - g Output f's contents, then standard input, then g's contents. cat Copy standard input to standard output. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Full documentation at: <http://www.gnu.org/software/coreutils/cat> or available locally via: info '(coreutils) cat invocation'
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇLinux Ï´óÎļþÇиîÓëºÏ²¢µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡
ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£