1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Linux】ログローテートされたファイルを解凍展開せずに見る方法

Posted at

 ログローテートされたファイルを解凍することなく、中身を見たいってなったときに便利。
というか、ログローテートされたファイルのログを見るときにこのコマンドしか使っていない。
  gunzip -dc ≪ファイル名≫ | less
  gunzip -dc ≪ファイル名≫ | grep "≪検索文字≫"

標準出力をfileAに書き込み、fileAを圧縮した後、それを解凍せずに中身が見れることを確認します。
まずは、標準出力をfileAに書き込みます。

[root@www test]# echo "happynewyear 2025" > fileA
[root@www test]# cat fileA
happynewyear 2025

⇒fileAに書き込まれたことをcatで確認できること

次に、fileAを圧縮します。

[root@www test]# gzip fileA
[root@www test]# ll
合計 8
4 -rw-r--r-- 1 root root 44 2024/12/29 09:29:17 fileA.gz
4 -rw-r--r-- 1 root root 22 2024/12/29 09:32:54 fileB
0 -rw-r--r-- 1 root root  0 2024/12/28 18:13:19 fileC

fileA.gzが作られたこと

最後に、fileA.gzの中身を解凍なしに見ます。
今回はパイプでcatコマンドに標準出力を渡します。

[root@www test]# gunzip -dc fileA.gz | cat
happynewyear 2025

fileA.gzの内容が表示されること
grepも試してみます。

[root@www test]# gunzip -dc fileA.gz | grep "2025"
happynewyear 2025

2025が赤文字となっていること

1
0
7

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?