LoginSignup
7
7

More than 5 years have passed since last update.

シェルを書くときによく使うものメモ

Last updated at Posted at 2015-11-03

date コマンド

今の日付を yyyy/MM/dd HH:mm:ss 形式で出力する

date "+%Y/%m/%d %H:%M:%S" 

echoコマンド

\nを改行として扱う

-e オプションを付ける(文字列はダブルクォーテーションで囲む)

➜  echo -e "aaaa\nbbbb" 
aaaa
bbbb

if

ifでファイルの存在チェック

# ファイルある
if [ -e ファイルのパス ]; then
  echo "ファイルあるよ"
else
  echo "ファイルないよ"
fi

# ない
if [ ! -e ファイルのパス ]; then
  echo "ファイルない"
fi

while

whileで無限ループ

# とにかく無限にHey!って出力し続ける
while true ; do
  echo "Hey!"
done

# 30秒毎に無限にHey!って出力し続ける
while true ; do
  echo "Hey!"
  sleep 30
done

sed, awk

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