find /home -name filename -type d find /home -name filename -type f find /home -name "*.java" find / -name apache 2>/dev/null 不显示错误 1为标准输出,2位错误输出
ps -ef|grep tomcat ls -l /proc/{procId}
set number 显示行号 dd 删除行 p 粘贴(yy复制) /string 查找 :%s/old/new/g 替换
磁盘使用情况
grep -n keyword filename grep [tf] filename 含't'或'f'的行 grep -20 ReleaseJF catalina.out 显示前后20行 // (xxx) xxx-xxxx or xxx-xxx-xxxx. (x means a digit) cat file.txt | grep -Eo '^(\([0-9]{3}\) ){1}[0-9]{3}-[0-9]{4}$|^([0-9]{3}-){2}[0-9]{4}$'
tar -cvf test.tar test/ test2/ tar -tf test.tar 列出,不解压 tar -xvf test.tar
$ date;who
2016年 09月 18日 星期日 14:55:23 CST
migujsj pts/02016-09-18 14:34 (10.25.118.5)
user group other -rwx -rwx -rwx
echo "hello shell" 换行 echo -n "hello shell" 不换行
name='value' 定义 echo $name 引用
将命令输出赋予变量 now = \`date +%y%m%d\`
> create >> add < 输出 `wc<test.java`(行,词,字节)
[migujsj@migu04 ~]$ expr $[1+2*3]
7
cnt=`expr $cnt + 1`
if command;then
commands
fi ### for ###
fileName='states'
for state in `cat $fileName`
do
echo $state
done
for((i=1;i<=10;i++))
do
echo $i
done
内部分隔符
IFS_old=$IFS #将原IFS值保存,以便用完后恢复 IFS=$’\n’#更改IFS值为$’\n’ ,注意,以回车做为分隔符,IFS必须为:$’\n’ for i in `cat m.txt` do echo $i done IFS=$IFS_old #恢复原IFS值
if test -n $1;then //如果有参数
do
echo $1;
done
if [[ -n $1 ]];then ...
-f(文件),-d(文件夹),-z(长度为0),-e(存在),-r(可读),-n(长度非0)
${#var} 变量长度
字符串:=,!=,-z,-n
数字:-eq,-ne,-gt,-ge,-lt,-le
条件测试有:[[]],[],test 这几种,注意:[[]] 与变量之间用空格分开,此格式较为通用。
count=1
cat test | while read line
do
echo 'Line $count: $line'
count =$[$count+1]
done
at corn * * * * * command 分 时 日 月 周 命令
head -n | filename
http://coolshell.cn/articles/9104.html
sed -n '1000,3000p' filename 显示1000到3000行的数据 sed 's/old/new/g' filename(**替换**) cat filename | sed 's/old/new/g' 不会改变源文件 sed -n '/_ _/p' main.java 有连续两个空格?(**查找**) //截取version $ReqFileTmp = "<Version>1.1.1</Version>" sed -n '/Version/'p $ReqFileTmp|sed 's/\///g'|sed 's/<Version>//g'
uname -a cat /etc/issue
http://coolshell.cn/articles/9070.html
gawk -F: '{print $1}' /etc/password | gawk '{$4="china";print $0}' 改变源文件
. 任意一个字符 * 前面的任意次数 [] [Yy]es,[^ch],[0-9] ^ 首,^book $ 尾,book$ {}可重复次数 + 至少一次 ? 0次或1次 | 或 () | sed -n '/b[ae]*t/p' | gawk '/b[ae]?t/{print $0}' (c|b)a(b|t), cat(yes), bat(yes), tat(no) Sat(urday)?, Sat(yes), Saturday(yes)
translate,轻量级sed
tr ‘a-z’ ‘A-Z’ < word.txt tr ‘a-z’ ‘A-Z’ <<< "asda单行字符串" cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -rn | awk '{print $2" "$1}' //统计词频
tailf log.txt | grep exception
if ($i<5) if [ $i -lt 5 ] if [ $a -ne 1 -a $a != 2 ] if [ $a -ne 1] && [ $a != 2 ] if [[ $a != 1 && $a != 2 ]] for i in $(seq 0 4);do echo $i;done for i in `seq 0 4`;do echo $i;done for ((i=0;i<5;i++));do echo $i;done for i in {0..4};do echo $i;done
# ls {ex1,ex2}.sh ex1.sh ex2.sh # ls {ex{1..3},ex4}.sh ex1.sh ex2.sh ex3.sh ex4.sh # ls {ex[1-3],ex4}.sh ex1.sh ex2.sh ex3.sh ex4.sh
# var=testcase # echo $var testcase # echo ${var%s*e} testca # echo $var testcase # echo ${var%%s*e} te # echo ${var#?e} stcase # echo ${var##?e} stcase # echo ${var##*e} # echo ${var##*s} e # echo ${var##test} case
[root@centos ~]# var=/home/centos [root@centos ~]# echo $var /home/centos [root@centos ~]# echo ${var:5} /centos [root@centos ~]# echo ${var: -6} centos [root@centos ~]# echo ${var:(-6)} centos [root@centos ~]# var=/home/centos [root@centos ~]# echo $var /home/centos [root@centos ~]# echo ${var:5} /centos [root@centos ~]# echo ${var: -6} centos [root@centos ~]# echo ${var:(-6)} centos [root@centos ~]# echo ${var:1:4} home [root@centos ~]# echo ${var/o/h} /hhme/centos [root@centos ~]# echo ${var//o/h} /hhme/cenths
curl 118.184.176.13/dyndns/getip
curl -l -H "sign:a696009a85ff4e7136df2e37e0ce7bf1" -H "appKey:cdd138c25c8248ccabffd9ff6a984649" -H "bodyType:json" -X POST -d '{"data":{"reqSrc":"USE","listType":"1","channelId":"","contentType":"10"}}' http://223.111.8.15:9081/aogs_forward/listRecommend
service crond start//启动服务
service crond stop //关闭服务
service crond restart //重启服务
service crond reload //重新载入配置
service crond status //查看服务状态
30 7 * * * /home/migu/sftp/hj/bin/hotUpdate.sh
*/30 * * * * /home/migu/sftp/hj/bin/importData.sh