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?

RHEL9系で特定時間帯に作成されたファイルを検索する方法(find コマンド)

1
Posted at

はじめに

試験環境で出力されたファイルが、ファイル名も出力先も全く分からない状態で、出力された日時(テスト操作した時間帯)しか分からない状態で
ファイルを探したかったのでchatGPTに相談したところ、下記方法を提案してもらった。
そのままchatGPTにナレッジベースの情報に整形してもらった。(以下内容)

概要

  • RHEL9/RHEL8 などの Linux 環境において、特定の時間帯に作成されたファイルを検索するには find コマンドの -newermt オプションを使用するのが最も簡便。
  • 時刻範囲を「基準時刻(開始)」と「基準時刻(終了)」で区切り、間に作成されたファイルを効率的に抽出できる。

手順

1. 基本の検索方法(時間帯を指定)

以下の例は「2025年11月19日の 18:00〜19:00 の間 に作成されたファイル」を検索する場合。

find /path/to/dir
-newermt "2025-11-19 18:00" ! -newermt "2025-11-19 19:00"

2. 今日の特定時間帯で検索する場合

find /path/to/dir
-newermt "$(date +%Y-%m-%d) 18:00"
! -newermt "$(date +%Y-%m-%d) 19:00"

3. よくある失敗例と対処

  • -mmin や -mtime を使うと特定時刻帯を正確に絞れない
  • 時刻は引用符で囲む(半角)
  • 全角クォートが混入するとエラーの原因となる

関連情報

  • -newermt は GNU findutils 固有機能のため、UNIX では使用できない環境がある
  • 詳細は man find を参照

改訂履歴

  • v1.0 (2025-11-28):初版作成
1
0
0

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?