Linuxコマンド覚書

find

ファイルもしくはディレクトリの検索 実行すると検索結果が出力される

$ find {検索するパス} {検索条件} {オプション}

拡張子を指定して検索

$ find ../../ -name '*.txt'

特定の文字列を含むファイルを検索

$ find Desktop/ -type f -name "*2019*"

sampleという名前が含まれるファイルを検索

$ find /Desktop -name "*sample*" -type f

sampleという名前が含まれるディレクトリを検索

$ find /Desktop -name "*sample*" -type d

名前にsampleが含まれる、パーミッションが644のものを検索

$ find /Desktop -name "*sample*" -perm 644 

昨日更新されたファイルを検索

$ find Desktop/ -mtime 1

0:今日
1:昨日
-3:三日以内に更新されたファイル
+10:10日よりも前に更新されたファイル

空ファイルもしくはディレクトリを検索する

$ find Desktop/ -empty

ファイル名がsmapleを含むかつ.pngファイルを検索する

$ find Desktop/ -name "*sample*" -and  -name "*.png"

ファイル名がsmapleを含むもしくは.pngファイルを検索する

$ find Desktop/ -name "*sample*" -or  -name "*.png"

grep

ファイルの中の文字列を検索する

$ grep {検索正規表現} {パス/ファイル名}

デスクトップにあるsample.txtの中にaaaという文字列がないかを検索する

$ grep aaa Desktop/sample.txt 

検索結果に行番号を表示する

$ grep aaa Desktop/sample.txt -n

大文字小文字を区別せずに検索する

$ grep aaa Desktop/sample.txt -i

検索結果の前後2行分を表示する

$ grep aaa Desktop/sample.txt -C2

ディレクトリ内も検索対象とする

$ grep aaa Desktop/ -r

open

open -a {アプリを指定} {パスとファイル名} 

finderを開く

$ open .

Chromeでデスクトップのsample.jpegを開く

$ open -a "Google Chrome" Desktop/sample.jpeg 

アプリ名にスペースがある場合はダブルクォートで囲う

一階層上の全ての.pngファイルを開く

$ open ../*.png

screencapture

$ screencapture {保存場所とファイル名}

デスクトップにsample.pngという名前で画面キャプチャ

$ screencapture ../Destop/sample.png