linux shell 学习

1.查看进程号   pgrep gedit 
2.查看环境变量 cat /proc/12401/environ
3.tr         cat /proc/12401/environ | tr '\0' '\n'

4.代理设置 HTTP_PROXY=http://192.168.0.2:3128
          export HTTP_PROXY

5.获取变量长度
  var=1234567890
  echo ${#var}

6.算术操作 let 、 (( )) 、[]
  let result = no1+no2
  echo $result 
  
  result=$[no1 + no2]
  result=$[$no1 + 5]
  result=$((no1 +50))
  result=`expr 3 + 4`
  result=$(expr $no1 + 5)
  
  echo "4 * 0.56" | bc
  result=`echo "$no*1.5" | bc`
  

7.获取命令推出状态
   echo $?
   每行数据都加上行号  ll | cat -n 
   别名设置   alias rm='cp $@ ~/backup; rm $@' 
   取消别名  $ \command 

8.find 命令
    find /home/slynux -iname "*.txt" -print
    find . \( -name "*.txt" -o -name "*.pdf" \) -print
    find /home/slynux -path "*slynux*" -print
    -regex 支持正则表达式匹配
    find . -type f -altime +7 -print
    find . -type f -size +2k 
    find . -type f -name "*.swp" -delete
    find . -type f -name "*.txt" -print0 | xargs -0 rm -f
    find path -type f -name "*.c" -print0 | xargs -0 wc -l

9.排序
    sort file1 file2 > sorted.txt
    cat sorted.txt | uniq> uniq_lines.txt
    sort -m sorted1 sorted2  #合并两个排好序的文件   

10.删除两个文件重复行
   grep -vxFf s2 s1


11.awk
cat $downFileName | awk -F ' ' '{if($1!~/^([0-9])+$/){if(NR>'${startnum}')print $1 }}' > $tofileName

!~ 不匹配
~ 匹配


12.两个文件,删除一个文件里包含词的行

list=(`cat sexy | tr '\r\n' ' '`)

num=${#list[@]} 

for((i=0;i<num;i++));
do 
   echo ${list[i]};
   cat apps/appNewSearch_IN_20141109 | awk -F ' ' 'BEGIN{IGNORECASE=1}{if($1~/'$VAR'/){ print $1}  }'
done



13.awk 去除重复行
awk '!a[$0]++' file


15.找出一个文件中重复行
awk '{a[$0]++}a[$0]==2'


16.打印指定模式的字符串
sed -n -e's/.*time=\[\(.*\)\]/\1/p'

猜你喜欢

转载自kevin1.iteye.com/blog/1989401
今日推荐