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?

# AWS学習ログ Day9(2026-02-26)

0
Posted at

今日やったこと

教材

Cloudtech

時間

25分 × 1セット


学んだこと・やったこと

グロブ(Glob)について

特定の条件に一致する ファイル名 / ディレクトリ名 をまとめて指定できる仕組み(ワイルドカード)。

よく使うパターン例

  • ls -l [ab]*
    先頭が a または b のものに一致

  • ls -l [a-c]*
    先頭が a〜c のものに一致(連続範囲の指定)

  • ls -l [^ab]*
    先頭が a でも b でもない ものに一致(否定)

  • ls -l t?.sh
    ?任意の1文字
    例:ta.sh / t1.sh などに一致(ただし t10.sh は一致しない)

  • ls -l {b*,c*,*est*}
    {}複数パターンをまとめて指定(ブレース展開)
    先頭が b / 先頭が c / どこかに est を含む、のいずれかに一致


grep コマンド

ファイルの中から 指定した文字列を含む行を検索する。

  • grep root /etc/passwd
    /etc/passwd から root を含む行を検索

  • grep root /etc/*
    /etc/ 配下のファイル群から root を含む行を検索
    ※ディレクトリが含まれると警告が出る場合がある

よく使うオプション

  • -i:大文字小文字を区別しない
  • -v:一致しない行を表示(除外)

正規表現(grep側の話)

※ グロブ(ファイル名展開)と、grepの正規表現は別物。

  • grep 'ro..' /etc/passwd
    .任意の1文字(2個なので任意2文字)
    例:root などに一致

  • grep 'r.*' /etc/passwd
    .*任意の文字が0文字以上続く
    r で始まるパターンに広く一致

補足:パターンはシングルクォート '...' で囲うと、シェル側の解釈を避けられて安全


egrep(= grep -E)

拡張正規表現を使うgrep。最近は egrep より grep -E が推奨されることが多い。


less コマンド

大きなファイルをページングして閲覧する。

  • f:次ページ
  • b:前ページ
  • q:終了

パイプ(|

前のコマンドの出力を、次のコマンドの入力に渡す。

  • grep root /etc/* | less
    検索結果を less で見やすく表示

head / tail

head

ファイルの先頭を表示する。

  • head -n 20 file.txt(先頭20行)

tail

ファイルの末尾を表示する。

  • tail -n 20 file.txt(末尾20行)
  • tail -f file.txt(追記をリアルタイム監視)

感想

ちょっと勉強をサボってしまったので、また今日から再開する。

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?