【Linux】ファイル内容を操作するコマンド

■ はじめに

ファイル内容を操作するコマンドを書き溜めていく

目次

【1】sort
【2】uniq
【3】何もしない組み込みコマンド「:」でファイルを空にする

【1】sort

* 並び替え

https://atmarkit.itmedia.co.jp/ait/articles/1611/09/news020.html

オプション

Option Explanation
-n 文字列を数値と見なして並べ替える
-r 逆順で並べ替える

使用例

# ディスク容量がでかいTop5を表示
du | sort -nr | head -n 5

【2】uniq

* 一意にする

【3】何もしない組み込みコマンド「:」でファイルを空にする

# 何もしない組み込みコマンド「:」でファイルを空にする
: > hello.txt

https://qiita.com/xtetsuji/items/381dc17241bda548045d

$ echo "Hello" > hello.txt

$ cat hello.txt
Hello

# カラにする
$ : > hello.txt

# 確認
$ cat hello.txt

関連記事

ネットワーク系コマンド ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2016/07/27/214633
ネットワーク系コマンド ~ IPアドレス編 ~
https://dk521123.hatenablog.com/entry/2016/10/03/223638
ファイルの内容を表示するコマンド
https://dk521123.hatenablog.com/entry/2016/08/08/235934
ファイル内容を操作するコマンド
https://dk521123.hatenablog.com/entry/2023/07/26/000000
Linux ~ パフォーマンスに関わるコマンド ~
https://dk521123.hatenablog.com/entry/2015/02/21/112554