memo

memo dayo.

sh

grep option memo

cat test.txt | grep -v 'hoge' grep -r 'hoge' * cat test.txt | egrep -i 'JPG'

ファイルサイズ順に検索結果を表示する

sh

find / -name "*2015*.gz" | xargs du -k | sort -n

対象ディレクトリ配下に存在する拡張子の一覧

sh sh

find . -type f | sed 's/\./ /g' | awk '{print $NF}' | sort | uniq

viで文字コードを指定して開く

sh sh

vi -c ":e ++enc=utf8" utf8.txt vi -c ":e ++enc=cp932" sjis.txt vi -c ":e ++enc=euc-jp" euc.txt

検索したファイルを削除する

sh sh

find ~/ -type f -name "Thumbs.db" | xargs rm -rf find ~/ -type f -name "desktop.ini" | xargs rm -rf find ~/ -type f -name ".DS_Store" | xargs rm -rf

ファイルを空にする

sh sh

echo -n > aaa.txt

grepで空行を省く

sh sh

cat 1.txt | grep -v '^\s*$' > 2.txt

変数に代入したコマンド文字列を実行する

sh sh

cmd="" cmd=$cmd"cat 1.txt | " cmd=$cmd"sort | " cmd=$cmd"uniq > 2.txt" eval $cmd

ファイルを一行ずつ読み込む

sh sh

cat aaa.txt | while read line do echo $line done

先頭から数文字を取得

sh sh

echo 12345 | cut -c-3

ディレクトリとファイルの一覧を取得

sh sh

file_s="./*" for file_1 in $file_s; do echo $file_1 done

文字列置換

sh sh

echo "aaa.txt" | sed -e "s/\.txt//g"

echoで改行しない

sh sh

echo -n 999

grepで指定文字列を除外する

sh sh

cat *.txt | grep -v "test"

uptimeとfreeを記録するバッチ

sh sh

#!/bin/sh str='' str=$str`date +"%Y%m%d,%H%M"` str=$str"," str=$str`uptime | awk -F"load average:" '{print $2}' | tr -d " "` str=$str"," str=$str`free -m | grep "buffers/cache:" | awk '{print $3","$4}'` str=$str"\n" echo -ne $str

pemファイルでssh

sh sh

ssh -i aaa.pem username@servername

配下のファイルのタイムスタンプを指定する

sh sh

touch -d "2001-01-01 00:00:00" ./*

1日以内に更新されたファイル一覧

sh sh

find . -mtime -1

配下のファイルのタイムスタンプを現在にする

sh sh

find ./ -type f -exec touch {} \;

配下のファイル名を一括置換する

sh sh

# 確認 find ./ -type f | grep index.html find ./ -type f | grep .gitkeep # 配下の index.html を .gitkeep へ置換 find ./ -type f | grep index.html | sed 'p;s|index.html|.gitkeep|g' | xargs -n2 git mv # 確認 find ./ -type f | grep index.html…

mysqldumpするバッチ

sh

#!/bin/sh str_ymd=`date +"%Y%m%d%H%M%S"` str_cmd='' str_cmd=$str_cmd'/usr/bin/mysqldump' str_cmd=$str_cmd' --default-character-set=utf8' str_cmd=$str_cmd' --skip-lock-tables' str_cmd=$str_cmd' --user=db_user' str_cmd=$str_cmd' --password=d…

権限777のファイルの一覧

sh

find . -perm 777

0バイトのファイルだけ探す

sh

0バイトのファイル一覧 find . -size 0c 0バイトのファイルを削除 find . -size 0c -exec rm -rf {} \;

rsyncでファイルを送信する(ssh鍵オプション有り)

sh

rsync -lptgoDzvr --delete -e "ssh -i /home/yourname/.ssh/id_dsa" /aaa/bbb/ccc yourname@otherserver:/aaa/bbb/

shスクリプトのフルパスを取得する

sh

#### get dir name #### case $0 in /*) K_DIR_NAME=`dirname "$0"` ;; ./*) str_aaa=$0 str_bbb='./' int_len=`expr ${#str_aaa} - ${#str_bbb}` str_aaa=${str_aaa:${#str_bbb}:$int_len} K_DIR_NAME=`dirname "$PWD/$str_aaa"` ;; *) echo $0 K_DIR_NAME=…

ディレクトリをTarでまとめる

sh

tar cvfz /tmp/opt_backup.tar.gz /opt

空ディレクトリだけを探す

sh

空ディレクトリの一覧 find . -type d -empty 空ディレクトリを削除 find . -type d -empty -exec rm -rf {} \;

検索したファイルに対して処理を行う

sh

■検索したファイルを削除する find . -name Thumbs.db -exec rm -f {} \; find . -name ".DS_Store" -exec rm -f {} \;■検索したファイルのパーミッションを変更する find . -name "*.txt" -exec chmod 777 {} \;

指定日以降に更新されたファイルの一覧

sh

touch -m -d '2010/08/04 00:00:00' /tmp/gomi.txt find . -type f -newer /tmp/gomi.txt

scpでファイルを受信する

sh

scp -rp -oIdentityFile=identity_file yourname@xxx.xxx.xxx.xxx:/otherserver/yourname/* /thisserver/yourname/