LoginSignup
0
0

More than 3 years have passed since last update.

【インフラ】whileコマンドまとめ

Last updated at Posted at 2021-01-15

1. 基本的なwhile文

コマンド
while true
> do
> echo "hello world"
> sleep 1
> done
出力結果
// 実施結果
hello world  // 際限なく繰り返す
hello world

ファイル検索 + 中身の文字列検索

コマンド
$ find ./ -type f -name "sample.txt" | while read line;
> do
> $line
> grep sample $line
> done
出力結果
./tmp/sample.txt
sample

ファイル検索 + 文字列検索(検索対象一部除外)

コマンド
$ find ./ -type f \! \( -name "exclusion" -o "test" \) | while read line;
> do
> echo $line
> grep sample $line
> done
出力結果
./tmp/sample.txt
sample

ディレクトリ情報検索

コマンド
$ find / -type d | xargs ls -ld | awk '{print $3,$4,$6,$9}' | sort
出力結果
root root 1月 14日 /tmp/test

Vim頻出操作

1行目先頭:1G or gg
最終行先頭:G

カーソル行先頭:^
カーソル行末尾:$

1語次へ:w
1語前へ:b
単語末尾:e

取り消し:u

1行コピペ:yyp
複数行コピペ:10yyp

1行削除:dd
複数行削除:10dd

置換:%s/before/after/g
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