Linux下如何实现文件切割
这篇文章主要介绍了Linux下如何实现文件切割,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
linux下文件分割可以通过split命令来实现,可以指定按行数分割和安大小分割两种模式。Linux下文件合并可以通过cat命令来实现,非常简单
在 Linux 系统下使用 split 命令进行大文件切割很方便
[1] 命令语法
#-a:指定输出文件名的后缀长度(默认为2个:aa,ab...)#-d:指定输出文件名的后缀用数字代替#-l:行数分割模式(指定每多少行切成一个小文件;默认行数是1000行)#-b:二进制分割模式(支持单位:k/m)#-C:文件大小分割模式(切割时尽量维持每行的完整性)split[-a][-d][-l][-b][-C][要切割的文件][输出文件名]
[2] 使用实例
#行切割文件$split-l300000users.sql/data/users_#使用数字后缀$split-d-l300000users.sql/data/users_#按字节大小分割$split-d-b100musers.sql/data/users_
[3] 帮助信息
#帮助信息$split--helpUsage:split[OPTION]...[FILE[PREFIX]]OutputpiecesofFILEtoPREFIXaa,PREFIXab,...;defaultsizeis1000lines,anddefaultPREFIXis'x'.WithnoFILE,orwhenFILEis-,readstandardinput.Mandatoryargumentstolongoptionsaremandatoryforshortoptionstoo.-a,--suffix-length=NgeneratesuffixesoflengthN(default2)后缀名称的长度(默认为2)--additional-suffix=SUFFIXappendanadditionalSUFFIXtofilenames-b,--bytes=SIZEputSIZEbytesperoutputfile每个输出文件的字节大小-C,--line-bytes=SIZEputatmostSIZEbytesofrecordsperoutputfile每个输出文件的最大字节大小-dusenumericsuffixesstartingat0,notalphabetic使用数字后缀代替字母后缀--numeric-suffixes[=FROM]sameas-d,butallowsettingthestartvalue-e,--elide-empty-filesdonotgenerateemptyoutputfileswith'-n'不产生空的输出文件--filter=COMMANDwritetoshellCOMMAND;filenameis$FILE写入到shell命令行-l,--lines=NUMBERputNUMBERlines/recordsperoutputfile设定每个输出文件的行数-n,--number=CHUNKSgenerateCHUNKSoutputfiles;seeexplanationbelow产生chunks文件-t,--separator=SEPuseSEPinsteadofnewlineastherecordseparator;使用新字符分割'\0'(zero)specifiestheNULcharacter-u,--unbufferedimmediatelycopyinputtooutputwith'-nr/...'无需缓存--verboseprintadiagnosticjustbeforeeach显示分割进度outputfileisopened--helpdisplaythishelpandexit显示帮助信息--versionoutputversioninformationandexit显示版本信息TheSIZEargumentisanintegerandoptionalunit(example:10Kis10*1024).UnitsareK,M,G,T,P,E,Z,Y(powersof1024)orKB,MB,...(powersof1000).CHUNKSmaybe:NsplitintoNfilesbasedonsizeofinputK/NoutputKthofNtostdoutl/NsplitintoNfileswithoutsplittinglines/recordsl/K/NoutputKthofNtostdoutwithoutsplittinglines/recordsr/Nlike'l'butuseroundrobindistributionr/K/NlikewisebutonlyoutputKthofNtostdoutGNUcoreutilsonlinehelp:Fulldocumentationat:oravailablelocallyvia:info'(coreutils)splitinvocation'2. 文件合并 – cat
在 Linux 系统下使用 cat 命令进行多个小文件的合并也很方便
[1] 命令语法
#-n:显示行号#-e:以$字符作为每行的结尾#-t:显示TAB字符(^I)cat[-n][-e][-t][输出文件名]
[2] 使用实例
#合并文件$cat/data/users_*>users.sql
[3] 帮助信息
#帮助信息$cat--hUsage:cat[OPTION]...[FILE]...ConcatenateFILE(s)tostandardoutput.WithnoFILE,orwhenFILEis-,readstandardinput.-A,--show-allequivalentto-vET-b,--number-nonblanknumbernonemptyoutputlines,overrides-n-eequivalentto-vE-E,--show-endsdisplay$atendofeachline-n,--numbernumberalloutputlines-s,--squeeze-blanksuppressrepeatedemptyoutputlines-tequivalentto-vT-T,--show-tabsdisplayTABcharactersas^I-u(ignored)-v,--show-nonprintinguse^andM-notation,exceptforLFDandTAB--helpdisplaythishelpandexit--versionoutputversioninformationandexitExamples:catf-gOutputf'scontents,thenstandardinput,theng'scontents.catCopystandardinputtostandardoutput.GNUcoreutilsonlinehelp:Fulldocumentationat:oravailablelocallyvia:info'(coreutils)catinvocation'
感谢你能够认真阅读完这篇文章,希望小编分享的“Linux下如何实现文件切割”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。