努力工作,把握幸福。

发布新日志

  • curl 用法(转)

    2014-05-04 15:01:40

    http://blog.51yip.com/linux/1049.html
  • CentOS YUM installation

    2014-02-17 17:04:02

    1. Uninstall the original yum

    # rpm -aq | grep yum|xargs rpm -e --nodeps

    2. Download the centos yum installation file

    3. Install Centos yum

    # rpm -ivh python-iniparse-0.3.1-2.1.el6.noarch.rpm
    # rpm -ivh yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
    # rpm -ivh yum-3.2.29-40.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm

    4. Update the yum source, we use the 163 centos image source

    # cd /etc/yum.repos.d/
    # wget  http://mirrors.163.com/.help/CentOS6-Base-163.repo
    # vi CentOS6-Base-163.repo

    edit CentOS6-Base-163.repo ,replace the $releasever to version number,6 and save!or copy the following content to CentOS6-Base-163.repo

    #########################################################################
    # CentOS-Base.repo
    #
    # The mirror system uses the connecting IP address of the client and the
    # update status of each mirror to pick mirrors that are updated to and
    # geographically close to the client.  You should use this for CentOS updates
    # unless you are manually picking other mirrors.
    #
    # If the mirrorlist= does not work for you, as a fall back you can try the
    # remarked out baseurl= line instead.
    #
    #
    
    [base]
    name=CentOS-6 - Base - 163.com
    baseurl=http://mirrors.163.com/centos/6/os/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os
    gpgcheck=1
    gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
    
    #released updates
    [updates]
    name=CentOS-6 - Updates - 163.com
    baseurl=http://mirrors.163.com/centos/6/updates/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates
    gpgcheck=1
    gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
    
    #additional packages that may be useful
    [extras]
    name=CentOS-6 - Extras - 163.com
    baseurl=http://mirrors.163.com/centos/6/extras/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extras
    gpgcheck=1
    gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
    
    #additional packages that extend functionality of existing packages
    [centosplus]
    name=CentOS-6 - Plus - 163.com
    baseurl=http://mirrors.163.com/centos/6/centosplus/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=centosplus
    gpgcheck=1
    enabled=0
    gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
    
    #contrib - packages by Centos Users
    [contrib]
    name=CentOS-6 - Contrib - 163.com
    baseurl=http://mirrors.163.com/centos/6/contrib/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=contrib
    gpgcheck=1
    enabled=0
    gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
    
    #########################################################################

    5. clear yum cache

    # yum clean all
    # yum makecache     # cache the server information to local, improve the installation speed.

    6. install tool with yum -- require your Linux server can access Internet

    # yum install xxx, such as

    # yum install ftp

    # yum install telnet

    # yum install tmpwatch

    once you have installed this tool, when running this command, it would tell you 'nothing to do'

    7. install tool with yum -- once your Linux server has no access to Internet

    download the related rpm from Internet

    then upload the rpm to your Linux server, run command

    rpm -ivh xxx.rpm --nodeps --force

    --nodeps //don't check dependency library

    --force //install it forcibly

  • Unix Shell 学习(三)-- () 与 {}

    2012-06-14 17:20:54

    1.{} 的用法
    确认你有一个叫file和一个叫file1的变量。能够使用以下的语句给它们赋值:
    $ file=this
    $ file1=that
    $echo $fileand$file1 寻找变量fileand,file1
    sh: fileand: parameter not set
    $ echo ${file} and $file1 寻找变量file,file1
    thisandthat
    花括号被用来区分变量名和周围的文本
    2.()的用法
    命令替代
    语法:
    $(command)
    例子:
    $pwd
    /home/user2
    $ curdir=$(pwd)
    $ echo $curdir
    /home/user2
    $ cd /tmp
    $ pwd
    $ cd $curdir
    $ pwd
    /home/user2
    命令替代用来替代一个命令和命令行输出。命令替代的标准语法,也是POSIX鼓励的一种语法是:$(command).
    命令替代让你捕获一个命令的输出,用它作为另一个命令的参数,或是赋值给一个变量。象在变量替代中一样,命令替代的执行是在命令行开始之前完成的。当命令行输出包含回车换行,它们会被空格代替。
    同变量替代相似,命令替代使用一个美元符号之后的用括号包围的一个命令。
    所有有效的shell脚本都可以加入命令替代。Shell 扫描每行脚本,执行它发现的开始于一个开括号,结束与于一个闭括号的命令。
    命令替代的另外一种格式是用反引号来环绕一个命令象:
    `command`
    它和$(command) 是等价的,并且这是Bourne Shell认证的唯一的形式。`command`形式可以用在POSIX的脚本中和Bourne Shell的脚本中。
    命令替代通常是在将一个命令的输出赋给一个变量或以后的处理时使用。通常pwd命令将它的输出送到你的屏幕。当你执行以下的赋值语句:
    $ curdir=$(pwd) 或 $ curdir=`pwd`
    pwd 的输出被赋给变量 curdir。
  • Unix Shell 学习(二)--循环结构语法

    2012-06-14 15:26:27

    循环分为 for 循环, while 循环 和 until 循环

    For 循环

    语法:  for 变量 in 列表
           do
           操作
           done
          
            注: 变量指循环内部用来指代当前所指代那个列表中的那个对象
            列表指for 循环内部要操作的对象,可以是字符串也可以是文件,文件必须是文件名
      
        例:删除垃圾箱中所有的.gz文件

          #delete all of .gz file from dustbin

          for i in $HOME/dustbin/*.gz
          do
          rm?Cf $i
          echo "$i had been deleted"
          done

    While 循环

    语法: While 表达式
          do
          操作
          done
    只要表达式成立, do 和done之间的操作就会一直进行

    Until 循环

    语法: until表达式
          do
          操作
          done
    重复 do和done之间的操作,直到表达式成立

    例:
         #test until
         # add 1 from 100
         total=0
         num=0
         until test num?Ceq100
         total=`expr $total +$num`
         num = `expr $num +1`
         done
         echo "The result is $total"


  • Shell 学习 --- 如何查看某端口被那个程序占用

    2012-06-03 12:09:23

    netstat -an|grep 8080(非root可用)
  • Unix Shell 学习 (一)--变量表达式

    2012-05-29 18:22:48


    1. 字符串比较

    作用: 测试字符串是否相等,长度是否为0, 字符串是否为NULL(注:bash 区分零长度字符串和空字符串)

    常用字符串操作符:

    = 比较两个字符串是否相同, 同则是为“是”,
    != 比较两个字符串是否相同,不同则为“是”,
    -n 比较字符串长度是否大于0, 大于0 则为“是”
    -z 比较字符串长度是否等于0, 等于0则为“是”

    2. 数字比较
    -eq 等于
    -ge 大于等于
    -le 小于等于
    -ne 不等于
    -gt 大于
    -lt 小于

    3. 逻辑操作
    -a or (and) 两个逻辑值都为是,才返回 真
    -o or (or)  其中一个逻辑值为是,就返回真

    4. 文件操作

    -d 对象存在且为目录,返回值为“是”
    -f 对象存在且为文件,返回值为“是”
    -L 对象存在且为符号连接返回值为“是”
    -r 对象存在且为可读则返回值为“是”
    -s 对象存在且长度为非零返回值为“是”
    -w 对象存在且科协则返回值是“是”
    -x 对象存在且可执行则返回值为“是”


Open Toolbar