LoginSignup
12
16

More than 5 years have passed since last update.

運用で使うLinuxコマンド【メモ】

Posted at

サーバ運用でよく使うLinuxコマンド集

ファイルコピー(タイムスタンプ保持)

shell
$ cp -p ${SRC} ${DIST}

pオプション付けると吉

ディスク容量チェック

shell
$ df -h

ディレクトリ配下のディスク使用量をチェック

shell
$ du -hx --max-depth=1

ファイルサイズが大きいとDISK I/O負荷になるので注意

ナイス値を最低にしてコマンド実行

shell
$ nice -n 19 ionice -c 3 ${COMMAND}

DISK I/O負荷軽減のおまじない

対象ディレクトリの7日以前のファイル削除

shell
$ find ${DIR} -type f -mtime +7 | xargs rm

対象ディレクトリから該当する文字が含まれるファイルを出力する

shell
$ find ${DIR} -type f -exec grep -l "${SEARCH_WORD}" {} \;

リモートサーバとファイル差分確認

shell
$ rsync -avz --dry-run -e ssh ${LOCAL_DIR} ${SERVER}:${REMOTE_DIR}

帯域制限したファイル転送方法

shell
$ rsync -avz --ignore-existing --bwlimit=1024 ${LOCAL_DIR} ${SERVER}:${REMOTE_DIR}

カレントディレクトリにあるhtmlファイル中のfromをformに置換する

shell
$ perl -i -p -e 's/from/form/g;' *.html

バックグラウンドモードでスクリプト実行

shell
$ nohup sh ${SHELL_FILE} &

ファイルディスクリプタ数の確認

shell
$ lsof -p ${PID} | wc

対象時刻のL/Aを確認する

shell
$ sar -f /var/log/sa/sa01 -s 20:00:00 -e 21:00:00 -q

iptablesで対象IPアドレスをブロック

shell
$ iptables -A INPUT -i eth0 -s ${IP_ADDR} -j DROP

ホスト名設定

shell
$ hostnamectl set-hostname ${HOSTNAME}

デーモン登録

shell
$ systemctl enable ${PROCESS}.service

デーモン確認

shell
$ systemctl list-unit-files ${PROCESS}.service

サービス再起動

shell
$ systemctl restart ${PROCESS}.service
12
16
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
12
16