#search files by type or name or size
find /asle03/sle/data -type f -name "SLEUPL*.dat" -exec ls -l {} \;
find /asle03/sle/log -type f -size 100K -exec ls -l {} \;
#find file and include "error" string
find / -type f -name "*.log" | xargs grep "ERROR"
find . -type f | xargs grep "10002"
#find 777 permission files and change to 775
find . -perm 777 | xargs chmod 775
#query MQ version:
dspmqver
#find a port and kill process
lsof -i:9080
kill -9 1234
#查看进程对应的端口
netstat -antp | grep 进程号
#change the owner of files or folders
cd /usr/local/web/sites/WLD1138
[as root] find . -user root -exec chown -R webspher:webspher {} \;
#clear file content
cp /dev/null filename.log
vi filename
:1,.d
#Linux machine performance
prstat -a
sar -u 2 5
#Check password in UAT/PROD
pbrun checkpwm -S CTG -U CTG0SLE
#Cut String
一、Linux shell 截取字符变量的前8位,有方法如下:
1.expr substr "$a" 1 8
2.echo $a|awk '{print substr($0,1,8)}'
3.echo $a|cut -c1-8
二、按指定的字符串截取
1、第一种方法:
${varible##*string} 从左向右截取最后一个string后的字符串
${varible#*string}从左向右截取第一个string后的字符串
${varible%%string*}从右向左截取最后一个string后的字符串
${varible%string*}从右向左截取第一个string后的字符串
"*"只是一个通配符可以不要
2、第二种方法:${varible:n1:n2}:截取变量varible从n1到n2之间的字符串, 用于bash。
#replace file content
for file in `find . -name *.xml`
do
sed -i "s/$replaceMatchValue/$replaceValue/g" $file
done
#date
YESTERDAY=$(date -d yesterday +"%Y%m%d")
echo "yesterday is " $YESTERDAY
TODAY=$(date -d today +"%Y%m%d")
echo "today is " $TODAY
##根据条件查找进程并批量杀掉,其中grep -v "grep"表示反向选择,查找除了grep的进程
#!/bin/sh
pro_name=java
keys=`ps -ef |grep "$pro_name" |grep -v "grep" | awk '{print $2}'`
for key in ${keys}
do
sudo -t webspher kill -9 $key
done
##生成密钥对
ssh-keygen -b 1024 -t rsa
#读取csv文件,分割到数组
strsplit=","
filename="filename.csv"
while read line
do
IFS=$strsplit read -a column <<< "$line"
echo ${column[1]}
echo ${column[2]}
done <$filename
#Mysql连接命令
mysql -h服务器 -P端口 -u用户 -p密码
#按行垂直显示结果
select * from table \G