moreutils 這個套件,包含了一些有趣功能的小工具
可以透過 dnf install moreutils 或 apt install moreutils 安裝
套件包含以下工具,個人覺得比較實用的是 ifdata、pee、sponge、ts、vidir
/usr/bin/chronic
/usr/bin/combine
/usr/bin/errno
/usr/bin/ifdata
/usr/bin/ifne
/usr/bin/isutf8
/usr/bin/lckdo
/usr/bin/mispipe
/usr/bin/pee
/usr/bin/sponge
/usr/bin/ts
/usr/bin/vidir
/usr/bin/vipe
/usr/bin/zrun
chronic 用來隱藏正常執行結果的標準輸出
好像沒什麼用,使用 > /dev/null 可以達到一樣的效果
combine 布林合併兩分文件
combine file1 and file2 兩分文件都有則輸出行
combine file1 not file2 輸出只存在 file1 但不存在 file2 的行
combine file1 or file2 相當於 cat file1 file2
combine file1 xor file2 輸出只存在 file1 或 file2 的資料
errno 查詢 errno 名稱及描述
ifdata 直抓網路卡各項資訊
例如: ifdata -pa eth0 可以直接取出 IPv4 IP
ifne 標準輸入不為空時,執行後續指令
date | echo hello # 會出現 hello
true | echo hello # 不會出現 hello
isutf8 檢查檔案是否是合法 UTF-8 格式
現在系統已全面都是 UTF-8,好像沒什麼用了
lckdo 指定 lock file,避免指令重複執行
跟 flock 類似,man page 也建議使用 flock
mispipe 相當於 command1 | command2
和 pipe 的差異是使用 mispipe command1 command2 會回傳 command1 的 exit status
pee 複製標準輸入,pipe 給多支程式
類似 tee,tee 是將標準輸入寫到檔案,pee 是將它 pipe 給程式,可以多個,
通常用 pee 的情況也是要 pipe 給多個程式才需要它
例如: date | pee cat cat 執行結果可以看到兩個日期
sponge 這個指令會接收到所有 input 後才會輸出,可以做到同檔操作
例如: grep abc file | sponge file
若不使用 sponge,一般做法要兩行
grep abc file > file.tmp
mv file.tmp file
ts 在任何 input 上加上時間
這指令很好用,例如: ping 1.1.1.1 | ts
vidir 可以在 vi 模式進行檔案操作
例如刪除,改檔名,存檔後會真的刪除及改檔名
vipe 編輯 pipe
在 command1 | command2 中間,加入 vipe,command1 | vipe | command2,可以對資料異動後,再 pipe 給 command2
zrun 在不解開 .gz 的情況下,對解開的檔案進行操作
背景做法是解壓暫存檔,把暫存檔名當參數餵給 command
例如: zrun grep abc file1.gz