ラベル bash の投稿を表示しています。 すべての投稿を表示
ラベル bash の投稿を表示しています。 すべての投稿を表示

2020/05/03

ファイルのバックアップ時に、ファイル名に時間を追加する -- Linux, dateコマンド


  • GOAL
    Linuxでファイルのバックアップ取るときに、日付情報を追記する
  • HOW
    date コマンドを使う。
-> % ll
total 8
-rw-r--r--  1 toshi  staff    14B  5  3 00:49 testfile.txt

# Unix時間を追記する
-> % cp testfile.txt testfile.txt`date "+%s"`
-> % ll
total 16
-rw-r--r--  1 toshi  staff    14B  5  3 00:49 testfile.txt
-rw-r--r--  1 toshi  staff    14B  5  3 00:50 testfile.txt1588434625

# YYYYMMDDHHMMSSを追記する
-> % cp testfile.txt testfile.txt`date "+%Y%m%d%H%M%S"`
-> % ll
total 24
-rw-r--r--  1 toshi  staff    14B  5  3 00:49 testfile.txt
-rw-r--r--  1 toshi  staff    14B  5  3 00:50 testfile.txt1588434625
-rw-r--r--  1 toshi  staff    14B  5  3 00:51 testfile.txt20200503005117

# ハイフンでつなぐ -YYYY-MM-DDを追記する
-> % cp testfile.txt testfile.txt`date "+-%Y-%m-%d"`
-> % ll
total 48
-rw-r--r--  1 toshi  staff    14B  5  3 00:49 testfile.txt
-rw-r--r--  1 toshi  staff    14B  5  3 00:52 testfile.txt-2020-05-03
-rw-r--r--  1 toshi  staff    14B  5  3 00:50 testfile.txt1588434625
-rw-r--r--  1 toshi  staff    14B  5  3 00:51 testfile.txt20200503005117

2020/02/11

GCP: gcloud コマンドラインで、GAEの全インスタンスを停止する --- GCP,GAE,shellscript,gcloud

・Goal
 テストで作成したGAEの全サービスの全インスタンスをコマンドラインから削除・停止する。バージョン名等を指定せずに、どんどんデプロイすると稼働中のインスタンスが増える。それをコマンドラインで一気に全停止する。コンソール画面からだと、サービス毎/バージョン毎にプチプチと停止する必要があり面倒だった。。。

・How
 これが基本形
 ~$ gcloud app instances delete [instance ID] -v [version] -s [service]

・Example
# step1  一覧で確認
~ $ gcloud app instances list
SERVICE  VERSION  ID                                      VM_STATUS  DEBUG_MODE
default  master   00XXXXXXX                               N/A
test1    master   00XXXXXX1                               N/A
test2    master   00686ff30                               N/A

# step2 削除
~ $ gcloud app instances list | sed 1d | awk '{print $1, $2, $3}' | while read s v id; do gcloud app instances delete $id -v $v -s $s --quiet; done
Deleting the instance [default/master/00XXXXXXX].
Deleted [https://appengine.googleapis.com/v1/apps/---].
Deleting the instance [test1/master/00XXXXXX1].
Deleted [https://appengine.googleapis.com/v1/apps/---].
Deleting the instance [test2/master/00686ff30].
Deleted [https://appengine.googleapis.com/v1/apps/---].

# 説明
~ $ gcloud app instances list | \ # インスタンスのリストを出力
sed 1d | \ # 一行目をカット
awk '{print $1, $2, $3}' | \ # awk できれいにする。(この処理は不要・・・)
# 以下のハイライトの箇所で、順番に消していく。y/nを聞かれるので --quiet を追加
while read s v id; do gcloud app instances delete $id -v $v -s $s --quiet; done

2017/01/12

.bash コマンドインデックス

.bash のコマンド集

1. which bash - bash の種類を確認
   #/bin/bash
   #この結果をスクリプトの一行目に表示す
   #!/bin/bash
2. cd - フォルダの変更
3. ls - フォルダの中身を表示
4. rm - ファイル、フォルダの削除
5. cp - ファイルのコピー
6. mv - ファイルの移動
7. mkdir - ディレクトリを作成
8. pwd - 現在のフォルダパスを表示
9. chmod - ファイル・ディレクトリのアクセス権限変更
10. tee - 標準出力+ファイル出力の同時出力
11. awk - 文字列コントロール/編集
12. xargs - 
標準入力から生成したコマンドラインを実行する