How to install CentOS Linux on VMware 12

This post will introduce how to install a CentOS on VMware 12.

Install CentOS

Custom –> I will install the operating system later.

Good Commands

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
$> more a.txt // more display
$> more -5 a.txt // display the first 5 lines
$> ls -aR ~ // list all recursively
$> head a.txt // display the first 10 lines
$> head -n 12 a.txt // display the first 12 lines
$> head -n -10 a.txt // display all but the last 10 lines
$> tail a.txt // display the last 10 lines
$> tail -n 12 a.txt // the last 12 lines
$> wc -c a.txt // display the byte counts
$> wc -m a.txt // print the char counts
$> wc -l a.txt // print the line counts
$> wc -w a.txt // display the word counts
$> wc -L a.txt // print the length of the longest line
$> hostname
$> uname -a // print all information about system
$> file a.so // print type of a file
$> xargs // convert multi lines to single line
$> find . | grep txt | cp `xargs` temp // copy all 'txt' files from `find` command to `temp` directory
$> which echo // find where command `echo` is
$> chmod g+w a.txt // add write permission to group
$> chown -h xxx:xxx linker // change a linker owner but not object
$> ln -sfT linker newObject // change a linker from old to new

Net Configuration

  1. Network modes

    • Bridged
      • Connect virtual machine to Internet directly by physical netcard.
      • Other machines can access virtual machine directly.
    • NAT(Net Address Tranform)
      • virtual machine can access other machines.
      • Other machines can not access virtual machine.
    • Host-only
      • Like NAT but can not connect to Internet.
  2. Static IP Address

    • Edit file: /etc/sysconfig/network-scripts/ifcfg-enoxxxxx
      These values should be modified:

      1
      2
      3
      4
      5
      6
      ONBOOT=yes
      NM_CONTROLLED=no
      BOOTPROTO=static
      IPADDR=xxx.xxx.xxx.xxx
      NETMASK=xxx.xxx.xxx.xxx
      GATEWAY=xxx.xxx.xxx.xxx

      NETMASK and GATEWAY must be same with your VMnet8(NAT mode).

    • Edit file: /etc/resolv.conf for DNS

      1
      nameserver xxx.xxx.xxx.xxx

      nameserver must be same with VMnet8 gateway.

  3. Jobs

    1
    2
    3
    4
    5
    6
    $> cat a.txt & // run in background
    $> jobs // check jobs in background
    $> fg %n // switch job to foreground, `n` is job ID
    ctrl + z // switch job to background
    $> bg %n // continue a job in background
    $> kill %n // kill a job
  4. Process

    1
    2
    $> ps -Af // show all processes
    $> top
  5. Cut

    1
    $> cut -c 1-5 a.txt // show the 1st - 5th chars in each lines
  6. Device Info

    1
    2
    $> fdisk -l /dev/sda // show infos of `sda` like partitions
    $> df -ah // show free space of devices
  7. Host name

    1
    $> hostname // show host name

    change host name to edit /etc/hostname file.

  8. Host name to IP address
    Edit file /etc/hosts

    1
    2
    127.0.0.1 localhost
    xxx.xxx.xxx.xxx host1
  9. Nested Commands

    1
    2
    3
    $> echo www.baidu.com > a.txt
    $> echo `cat a.txt`
    $> ping $(echo $(cat a.txt))
  10. Add and Delete users

    1
    2
    $> useradd -m newuser // add new user
    $> userdel -rf newuser // delete new user
  11. Env variable

    1
    2
    3
    $> echo ${PATH}
    $> echo "$PATH"
    $> export mypath=${name:-$PATH} // ternary operator
  12. Parameters of scripts

    1
    2
    3
    4
    5
    6
    $? // return value
    $# // number of params
    $n // the n-th param
    $0 // current name of script
    $@ // get all params
    shift // left move param
  13. If
    An example of if:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    #!/bin/bash
    if [ $# -lt 2 ]; then
    echo less than 2!
    elif [ $# -gt 2 ]; then
    echo greater then 2!
    else
    echo good!
    fi
    echo ==============
    echo param number is: $#
    echo all params are: $@
    echo the 2nd param is: $2
    echo current script name is: $0
  14. For
    An example of for

    1
    2
    3
    4
    5
    6
    7
    8
    #!/bin/bash
    lines=5
    for (( x=1; x<=lines; x=$x+1 )); do
    for (( y=1; y<=$x; y=$y+1 )); do
    echo -n $ye
    done
    echo
    done
  15. YUM

    • Repository

      1
      2
      3
      $> mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
      $> curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
      $> yum makecache
    • Yum Commands

      1
      2
      3
      4
      5
      6
      7
      $> yum list // list all packages
      $> yum list installed // list all installed packages
      $> yum search xxx // search xxx in repos
      $> yum remove xxx // remove an installed package xxx
      $> yum install xxx // install a package
      $> yum [re]install --downloadonly --downloaddir=/home/xxx wget // download wget packages into /home/xxx
      $> yum localinstall xxx.rpm // local install a rpm
    • Make ISO file

      1
      2
      $> yum install mkisofs
      $> mkisofs -r -o xxx.iso yyy // make xxx.iso from dir yyy