0
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?

More than 3 years have passed since last update.

よく使うLinuxコマンド

Posted at

よく使用するLinuxコマンド・記号をまとめました。

目次

1. find
2. grep
3. diff
4. 記号

find

ファイルやディレクトリを検索するコマンド

基本的な使い方

$ find 検索場所  [オプション]  検索ファイル名

よく使うオプションなど

オプション 意味
-name ファイル名を指定して検索(ワイルドカードを使用して、部分検索が可能) find ./usr/ -name \*.txt
-iname 文字の大小を区別せずにファイル名を検索 find ./usr/ -name test.txt
-type f ファイルのみを対象に検索
-type d ディレクトリのみを対象に検索
-size ファイルの容量を指定して検索 find /var/log -size -100k
-anewer 変更日時よりも後にアクセスしたファイル・ディレクトリを検索 find ./usr/ -anewer ./usr/hoge.txt
-newer 指定したファイルの更新日時よりも後にアクセスしたファイル・ディレクトリを検索
-empty ファイル容量が0のファイル/ディレクトリを検索

演算子も使用することでより検索の幅を広げることができます。

演算子 意味
-and 複数条件(AND検索) find ./usr/ -type f -and -empty
-or 複数条件(OR検索)
-not 条件不一致検索 find ./usr/ -not -type f

grep

文字列を検索するコマンド

基本的な使い方

$ grep [オプション] 検索文字列 対象ファイル名

よく使うオプション

オプション 意味
-E 拡張正規表現で検索 grep –E 'a|b' ./usr/*
-e [検索文字列] パターンを指定して検索 grep -e 'hoge' test.txt
-i 大文字と小文字を区別せず検索
-v 一致しないものを検索
-m [数字] 数字の行分だけ検索結果を表示
–n 検索結果に行数を表示

diff

ファイルを比較するコマンド

基本的な使い方

$ diff [オプション] ファイル名1 ファイル名2

よく使うオプション

オプション 意味
-b スペースの差分は無視して差分を表示
-c context形式で差分を表示
-i 大文字と小文字の区別を無視して差分を表示
-s 差分があれば差分を出力し、無ければ差分なしのメッセージを出力
--color 色付きで差分を表示

記号

>

出力先を変更

# 「hello world」をresult.txtに出力
$ echo hello world > result.txt

>>

新規作成ではなく、既存のテキストファイルに追記する

# 「hello world」を既存のresult2.txtに出力
$ echo hello world >> result.txt

&

バックグランドジョブとして実行

$ echo 1000 &

&&

コマンドを連結して実行

echo hello world && echo world
0
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
0
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?