搜尋
首頁運維linux運維在Linux系統下進行大檔案的切割和合併

往往是因为网络传输的限制,导致很多时候,我们需要在 Linux 系统下进行大文件的切割。这样将一个大文件切割成为多个小文件,进行传输,传输完毕之后进行合并即可。

推荐学习:《linux视频教程

文件切割 - split

在 Linux 系统下使用 split 命令进行大文件切割很方便

命令语法

-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_

帮助信息

# 帮助信息
$ split --help
Usage: split [OPTION]... [FILE [PREFIX]]
Output pieces of FILE to PREFIXaa, PREFIXab, ...;
default size is 1000 lines, and default PREFIX is &#39;x&#39;.
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 &#39;-n&#39;        不产生空的输出文件
      --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;  使用新字符分割
                            &#39;\0&#39; (zero) specifies the NUL character
  -u, --unbuffered        immediately copy input to output with &#39;-n r/...&#39;     无需缓存
      --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 &#39;l&#39; 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 &#39;(coreutils) split invocation&#39;

文件合并 - 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&#39;s contents, then standard input, then g&#39;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 &#39;(coreutils)

以上是在Linux系統下進行大檔案的切割和合併的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:weixin。如有侵權,請聯絡admin@php.cn刪除
Linux操作系統的5個核心組件Linux操作系統的5個核心組件May 08, 2025 am 12:08 AM

Linux操作系統的5個核心組件是:1.內核,2.系統庫,3.系統工具,4.系統服務,5.文件系統。這些組件協同工作,確保系統的穩定和高效運行,共同構成了一個強大而靈活的操作系統。

Linux的5個基本要素:解釋Linux的5個基本要素:解釋May 07, 2025 am 12:14 AM

Linux的五個核心元素是:1.內核,2.命令行界面,3.文件系統,4.包管理,5.社區與開源。這些元素共同定義了Linux的本質和功能。

Linux操作:安全和用戶管理Linux操作:安全和用戶管理May 06, 2025 am 12:04 AM

Linux用戶管理和安全性可以通過以下步驟實現:1.創建用戶和組,使用命令如sudouseradd-m-gdevelopers-s/bin/bashjohn。 2.批量創建用戶和設置密碼策略,使用for循環和chpasswd命令。 3.檢查和修復常見錯誤,如家目錄和shell設置。 4.實施最佳實踐,如強密碼策略、定期審計和最小權限原則。 5.優化性能,使用sudo和調整PAM模塊配置。通過這些方法,可以有效管理用戶和提升系統安全性。

Linux操作:文件系統,進程等Linux操作:文件系統,進程等May 05, 2025 am 12:16 AM

Linux文件系統和進程管理的核心操作包括文件系統的管理和進程的控制。 1)文件系統操作包括創建、刪除、複製和移動文件或目錄,使用命令如mkdir、rmdir、cp和mv。 2)進程管理涉及啟動、監控和終止進程,使用命令如./my_script.sh&、top和kill。

Linux操作:外殼腳本和自動化Linux操作:外殼腳本和自動化May 04, 2025 am 12:15 AM

Shell腳本是Linux系統中用於自動化執行命令的強大工具。 1)Shell腳本通過解釋器逐行執行命令,處理變量替換和條件判斷。 2)基本用法包括備份操作,如使用tar命令備份目錄。 3)高級用法涉及使用函數和case語句管理服務。 4)調試技巧包括使用set-x開啟調試模式和set-e在命令失敗時退出。 5)性能優化建議避免子Shell,使用數組和優化循環。

Linux操作:了解核心功能Linux操作:了解核心功能May 03, 2025 am 12:09 AM

Linux是一個基於Unix的多用戶、多任務操作系統,強調簡單性、模塊化和開放性。其核心功能包括:文件系統:以樹狀結構組織,支持多種文件系統如ext4、XFS、Btrfs,使用df-T查看文件系統類型。進程管理:通過ps命令查看進程,使用PID管理進程,涉及優先級設置和信號處理。網絡配置:靈活設置IP地址和管理網絡服務,使用sudoipaddradd配置IP。這些功能在實際操作中通過基本命令和高級腳本自動化得以應用,提升效率並減少錯誤。

Linux:進入和退出維護模式Linux:進入和退出維護模式May 02, 2025 am 12:01 AM

進入Linux維護模式的方法包括:1.編輯GRUB配置文件,添加"single"或"1"參數並更新GRUB配置;2.在GRUB菜單中編輯啟動參數,添加"single"或"1"。退出維護模式只需重啟系統。通過這些步驟,你可以在需要時快速進入維護模式,並安全地退出,確保系統的穩定性和安全性。

了解Linux:定義的核心組件了解Linux:定義的核心組件May 01, 2025 am 12:19 AM

Linux的核心組件包括內核、shell、文件系統、進程管理和內存管理。 1)內核管理系統資源,2)shell提供用戶交互界面,3)文件系統支持多種格式,4)進程管理通過fork等系統調用實現,5)內存管理使用虛擬內存技術。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!