LoginSignup
11
10

More than 5 years have passed since last update.

Linux findコマンド

Last updated at Posted at 2016-08-07
  1. ファイル名で検索

    $ find ./ -name "*.rb"
    
  2. ファイルサイズで検索

    $ find . -size 0  # empty file
    $ find . -size 1000c  # 1000バイト
    $ find . -size 1000k  # 1000KB
    $ find . -size +1000c  # 1000バイト以上
    $ find . -size -1000c  # 1000バイト以下
    
  3. ファイルタイプで検索

    $ find ./ -type f # ファイル
    $ find ./ -type d # フォルダ
    $ find ./ -type l # symbolic link
    
  4. 権限で検索
    権限の確認はこちら
    特定権限マッチ -
    いずれかマッチ +

    $ find ./ -perm -g+w # グループに書き込み権限がある
    $ find ./ -perm 644
    $ find . -perm +111 # ユーザー,グループ,その他のユーザーのいずれかに実行権限ある
    
  5. 時間で検索

    $ find . -amin 120 # 最後にアクセスした時間が2時間前
    $ find . -atime 2  # 最後にアクセスした時間が2日前
    $ find . -mmin -10 -mmin -20 # 10分前から20分前までに変更されたファイル
    $ find . -mtime -10 -mtime -20 # 10日前から20日前までに変更されたファイル
    $ find . -newermt "2015-10-01" -and ! -newermt "2016-01-31" -ls # 2015-10-01から2016-01-31までのファイル
    
  6. ファイル検索して削除

    $ find . -size 0 | xargs rm -rf # 空ファイルを全部削除
    
11
10
1

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
11
10