ファイル操作
旧関数のチェック
chkmb ディレクトリ名
(例:chkmb /home/system/hoge )
とすることで、
mberegi mbereg_replace mbregex_encoding
を使っていないかチェックする。
圧縮
tar fcz /tmp/hoge.tar.gz /home/system/hoge
解凍
tar zxvf formove.tar.gz
ディレクトリの権限の変更
chmod -R 777 hoge
chown -R web_admin.web_admin hoge
ディレクトリの転送
/usr/bin/rsync -auz -e ssh /hoge/fuga/元のディレクトリ/ ユーザ名@xxx.xxxx.com:/hoge/fuga/先のディレクトリ/
ファイルの転送(送信)
scp コピーしたいファイル名 ユーザ名@xxx.xxxx.com:/hoge/fuga/
ファイルの転送(受信)
scp ユーザ名@xxx.xxxx.com:/hoge/fuga/コピーしたいファイル名 ./
圧縮されたファイルの分割
nice -n 15 gunzip -c xxxx.log.gz | nice -n 15 split -C 10000000 &
ファイルサイズの大きいものトップ30を抽出する
調査したいディレクトリにて
du -m |sort -n |tail -30
で抽出
こんな感じもあり
du -SmH|grep M|sort -n|tail -30|tac
ファイル数を数える
ls|wc-l
例:文字列 20_ を含むファイル数
ls|grep 20_| wc -l
1秒毎に使用メモリ量を観察する
while true; do nice -n 15 free -m ; sleep 1 ; done
ユーザ追加
/usr/sbin/groupadd hoge
/usr/sbin/useradd -g hoge hoge
/usr/sbin/usermod -d /home/hoge hoge
/usr/sbin/useradd -g users hoge
/usr/sbin/usermod -G users,wheel,cvsroot hoge
ユーザー削除
userdel hoge
バキューム
vacuumdb -U postgres 対象DB名 -f -v -z
アナライズ
VACUUM ANALYZE (対象テーブル名)
パフォーマンスの計測
explain analyze を selectの前に付ける
データベースの削除
dropdb -U postgres 削除する DB名
列にインデックスを張る
create index インデックス名 on 対象テーブル (対象列名)
サーバ上のxxxxと名の付くDBに対して、一括で処理を行う
この例は、t_order_type のインデックスを一括で除去する例
for i in `psql -U postgres -l|grep post|grep xxxx| cut -f1 -d'|'` ; do psql -U postgres $i -c 'drop index t_order_type;' ; done;
※DB削除
/usr/bin/dropdb -U postgres hogehoge
※DB作成
/usr/bin/createdb -U postgres -E SQL_ASCII hoge
※DBバックアップ
/usr/bin/pg_dump -U postgres hoge > BK-hoge.dmp
※リストア
(dmp)
psql -U postgres hoge < BK-hoge.dmp
持ってきたファイルを解凍して、DBをリストアする
gunzip -c 20071211043001.gz | psql -U postgres hoge