LoginSignup
3
3

More than 5 years have passed since last update.

ワンライナー個人メモ

Last updated at Posted at 2015-10-21

shell

mkdir && cd, touch && chmod

よく忘れるやつ

mkdir /tmp/dir && cd $_
touch /tmp/file && chmod +x $_

ランダムなbase64を任意バイトサイズ分

cat /dev/urandom | base64 | head -c 262144 > rand.txt

ssh

ポートフォワーディング

ローカルの13306ポートをリモートサーバーの3306にマッピングするとしたら。

ssh -N -L 13306:localhost:3306 user@host

nginx

ログの手動ローテート

mv /var/log/nginx/access.log{,.`date '+%Y%m%dT%H%M%S%z'`} && kill -USR1 `cat /var/run/nginx.pid`

MySQL

スローログの手動ローテート

mv `mysql -uroot -N -B -e "show variables like 'slow_query_log_file'" | \
cut -f 2`{,.`date '+%Y%m%dT%H%M%S%z'`} && \
mysql -uroot -e "FLUSH SLOW LOGS"

Redis

MySQL to Redis

usersテーブルをRedis Hashesにするとしたら。例えば。

mysql -uroot testdb -NB -e "select 'HMSET',concat('users-', id), 'id', id, 'account_name', account_name from users limit 10" | perl -pe 's/\n$/\r\n/' | redis-cli --pipe

値にスペースが含まれていたりする場合は、クォートで囲むべし。

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