6
5

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 5 years have passed since last update.

コンソールでよく使うLinuxコマンドメモ

Last updated at Posted at 2015-06-02

投稿テストがてら、自分用のメモです。

Linux

管理系

インストール済みのソフト一覧表示

yum list installed

パッチ適用履歴を確認する

rpm -q --changelog openssl  

サービス起動停止

systemctl stop httpd
systemctl start httpd

検索系

拡張子を指定してYYYY-MM-DDの日付を取りたい

find -type f -name "*.sh" | xargs -I{} ls -l --time-style=+%Y-%m-%d\ %H:%M:%S {} ls -l {}
find -type f | xargs -I{} ls -l --time-style=+%Y-%m-%d\ %H:%M:%S {} | awk '{print $6 " "  $8 }'

今いるディレクトリ内の、ファイルの中身を検索して、行数を出したい。

find -type f | xargs grep -Hn "hoge"

拡張子ごとに集計してソート

find . -type f -print | sed -e 's/^.*\///' | grep '\.' | sed -e 's/^.*\.//' | sort | uniq -c | sort -nr

SVNコマンドに流し込みたい

find -type f | xargs -I{} svn propset svn:needs-lock "*" {}

NW系

sshでホストチェックを外す

ssh -oStrictHostKeyChecking=no ec2-uesr@192.168.0.X

OpenSSLで繋いで使用されているプロトコル等確認

openssl s_client -connect www.targeturl.com:443

DBとの接続数をカウント

netstat -tanp | grep ${DB_PORT} | grep ESTABLISHED

ポート利用状況確認

lsof -i -n -P | grep ${PORT}
netstat -ant | grep ${PORT}

netcatで疎通確認

nc -vn 192.168.0.X ${PORT}

その他よく使う

date

コンソールというか、スクリプトで使う度に調べてるので。。。とりあえず例だけ記載。

date "+%Y-%m-%d_%H-%M-%S.%N"

diff

再帰的に比較して、差異がでたファイルのみ表示
一部比較したくないディレクトリは除外する。

diff -r -x 'log' /path/to/target1 /path/to/target2

ちょいスクリプト編

For文
色んな所にものをばらまく。

ALL_HOST=(192.168.0.X 192.168.0.XX);
for h in \${ALL_HOST[@]}; do
 scp -rp Test.sh ec2-user@${h}:/home/ec2-user/
done; echo "Done";

if文
いろいろ一行で。。。

[ -f \$target ] && rm -f $target
[ \$hoge = \$foo ] && echo "true" || echo "false"

Zabbix

疎通確認(ntpのプロセス数を取ってます)

zabbix_get -s 192.168.0.X -k proc.num[ntpd]

PostgreSQL

psqlコマンドでつなぐ

psql -h ${TARGET_HOST} -U ${DB_USER} -d ${DB_NAME} -p ${DB_PORT}

AWS系

バケットにあるものをすべてカレントディレクトリにダウンロード

TRG=$(aws s3 ls s3://mybucket/path/to/ --recursive | awk '{print $4}')
for ITEM in $TRG; do
 aws s3 cp s3://mybucket/$ITEM .;
done
6
5
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
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?