00. 目录
01. 命令概述
split命令可以将一个大文件分割成很多个小文件,有时需要将文件分割成更小的片段,比如为提高可读性,生成日志等。
在默认情况下将按照每1000行切割成一个小文件 。
15 分钟之后,我要去朋友家聚会。我打算从我的台式机上把一部 700MB 大小的美国大片拷贝出来,带到朋友家去看,可是我的两个优盘都只有 512MB,这让我如何是好?
别急,用 10 分钟赶快来认识一下我们的 split 拆分小能手,一切问题将迎刃而解。当遇到大文件而苦不堪言的时候,split 就会像天使一样解救我们于水火之中
02. 命令格式
split [OPTION] [INPUT [PREFIX]]
- 1
03. 常用选项
把 输入文件 INPUT 按 固定大小 的 文件片 PREFIXaa, PREFIXab,
... 输出; 缺省的 PREFIX 是 `x'. 如果 没有 指定 INPUT, 或 INPUT
是 -, 就从 标准输入 读取 数据.
-b, --bytes=SIZE
输出文件 大小 定为 SIZE 字节
-C, --line-bytes=SIZE
输出文件 大小 定为 最多 SIZE 字节 的 行
-l, --lines=NUMBER
输出文件 大小 定为 NUMBER 行
-d 使用数字而不是字母作为切割后的小文件的后缀;
-v 显示详细的处理信息
-NUMBER
同 -l NUMBER
--verbose
在 打开 每一个 输出文件 之前, 把 诊断信息 送往 标准错误
--help 显示 帮助信息, 然后 结束
--version
显示 版本信息, 然后 结束
指定 SIZE 时 可以 使用 倍乘后缀: b 是 512, k 是 1K, m 是 1
Meg.
b: 512(blocks)
K: 1024(kibiBytes)
KB: 1000(kiloBytes)
M: 1024*1024(mebiBytes)
MB: 1000*1000(megaBytes)
G: 1024*1024*1024(gibiBytes)
GB: 1000*1000*1000(gibaBytes)
T, P, E, Z, Y
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
04. 参考示例
4.1 指定行数来切割
[deng@localhost test]$ split -l 30 passwd
[deng@localhost test]$ ls
passwd xaa xab
- 1
- 2
- 3
默认文件名是xaa,xbb排序的
4.2 指定文件大小来切割
[deng@localhost test]$ split -b 1b passwd
[deng@localhost test]$ ls
passwd xaa xab xac xad xae
[deng@localhost test]$ ls -lh
总用量 24K
-rw-r--r-- 1 deng deng 2.4K 7月 24 15:32 passwd
-rw-rw-r-- 1 deng deng 512 7月 24 15:39 xaa
-rw-rw-r-- 1 deng deng 512 7月 24 15:39 xab
-rw-rw-r-- 1 deng deng 512 7月 24 15:39 xac
-rw-rw-r-- 1 deng deng 512 7月 24 15:39 xad
-rw-rw-r-- 1 deng deng 328 7月 24 15:39 xae
[deng@localhost test]$
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
文件名可以不设置,系统默认新文件以字母x开头,前面每个文件大小是512个字节
4.3 合并文件
[deng@localhost test]$ cat xa* > passwd1
[deng@localhost test]$ ls -l passwd passwd1
-rw-r--r-- 1 deng deng 2376 7月 24 15:32 passwd
-rw-rw-r-- 1 deng deng 2376 7月 24 15:41 passwd1
[deng@localhost test]$
- 1
- 2
- 3
- 4
- 5
4.4 综合示例
生成一个大小为100KB的测试文件
[deng@localhost test]$ dd if=/dev/zero bs=100k count=1 of=data.file
记录了1+0 的读入
记录了1+0 的写出
102400字节(102 kB)已复制,0.00037411 秒,274 MB/秒
[deng@localhost test]$
- 1
- 2
- 3
- 4
- 5
使用split命令将上面创建的date.file文件分割成大小为10KB的小文件
[deng@localhost test]$ split -b 10k data.file
[deng@localhost test]$ ls
data.file xaa xab xac xad xae xaf xag xah xai xaj
[deng@localhost test]$ ls -l
总用量 220
-rw-rw-r-- 1 deng deng 102400 7月 24 15:42 data.file
-rw-rw-r-- 1 deng deng 10240 7月 24 15:43 xaa
-rw-rw-r-- 1 deng deng 10240 7月 24 15:43 xab
-rw-rw-r-- 1 deng deng 10240 7月 24 15:43 xac
-rw-rw-r-- 1 deng deng 10240 7月 24 15:43 xad
-rw-rw-r-- 1 deng deng 10240 7月 24 15:43 xae
-rw-rw-r-- 1 deng deng 10240 7月 24 15:43 xaf
-rw-rw-r-- 1 deng deng 10240 7月 24 15:43 xag
-rw-rw-r-- 1 deng deng 10240 7月 24 15:43 xah
-rw-rw-r-- 1 deng deng 10240 7月 24 15:43 xai
-rw-rw-r-- 1 deng deng 10240 7月 24 15:43 xaj
[deng@localhost test]$
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
文件被分割成多个带有字母的后缀文件,如果想用数字后缀可使用-d参数,同时可以使用-a length来指定后缀的长度
[deng@localhost test]$ split -b 10k data.file -d -a 3
[deng@localhost test]$ ls
data.file x000 x001 x002 x003 x004 x005 x006 x007 x008 x009
[deng@localhost test]$
- 1
- 2
- 3
- 4
为分割后的文件指定文件名的前缀
文件被分割成多个带有字母的后缀文件,如果想用数字后缀可使用-d参数,同时可以使用-a length来指定后缀的长度
[deng@localhost test]$ split -b 10k data.file -d -a 3 split_file
[deng@localhost test]$ ls
data.file split_file003 split_file007 x001 x005 x009
split_file000 split_file004 split_file008 x002 x006
split_file001 split_file005 split_file009 x003 x007
split_file002 split_file006 x000 x004 x008
[deng@localhost test]$
- 1
- 2
- 3
- 4
- 5
- 6
- 7
使用-l选项根据文件的行数来分割文件,例如把文件分割成每个包含10行的小文件
[deng@localhost test]$ split -l 10 data.file
- 1
05. 附录
为了提升驱动代码在不同内核子系统间的可复用能力,OpenHarmony HDF(Hardware Driver Foundation)驱动框架提供了OSAL(Operating System Abstraction Layer)操作系统抽象层接口。OSAL为驱动程序提供了任务、定时器、互斥锁、信号量等基础库相关接口,使驱动相关的实现不再依赖于具体的内核或POSIX接口,是实现驱动可迁移的基石。OpenHarmony HDF驱动框架已经在LiteOS-M,LiteOS-A,Linux内核完成适配,可直接使用。
本文主要分析下驱动适配代码仓中的OSAL的相关接口,主要以适配LiteOS-M内核的OSAL接口为例。OSAL在HDF驱动框架中的位置,见HDF架构图。
1、OSAL头文件
在文件夹drivers/framework/include/osal中定义了OSAL的头文件,对这些头文件的说明如下。
class="table-box">头文件 | 头文件描述 |
---|---|
osal_atomic.h | 原子变量相关接口 |
osal_cdev.h | 字符设备相关接口 |
osal_file.h | 文件相关接口 |
osal_firmware.h | 固件文件相关接口 |
osal_io.h | I/O操作类接口 |
osal_irq.h | 中断相关接口 |
osal_mem.h | 内存申请释放接口 |
osal_mutex.h | 互斥锁相关接口 |
osal_sem.h | 信号量相关接口 |
osal_spinlock.h | 自旋锁相关接口 |
osal_thread.h | 线程相关接口 |
osal_time.h | 时间相关接口 |
osal_timer.h | 定时器相关接口 |
评论记录:
回复评论: