0
2

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 1 year has passed since last update.

よく忘れるコマンドとかメモ

Last updated at Posted at 2017-02-01

いつも忘れるのでメモ

パイプでつないだコマンドの戻り値

コマンドの実行結果をture,false,errorで受け取りたい時

$ ll | grep sample > /dev/null 2>&1; echo $?

結果があれば0なければ1が返る

エラーの場合には2が返る

$ ll aaaa > /dev/null 2>&1; echo $?
2

戻り値0,1,2の意味

$ ls --help

# *snip*

Exit status:
 0  if OK,
 1  if minor problems (e.g., cannot access subdirectory),
 2  if serious trouble (e.g., cannot access command-line argument).

# *snip*

参考:http://www.mazn.net/blog/2011/09/09/532.html

ポートスキャン

$ nmap -p 22 192.168.33.10 -P0

Starting Nmap 6.40 ( http://nmap.org ) at 2017-08-03 04:35 UTC
Nmap scan report for 192.168.33.10
Host is up (0.00076s latency).
PORT   STATE SERVICE
22/tcp open  ssh

Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds
STATE desc
open 開いている
closed 閉じている
filtered わからない

firewalld設定

$ sudo firewall-cmd --permanent --zone=public --add-service=http 
$ sudo firewall-cmd --permanent --zone=public --add-service=https
$ sudo firewall-cmd --permanent --zone=public --add-port=8000/tcp 
$ sudo firewall-cmd --reload

ssh秘密鍵の変換

puttyをインストール

$ brew install putty

pem -> ppk

$ puttygen sample.pem -O private -o sample.ppk

ppk -> id_rsa

$ puttygen sample.ppk -O private-openssh -o id_rsa

ssh-keygen

$ ssh-keygen -f ./id_rsa -t rsa -C 'example@com' -N ''
$ ssh-keygen -f ./id_rsa -t rsa -b 4096 -C 'example@com' -N ''

ssh-add

$ eval `ssh-agent`
$ ssh-add ~/.ssh/id_rsa
$ ssh-add -l

公開鍵を紛失した時

秘密鍵から公開鍵を生成する

$ ssh-keygen -y -f id_rsa > id_rsa.pub

~/.ssh/configの書き方

Host 任意の接続名
    HostName ホスト名
    User ユーザー名
    Port ポート番号
    IdentityFile 秘密鍵のPATH(~/.ssh/hoge.key)
    # sshd サーバと応答確認する間隔
    ServerAliveInterval 60
$ chmod 600 ~/.ssh/config

参考:ssh 接続をタイムアウトしないようにする

踏み台を経由する必要があっても、1回のsshコマンドで対象サーバーに接続する

~/.ssh/config
# ホスト間認証の方式を設定する。sierraでデフォルトで無効にされているDSA鍵を有効にする
HostKeyAlgorithms +ssh-dss
# 秘密鍵を読み込むタイミングでエージェントに自動的に鍵を登録させる
# 毎度ssh-addコマンドを叩く必要がなくなる
AddKeysToAgent yes
# エージェント転送を有効にする
Host *
ForwardAgent yes

# 踏み台サーバーの情報
Host gateway
    HostName [踏み台サーバーのホスト名 or IPADDR]
    User sample_user

# 接続するサーバーの情報
Host sample_server
    HostName [接続先サーバーのホスト名 or IPADDR]
    User sample_user
    Port 22
    IdentityFile ~/.ssh/id_rsa
    ServerAliveInterval 60
    ProxyCommand ssh gateway nc %h %p

シェルスクリプトで実行中のスクリプトの絶対パスを取得する

SCRIPT_DIR=$(cd $(dirname $0); pwd)
echo $SCRIPT_DIR

参考:[bash] 実行スクリプトの絶対パスの取得

psコマンドでプロセスIDのみ抽出する

$ ps -e | grep 'php' | awk '{print $1}'

出力結果の改行も除去する場合

$ ps -e | grep 'php' | awk '{print $1}' | tr '\n' ' '

一括置換

カレントディレクトリ以下の、拡張子がphpのファイル内にある、namespace app\modules\samplenamespace application\modules\sampleに全て書き換える場合

$ grep -lr 'namespace app\\modules\\sample' ./*.php \
  | xargs sed -i -e 's/namespace app\\modules\\sample/namespace application\\modules\\sample/g'

git submodule

.gitmodules
[submodule "sample-repo"]
  path = sample-repo
  url = repositoryのアドレス
  ignore = dirty

追加

$ git submodule add repositoryのアドレス ./submodules/sample-repo

init

$ git submodule init

update

$ git submodule update

pull

$ git submodule foreach git pull origin master

言語別文字列エスケープ方法

php - preg_quote

preg_quote('\()[].*')

python - re

import re
result = re.escape('\()[].*')

Google ChromeでJSONを整形する

consoleで以下を実行

resp = '<JSONデータ>';
console.log(JSON.stringify(resp,null," "));

Chromeでfullscreen caprue(Mac)

F12でインスペクター開いて、command+shift+P
検索windowで「Capture full size screenshot」を選択

Screen Shot 2020-12-16 at 13.04.51.png

ERROR 1840 (HY000) at line 34: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty.

mysql> reset master;

openssl

$ openssl genrsa -out private.key 2048
$ openssl rsa -in private.key -pubout -out public.key
0
2
2

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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?