1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

はやしのコマンド備忘録(っ'ヮ 'c)

Last updated at Posted at 2016-06-17

Grep検索

find . -type f -name "*.py" | xargs grep "print" > ../grep_result.txt

カレントディレクトリ配下のファイルの内、指定の文字列が含まれている行を出力する

  • find .
    • 検索するディレクトリ
    • ここでは「.」なのでカレントディレクトリ
  • -name "*.py"
    • ファイ名を指定する
    • ここでは、"*.py"なのですべてのPythonスクリプト
  • grep "print"
    • 検索キーワード
  • ../grep_result.txt
    • 検索結果出力さきのファイルパス
    • 検索対象内のファイルに、検索結果を出力すると、再起的検索することになりエラーとなるので注意する必要がある

ディレクトリの容量を確認

du -m -s * | sort -n
  • -m
    • メガバイト単位で容量を表示する
  • -s *
    • カレントディレクトリ直下のディレクトリとファイルを対象とする
  • sort -n
    • 数字として並び替える

ディレクトリを再帰的に削除

rm -rf directory_name
  • directory_nameはディレクトリの名前

ファイルを検索する

find . -name *.txt
  • find .
    • 検索するディレクトリ
    • ここでは「.」なのでカレントディレクトリ
  • *.txt
    • ファイル名
1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?