参考资料:鸟哥的私房菜
http://linux.vbird.org/
grep
引用
[root@www ~]# grep [-acinv] [--color=auto] '搜尋字串' filename
選項與參數:
-a :將 binary 檔案以 text 檔案的方式搜尋資料
-c :計算找到 '搜尋字串' 的次數
-i :忽略大小寫的不同,所以大小寫視為相同
-n :順便輸出行號
-v :反向選擇,亦即顯示出沒有 '搜尋字串' 內容的那一行!
-l :不输出查找文本行,只输出文件名
-r :遍历文件树
-C :显示NUM行查找结果的上下文
-m :最大寻找数,找到NUM个数后即停止
--color=auto :可以將找到的關鍵字部分加上顏色的顯示喔!
#去掉文件注释以及空行
grep -v '^$' regular_express.txt | grep -v '^#'
#
grep -n 't[ae]st' regular_express.txt
#或操作
tail -f searcher.log |grep -E 'WARNING|ERROR'
#只输出最小匹配
grep -oP "key.*?," text
diff
引用
[root@www ~]# diff [-bBi] from-file to-file
選項與參數:
from-file :一個檔名,作為原始比對檔案的檔名;
to-file :一個檔名,作為目的比對檔案的檔名;
注意,from-file 或 to-file 可以 - 取代,那個 - 代表『Standard input』之意。
-b :忽略一行當中,僅有多個空白的差異(例如 "about me" 與 "about me" 視為相同
-B :忽略空白行的差異。
-i :忽略大小寫的不同。
diff -Bby --suppress-common-lines file1 file2
find
引用
find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
awk
以,为分割符
awk -F, '{print $0, $2}'
sed
保留行首为#的评论,并在原文件上修改
sed -i '/^#/!d' /etc/rc.local
添加到第一行
sed -i '1i\worker_rlimit_nofile 262144;' /etc/nginx/nginx.conf
替换内容
sed -i 's/worker_connections.*/worker_connections 262144;/g' /etc/nginx/nginx.conf
保存匹配字符,取整
sed 's/\([0-9].\).*/\1/'
scp
scp -rv -P 1234 /from/src /to/des
scp -i .ssh/keys -P 12345 foo fuck@10.1.1.1:/home/fuck
rsync
rsync -avz /from/local/src dest
rsync -avz test.* user@10.1.0.1:/home/user
启动rsync服务器
sudo rsync --daemon --config=rsyncd.conf
vim rsyncd.conf
uid = joey
gid = joey
use chroot = no
read only = no
max connections = 4
syslog facility = local5
pid file = /tmp/rsyncd.pid
[ftp]
path = /tmp/ftp/
comment = whole ftp area (approx 6.1 GB)
rsync -av ./a/ joey@127.0.0.1::ftp/
tzselect
修改linux时区
vim /etc/profile
TZ='Asia/Shanghai'; export TZ
不用密码的ssh
ssh-keygen -t rsa
cd ~/.ssh
scp id_rsa.pub user@targethost:~
ssh user@targethost "cat ~/id_rsa.pub >> ~/.ssh/authorized_keys"
ssh user@targethost "chmod 600 ~/.ssh/authorized_keys"
ssh user@targethost "rm -rf ~/id_rsa.pub"
时间
ntpdate stdtime.gov.hk
hwclock -w
时区
dpkg-reconfigure tzdata