pbr*_*ult 109 linux command-line
是否有类似cat
Linux 的命令可以从文件中返回指定数量的字符?
例如,我有一个文本文件,如:
Hello world
this is the second line
this is the third line
Run Code Online (Sandbox Code Playgroud)
我想要的东西会返回前5个字符,这将是"你好".
谢谢
Dan*_*Dan 179
head
也有效:
head -c 100 file # returns the first 100 bytes in the file
Run Code Online (Sandbox Code Playgroud)
..将提取前100个字节并返回它们.
使用head
这个的好处是tail
匹配的语法:
tail -c 100 file # returns the last 100 bytes in the file
Run Code Online (Sandbox Code Playgroud)
小智 45
您可以使用dd提取任意块的字节.
例如,
dd skip=1234 count=5 bs=1
Run Code Online (Sandbox Code Playgroud)
将字节1235到1239从其输入复制到其输出,并丢弃其余部分.
要从标准输入中获取前五个字节,请执行以下操作:
dd count=5 bs=1
Run Code Online (Sandbox Code Playgroud)
请注意,如果要指定输入文件名,则dd具有旧式参数解析,因此您可以执行以下操作:
dd count=5 bs=1 if=filename
Run Code Online (Sandbox Code Playgroud)
还要注意dd详细宣布它做了什么,所以为了抛弃它,做:
dd count=5 bs=1 2>&-
Run Code Online (Sandbox Code Playgroud)
要么
dd count=5 bs=1 2>/dev/null
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
113330 次 |
最近记录: |