Linux 学习笔记

Linux学习笔记

请切换web视图查看,表格比较大,方法:视图》》web板式视图html

博客园不能粘贴图片吗java

 http://wenku.baidu.com/view/bda1c3067fd5360cba1adb7dlinux

目录程序员

Linux学习笔记... 1web

请切换web视图查看,表格比较大,方法:视图》》web板式视图... 1正则表达式

1.      经常使用命令... 3shell

1.1文件处理命令... 3数据库

1.2权限管理命令... 8apache

1.3文件搜索命令... 12编程

1.4帮助命令... 19

1.5压缩解压命令... 20

1.6网络通讯指令... 23

1.7 Shell应用技巧... 25

2.      Vim/Vi 28

3.      引导... 34

4软件包的安装... 39

4.1挂载光盘... 39

5.用户管理... 40

5.1组管理... 41

5.2批量添加用户... 41

6.      进程管理... 44

6.2计划任务... 45

7.      shell编程... 46

7.1        hello world. 46

7.2标准输入和输出... 46

7.2变量,位置变量$! $$ $# $@ $* $?,环境变量,运算符... 47

7.3if…else. 52

7.4for. 53

7.5awk. 54

7.6一个显示用户信息的脚本... 54

7.7一个杀死登录用户的脚本... 56

结果以下... 56

脚本内容... 56

7.8select case. 57

select. 57

select+case. 57

case. 58

7.9while. 59

7.10批量添加用户... 59

7.11批量删除用户... 60

7.12break  .. continue. 60

7.13 shift,参数累加求和... 61

效果: 参数左移... 61

7.14用户执行脚本的权限... 62

sh script. 62

1.      对脚本有r权限... 62

2.      脚本所在目录要有r-x权限... 62

脚本直接执行... 62

1.      对脚本有rx权限... 62

2.      脚本所在目录有rx权限... 62

7.15正则表达式... 62

7.16截取字符串awk,cut,set. 65

awk 列操做... 66

第一行不执行,第一行先读取的... 66

因此加BEGIN.. 67

行操做... 67

选取某一行... 68

去掉某一行... 68

追加某一行或几行... 68

替换... 69

7.17定时任务... 69

8.      安装jdk. 71

[root@dc-01 java]#  rpm -qa | grep jdk. 71

java-1.6.0-openjdk-1.6.0.0-1.45.1.11.1.el6.i686. 71

卸载之:... 71

[root@dc-01 java]# yum -y remove java-1.6.0-openjdk-1.6.0.0-1.45.1.11.1.el6.i686. 71

查看系统位数... 71

下载对应的安装包... 71

http://pan.baidu.com/s/1qWnzJCK. 71

1.修改权限为可执行... 71

2.rpm –ivh 安装包... 71

3.vi /etc/profile 尾部添加环境变量... 72

79 JAVA_HOME=/usr/java/jdk1.7.0_67. 72

80 PATH=$JAVA_HOME/bin:$PATH.. 72

81 CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar. 72

82 export JAVA_HOME. 72

83 export PATH.. 72

84 export CLASSPATH.. 72

4. 执行source /etc/profile命令让修改生效。... 72

5.查看安装结果... 72

至此,安装jdk成功... 73

9.      安装Tomcat. 73

1.下载安装包,千万选好安装源,由于安装包的问题,硬是让我调试了一天,真是傻逼,从新官网下载安装以后立马能够用了... 73

http://tomcat.apache.org/download-70.cgi 73

2.解压到/usr/local 下,并重命名为tomcat. 73

#tar zxvf apache-tomcat-7.0.35.tar.gz /解压... 73

#mv apache-tomcat-7.0.35 apache-tomcat /改名... 73

#cd /apache-tomcat/bin/ /打开此目录... 74

#chmod 777 *.sh /加777权限... 74

#bash catalina.sh start /启动... 74

 

 

1.    经常使用命令

命令存放,哪些命令能够执行?

 

root:

/sbin

/usr/sbin

all users:

 

/bin

/usr/bin

bin--binary 二进制文件

Linux全部都是文件,都是二进制文件

usr—user

sbin—super binary

 

 

1.1文件处理命令

 

文件处理命令

 

1

ls

英文原意是list   功能:显示目录文件 属性能够连着写,好比ls -ld

Eg

含义

-a    all

显示全部文件,包括隐藏文件

ls -a /

 

-l    long

 

 

 

-I 显示i节点

详细信息显示

[root@localhost ~]# ls -l

total 68

-rw------- 1 root root  1211 Feb 14 04:02 anaconda-ks.cfg

drwxr-xr-x 3 root root  4096 Feb 14 11:20 Desktop

-rw-r--r-- 1 root root 31736 Feb 14 04:02 install.log

-rw-r--r-- 1 root root     0 Feb 14 03:16 install.log.syslog

drwxr-xr-x 2 root root  4096 Feb 14 17:36 test

drwxr-xr-x             2          root       root   4096      Feb 14 11:20

每三个表示权限   表示硬链接数   全部者    所属组  文件大小  建立时间

数据块 block  512字节

第一个字符表示以下:

d  目录directory

-          二进制文件

l  软连接文件

每三个分配以下:

r—read 读   w—write写  x—execute执行

rwx         r-x          r-x

全部者u    所属组g      其余人o

user         group        others

-d

查看目录属性

[root@localhost ~]# ls -ld /test

drwxr-xr-x 3 root root 4096 Feb 14 17:42 /test

 

2

cd

切换目录

 

 

Cd  /

进入根目录

 

 

Cd [目录]

 

 

 

Cd ..

返回父级目录

 

 

3

pwd

英文:print working directory

查看当前目录

[root@localhost ~]# pwd

/root

 

4

touch

建立空文件

 

 

[root@localhost test]# touch testfile

[root@localhost test]# ls -l testfile

-rw-r--r-- 1 root root 0 Feb 14 18:51 testfile

 

 

5

mkdir

英文:make directories

建立空目录

[root@localhost ~]# mkdir test

 

6

cp

英文:copy

复制文件

-R 复制目录

 

copy   [源文件,可多个] [目的目录]

[root@localhost test]# cp /etc/inittab /etc/services /test

[root@localhost test]# ls /test

abc.txt  inittab  lost+found  samlee  services  testfile

 

将etc拷贝到test下

[root@localhost test]# cp -R /etc /test

 

/etc 主要是配置文件,很重要,记得备份

命令中止快捷键:Ctrl+c

7.

mv

英文:move

移动文件,更名

[root@localhost test]# ls /test

abc.txt  etc  inittab  lost+found  samlee  services  testfile

更名:

[root@localhost test]# mv services service 

[root@localhost test]# ls /test

abc.txt  etc  inittab  lost+found  samlee  service  testfile

移动:

[root@localhost test]# mv /test/inittab /tmp/

[root@localhost test]# ls /test

abc.txt  etc  lost+found  samlee  service  testfile

更名+移动:

[root@localhost test]#  mv /test/testfile /tmp/file.test

[root@localhost test]# ls /tmp

file.test                                   scim-panel-socket:0-root

gconfd-root                                 scim-socket-frontend-root

inittab                                     ssh-yoUWCY4180

keyring-z1fmdW                              virtual-root.IYU2ep

mapping-root                                vmware-config0

orbit-root                                  VMwareDnD

scim-bridge-0.3.0.lockfile-0@localhost:0.0  vmware-root

scim-bridge-0.3.0.socket-0@localhost:0.0    vmware-root-592157060

scim-helper-manager-socket-root

 

 

8

rm

remove

删除

[root@localhost test]# ls /test

abc.txt  etc  lost+found  samlee  service

删除service

[root@localhost test]# rm service

rm: remove regular file `service'? y

[root@localhost test]# ls /test

abc.txt  etc  lost+found  samlee

删除不询问:

[root@localhost test]# touch testfile

[root@localhost test]# ls

abc.txt  etc  lost+found  samlee  testfile

[root@localhost test]# rm -f testfile

[root@localhost test]# ls

abc.txt  etc  lost+found  samlee

 

rm –f 目录名称  不提示,强制删除,在写脚本的时候用,由于没有yes交互

r表示删除,f表示强制

9

cat

concatenate and display files

查看

[root@localhost test]# cat /etc/issue

CentOS release 5.5 (Final)

Kernel \r on an \m

 

适合查看文件小,由于多的话会把前面的覆盖,不能翻页。

好比cat /etc/services

10

more

(空格)或f 显示下一页

(enter)显示下一行

q或Q 退出

分页查看

[root@localhost test]# more /etc/services

 

 

11

head

-num 文件名

查看文件前num行

[root@localhost test]# head -5 /etc/services

# /etc/services:

# $Id: services,v 1.42 2006/02/23 13:09:23 pknirsch Exp $

#

# Network services, Internet style

#

 

 

12

tail

-num  文件名

-f     文件名

查看文件尾num行

动态查看文件尾部信息

[root@localhost test]# tail -5 /etc/services

com-bardac-dw   48556/tcp                       # com-bardac-dw

com-bardac-dw   48556/udp                       # com-bardac-dw

iqobject        48619/tcp                       # iqobject

iqobject        48619/udp                       # iqobject

# Local services

[root@localhost test]# tail -f /etc/services

 

tail –f 为了监视日志文件,默认显示10行

13

ln

英文:link

ln 文件名  目的目录

ln –s 文件名 目的目录

-s soft软链接

建立硬连接

建立软连接

[root@localhost test]# ln -s /etc/issue /issue.soft

[root@localhost test]# ls -l /etc/issue /issue.soft

-rw-r--r-- 1 root root 47 Apr 26  2010 /etc/issue

lrwxrwxrwx 1 root root 10 Feb 14 16:51 /issue.soft -> /etc/issue

 

硬连接:

[root@localhost test]# ln  /etc/issue /issue.hard

[root@localhost test]# ls -l /etc/issue /issue.hard

-rw-r--r-- 2 root root 47 Apr 26  2010 /etc/issue

-rw-r--r-- 2 root root 47 Apr 26  2010 /issue.hard

 

拷贝:

[root@localhost test]# cp /etc/issue /test/issue

[root@localhost test]# ls -l /etc/issue /test/issue

-rw-r--r-- 2 root root 47 Apr 26  2010 /etc/issue

-rw-r--r-- 1 root root 47 Feb 14 20:31 /test/issue

 

拷贝而且不改变时间,好比某些备份

[root@localhost test]# cp -p /etc/issue /test/issue

cp: overwrite `/test/issue'? y

[root@localhost test]# ls -l /etc/issue /test/issue

-rw-r--r-- 2 root root 47 Apr 26  2010 /etc/issue

-rw-r--r-- 1 root root 47 Apr 26  2010 /test/issue

 

 

 

软链接文件类型是l

软链接全部人都有权限,但能不能访问取决于源文件

软链接时间值 是建立软链接的时间

至关于快捷方式

 

相似于copy,文件大小相同

不一样于copy的是,它是同步更新的。

 

还有一个不一样的是,拷贝的时间是不一样,时间是建立的时间

 

一个i节点能够映射到多个文件,因此硬连接能够同步更新。

 

 

 

 

1.2权限管理命令

权限管理命令

14

chmod

change the permissions mode of a file

chmod[{ugo0}{+-=}[文件或目录][mode=421][文件或目录]

功能:

改变文件或目录权限

 

 

用数字表示

r--4

w--2

x—1

rwxr-xr--  754

rw-r-x—x  651

 

 

文件:

r-car,more,head,tail

w-echo,vi 能够修改内容

x-命令,脚本

目录:

r-ls

w-touch,mkdir,rm 对目录有这些权限

x-cd 对目录能够进去

因此,全部的目录都有rx权限,表示能够读取能够进去

[root@localhost test]# ls -l a

-rwxr-x--- 1 root root 0 Feb 19 15:45 a

[root@localhost test]# chmod o+rwx a

[root@localhost test]# ls -l a

-rwxr-xrwx 1 root root 0 Feb 19 15:45 a

[root@localhost test]# chmod o-rw a

[root@localhost test]# ls -l a

-rwxr-x--x 1 root root 0 Feb 19 15:45 a

[root@localhost test]# chmod g=r a

[root@localhost test]# ls -l a

-rwxr----x 1 root root 0 Feb 19 15:45 a

[root@localhost test]# chmod g=rx a

[root@localhost test]# ls -l a

-rwxr-x--x 1 root root 0 Feb 19 15:45 a

 

[root@localhost test]# chmod 641 a

[root@localhost test]# ls -l a

-rw-r----x 1 root root 0 Feb 19 15:45 a

chmod u+权限 文件或目录-------给所属者增长权限

chmod u+权限 文件或目录-------给所属者减小权限

 

chmod g=权限 文件或目录-------给所属组赋予权限

 

chmod o -----------------------------------同u,为加减权限

 

 

 

 

 

 

 

用数字表示权限,直接赋值就能够  chmod 641 a

15

chown

change file ownership

改变全部者

[root@localhost test]# ls -l a

-rw-r----x 1 root root 0 Feb 19 15:45 a

[root@localhost test]# chown helen a

[root@localhost test]# ls -l a

-rw-r----x 1 helen root 0 Feb 19 15:45 a

[root@localhost test]# chown nobody a

[root@localhost test]# ls -l a

-rw-r----x 1 nobody root 0 Feb 19 15:45 a

 

 

16

chgrp

change file group ownership

改变所属组

[root@localhost test]# ls -l a

-rw-r----x 1 nobody root 0 Feb 19 15:45 a

[root@localhost test]# chgrp adm a

[root@localhost test]# ls -l a

-rw-r----x 1 nobody adm 0 Feb 19 15:45 a

 

 

17

umask

 

查看建立文件的默认权限

改变默认权限 umask 权限掩码值

[root@localhost test]# mkdir newdir

[root@localhost test]# ls -ld newdir

drwxr-xr-x 2 root root 4096 Feb 20 10:40 newdir

[root@localhost test]# umask

0022

[root@localhost test]# umask -S

u=rwx,g=rx,o=rx

 

 

*

0022

 

特殊权限位

022-用户权限位,权限掩码值

   777

022

755

022 就是表示755

 

SetUID 4

SetGID 2

chmod u+s

       4755

       2755 组id

        6755同时SetUID和SetGID

 

*

Linux权限规则

 

缺省建立的文件不能授予可执行x权限

[root@localhost test]# touch testfile

[root@localhost test]# ls -l testfile

-rw-r--r-- 1 root root 0 Feb 20 10:50 testfile

 

虽然建立文件的默认权限是022,但建立的空文件testfile没有x权限

*

添加用户

 

 

[root@localhost test]# useradd miao

[root@localhost test]# passwd miao

Changing password for user miao.

New UNIX password:

BAD PASSWORD: it is too short

Retype new UNIX password:

passwd: all authentication tokens updated successfully.

添加用户信息

设置密码

设置密码

 

*

su -

切换用户

 

 

 

 

 

 

1.3文件搜索命令

Linux中全部都是文件,命令也是文件

文件搜索命令

18

which

 

查询命令所在的绝对路径

[root@localhost ~]# which chmod

/bin/chmod

[root@localhost ~]# whereis ls

ls: /bin/ls /usr/share/man/man1p/ls.1p.gz /usr/share/man/man1/ls.1.gz

 

命令也是文件

whereis除了绝对路径,还包括帮助文档

19

find

 

查找文件或目录

find [搜索路径][搜索关键字]

 

-name 文件名

*匹配任意字符 init*

?匹配单个字符 init???

 

-size 文件大小 block数据块 512字节=0.5kb

大于+

小于-

等于 find / -size 204800

 

-user 文件全部者

 

时间

  1. 天 ctime  atime  mtime
  2. 分钟 cmin  amin  mmin

c—change改变,表示文件的属性被修改过,全部者、所属组、权限

a—access访问

m—modify修改,表示文件的内容被修改过

-以内,+超过

find /etc –mmin  -120 一分钟内被修改过

-type 文件类型  f 二进制文件

               l 软链接文件

               d 目录

  1. 链接符  -a and   逻辑与 

        -o or     逻辑或

2.  链接符 find …. –exec 命令{}\;

          {}find查询的结果

          \转义符,符号命令使用自己的含义

          ;结果

          -ok提示

 

 

 

 

 

 

[root@localhost ~]# find /etc -name init

/etc/sysconfig/init

 

试验通配符和占位符

[root@localhost ~]# find /etc -name init*

/etc/selinux/targeted/contexts/initrc_context

/etc/sysconfig/init

/etc/sysconfig/network-scripts/init.ipv6-global

/etc/init.d

/etc/mail/spamassassin/init.pre

/etc/inittab

/etc/initlog.conf

/etc/rc.d/init.d

 

[root@localhost ~]# find /etc -name init???

/etc/inittab

[root@localhost ~]# find /etc -name init?

[root@localhost ~]# find /etc -name init??

/etc/init.d

/etc/rc.d/init.d

 

查找用户

[root@localhost ~]# find /home -user helen

/home/helen

/home/helen/.bash_logout

/home/helen/.kde

/home/helen/.kde/Autostart

/home/helen/.kde/Autostart/.directory

/home/helen/.mozilla

/home/helen/.mozilla/extensions

/home/helen/.mozilla/plugins

/home/helen/.bash_profile

/home/helen/.bashrc

/home/helen/.bash_history

 

测试转义字符

[root@localhost ~]# which rm

alias rm='rm -i'

        /bin/rm

[root@localhost ~]# rm abc.txt

rm: remove regular empty file `abc.txt'?

[root@localhost ~]# \rm abc.txt

 

查找二进制文件

[root@host141 ~]# find /etc -name init* -a -type f

/etc/inittab

/etc/initlog.conf

/etc/sysconfig/network-scripts/init.ipv6-global

/etc/sysconfig/init

/etc/selinux/targeted/contexts/initrc_context

 

测试链接符-exec

[root@localhost ~]# find /etc -name inittab

/etc/inittab

[root@localhost ~]# find /etc -name inittab -exec ls -l {} \;

-rw-r--r-- 1 root root 1666 Feb 14 04:02 /etc/inittab

 

[root@localhost ~]# cd /test

[root@localhost test]# pwd

/test

[root@localhost test]# ls

a  a.hard  a.soft  etc  issue  lost+found

[root@localhost test]# find /test -name a.soft

/test/a.soft

[root@localhost test]# find /test -name a.soft -exec rm {} \;

[root@localhost test]# ls

a  a.hard  etc  issue  lost+found

 

测试链接符-ok

[root@localhost test]# find /etc -name inittab -exec ls -l {} \;

-rw-r--r-- 1 root root 1666 Feb 14 04:02 /etc/inittab

[root@localhost test]# find /etc -name inittab -ok ls -l {} \;

< ls ... /etc/inittab > ? y

-rw-r--r-- 1 root root 1666 Feb 14 04:02 /etc/inittab

 

[root@localhost test]# ls

a  a.hard  etc  issue  lost+found

[root@localhost test]# find /test -name a.hard -ok rm {} \;

< rm ... /test/a.hard > ? y

[root@localhost test]# ls

a  etc  issue  lost+found

 

[root@localhost test]# find /etc -name init* -a -type f -exec ls -l {} \;

-rw-r--r-- 1 root root 28 Apr 10  2010 /etc/selinux/targeted/contexts/initrc_context

-rw-r--r-- 1 root root 1068 Jul  4  2009 /etc/sysconfig/init

-rwxr-xr-x 1 root root 5433 Jul  4  2009 /etc/sysconfig/network-scripts/init.ipv6-global

-rw-r--r-- 1 root root 1299 Jan 21  2009 /etc/mail/spamassassin/init.pre

-rw-r--r-- 1 root root 1666 Feb 14 04:02 /etc/inittab

-rw-r--r-- 1 root root 658 Sep 29  2009 /etc/initlog.conf

 

测试根据i节点删除文件

[root@localhost test]# touch "a b";

[root@localhost test]# ls

a  a b

[root@localhost test]# touch -- -abc

[root@localhost test]# ls

a  a b  -abc

 

[root@localhost test]# rm -abc

rm: invalid option -- a

Try `rm ./-abc' to remove the file `-abc'.

Try `rm --help' for more information.

[root@localhost test]# rm a b

rm: remove regular empty file `a'? a

rm: cannot lstat `b': No such file or directory

[root@localhost test]# rm a b

rm: remove regular empty file `a'? y

rm: cannot lstat `b': No such file or directory

 

[root@localhost test]# rm -- -abc "a b"

rm: remove regular empty file `-abc'? y

rm: remove regular empty file `a b'? y

[root@localhost test]# ls

[root@localhost test]#

 

[root@localhost test]# ls -i

1653280 a b  1653352 -abc

[root@localhost test]# find . -inum 1653280

./a b

[root@localhost test]# find . -inum 1653280 -exec rm {} \;

[root@localhost test]# ls

-abc

 

 

 

 

 

 

*通配符

 

大范围查找只在晚上2点左右进行,由于访问人数少,只占用一部分资源

 

 

 

 

 

 

 

?匹配单个字符,至关于占位

 

 

一般用>或者<

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

rm的别名是 rm-i

因此要提示,那么要使用自己的含义,加转义字符\

 

 

 

 

 

查找二进制文件

 

 

 

 

 

 

 

 

查找inittab

查找并显示详细信息

 

 

 

进入test

显示当前目录

 

显示当前目录下的文件

 

查找a.soft文件

 

查找a.soft文件并删除

a.soft已删除

 

 

查找inittab并查看详细信息

 

提示的查看(为了试验,真正用在rm)

 

 

 

 

 

 

 

 

 

 

 

查找init开头,文件类型是二进制文件的详细信息

 

 

 

 

 

 

 

 

 

一些奇葩的建立文件

 

 

 

 

 

 

这时候想要删除文件就会出问题

 

 

 

 

 

 

 

 

 

 

咱们知道建立过程的时候能够这样删除,若是不知道呢?

 

 

 

 

 

查找i节点

 

.表示当前目录,即/test

 

根据i节点删除,万能

 

20

locate

list files in databases

locate [搜索关键字]

locate file

能够查找全部跟file相关的文件,速度快

locate指令是根据数据库查找的,若是数据库中文件没有更新,那么就会找不到。

 

按期updatedb,则能够直接locate找到

 

 

 

21

updatedb

update the slocate database

创建整个系统目录文件的数据库

 

 

22

grep

 

grep [指定字串][源文件]

在文件中搜寻字串匹配的行,并输出

[root@localhost test]# grep tftp /etc/services

tftp            69/tcp

tftp            69/udp

tftp-mcast      1758/tcp

tftp-mcast      1758/udp

mtftp           1759/udp

subntbcst_tftp  247/tcp                         # SUBNTBCST_TFTP

subntbcst_tftp  247/udp                         # SUBNTBCST_TFTP

etftp           1818/tcp                        # Enhanced Trivial File Transfer Protocol

etftp           1818/udp                        # Enhanced Trivial File Transfer Protocol

tftps           3713/tcp                        # TFTP over TLS

tftps           3713/udp                        # TFTP over TLS

查找和tftp相关的行

             

 

 

1.4帮助命令

帮助命令

 

 

23

man

manual

man [命令或配置文件]

得到帮助信息

命令和配置文件相同时优先查看命令的帮助

帮助分不少种,其中第一种是命令,第五种是配置文件,当名字相同时经过

man 5来查看配置文件

 

man ls  使用more查看,空格翻页,enter下一行

 

[root@localhost test]# man 5 passwd

 

 

passwd能够修改用户密码,

和一个配置文件同名

24

info

information

info [任何关键字]

获取帮助信息

 

 

25

whatis

 

whatis apropos[任何关键字]

得到索引的简短说明信息

[root@localhost test]# whatis whereis

whereis              (1)  - locate the binary, source, and manual page files for a command

 

 

26

help

 

命令 –help

help 内置命令

[root@localhost test]# ls --help

 

               

 

 

1.5压缩解压命令

windows可解压Linux全部,但相反不可

共同:zip 但压缩比不高,若是小文件建议使用

gzip 和 bzip2只能压缩文件且不保留源文件,但后者-k能够保留

27

gzip

GNU zip

gzip 选项[文件]

压缩后文件格式: .gz

只能压缩文件,不能压缩目录

不保留源文件

 

解压缩:

gunzip 压缩文件

gzip –d 压缩文件

 

 

[root@localhost test]# ls

etc  issue  lost+found  newfile

[root@localhost test]# gzip newfile

[root@localhost test]# ls

etc  issue  lost+found  newfile.gz

 

不能压缩目录

[root@localhost test]# mkdir newdir

[root@localhost test]# ls

etc  issue  lost+found  newdir  newfile.gz

[root@localhost test]# gzip newdir

gzip: newdir is a directory – ignored

 

解压缩

[root@localhost test]# gzip -d newfile.gz

[root@localhost test]# ls

etc  issue  lost+found  newdir  newfile

[root@localhost test]# gzip newfile

[root@localhost test]# ls

etc  issue  lost+found  newdir  newfile.gz

[root@localhost test]# gunzip newfile.gz

[root@localhost test]# ls

etc  issue  lost+found  newdir  newfile

 

 

28

tar

 

打包目录

tar 选项[cvf][目录]

  -c 产生.tar打包文件

  -v 显示详细信息

  -f 指定压缩后的文件名

  -z 打包同时压缩

压缩后文件格式: .tar.gz

 

 

解压缩

  -x 解包.tar文件

  -v 显示详细信息

  -f 指定解压文件

  -z 解压缩

[root@localhost test]# ls

etc  issue  lost+found  newdir  newfile

[root@localhost test]# tar -zcf newdir.tar.gz newdir

[root@localhost test]# ls

etc  issue  lost+found  newdir  newdir.tar.gz  newfile

 

当没有后缀,或者不知道文件类型

[root@localhost test]# tar -zcf new newdir

[root@localhost test]# ls -l new

-rw-r--r-- 1 root root 113 Feb 26 14:56 new

[root@localhost test]# file new

new: gzip compressed data, from Unix, last modified: Thu Feb 26 14:56:08 2015

 

先打包再压缩

[root@localhost test]# tar -cf newdir2.tar newdir

[root@localhost test]# gzip newdir2.tar

[root@localhost test]# ls

etc  issue  lost+found  new  newdir  newdir2.tar.gz  newdir.tar.gz  newfile

 

解压缩

[root@localhost test]# ls

etc  issue  lost+found  new  newdir  newdir2.tar.gz  newdir.tar.gz  newfile

[root@localhost test]# tar -zxf newdir.tar.gz

[root@localhost test]# ls

etc  issue  lost+found  new  newdir  newdir2.tar.gz  newdir.tar.gz  newfile

[root@localhost test]# tar -zxf newdir2.tar.gz

[root@localhost test]# ls

etc  issue  lost+found  new  newdir  newdir2.tar.gz  newdir.tar.gz  newfile

[root@localhost test]# rm -rf newdir

[root@localhost test]# ls

etc  issue  lost+found  new  newdir2.tar.gz  newdir.tar.gz  newfile

[root@localhost test]# tar -zxf new

[root@localhost test]# ls

etc  issue  lost+found  new  newdir  newdir2.tar.gz  newdir.tar.gz  newfile

 

 

 tar –zcf 打包后的名字 要打包的文件名

 

  注:打包后的文件名能够没有后缀,可是为了辨识方便,养成良好习惯

 

 

 

 

看起来像是文本文件,但这种使用cat是没法查看的

使用file查看文件了性

29

zip

 

zip 选项[-r][压缩后文件名称][文件或目录]

-r  压缩目录

功能:压缩文件或目录

压缩后文件格式:.zip

保留源文件

范例:   zip services.zip /etc/services

        zip –r test.zip /test  压缩目录

 

 

 

 

30

unzip

 

unzip [压缩文件]

功能:解压.zip的压缩文件

范例:unzip test.zip

 

 

 

 

31

bzip2

 

bzip2 选项[-k][文件]

         -k 产生压缩文件后保留源文件

不加k则和gzip相同,但压缩比很高

功能:压缩文件

压缩后文件格式: .bz2

范例:  bzip2 –k file1

 

 

32

bunzip2

 

bunzip2 选项[-k][压缩文件]

        -k 解压缩后保留源文件

功能:解压缩

范例: bunzip2 –k file1.bz2

 

 

 

 

 

1.6网络通讯指令

33

write

 

当用户登录的时候,能够进行信息交互,

以Ctrl+D做为结束

 

[root@localhost test]# write helen

this is a test,hello

[helen@localhost ~]$   这里使用SSH登录

Message from root@localhost.localdomain on pts/1 at 15:37 ...

this is a test,hello

 

34

wall

 

登录的全部人都会收到

 

 

35

ping

 

测试网络连通性

ping 192.168.1.1

 

和windows不一样的是,Linux若是不ctrl+c终止就会一直进行下去

 

注意:

  丢包率:packet loss

  有时候数据存取不完整,检查网络设备。

 ping上万次

 

 

若是ping不通,先ping本机,证实本身没问题,ping 127.0.0.1 回环地址,检查本身的设置。

不通的时候不必定是网络不通,有可能防火墙等屏蔽了,不要武断的判断网络有问题。

 

改变ping的次数

[root@localhost test]# ping -c 3 192.168.0.141 像windows同样定义ping的次数

PING 192.168.0.141 (192.168.0.141) 56(84) bytes of data.

64 bytes from 192.168.0.141: icmp_seq=1 ttl=128 time=0.568 ms

64 bytes from 192.168.0.141: icmp_seq=2 ttl=128 time=0.456 ms

64 bytes from 192.168.0.141: icmp_seq=3 ttl=128 time=0.451 ms

 

--- 192.168.0.141 ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 2001ms

rtt min/avg/max/mdev = 0.451/0.491/0.568/0.059 ms

 

默认64字节,改变数据包大小

[root@localhost test]# ping -s 300 192.168.0.141

PING 192.168.0.141 (192.168.0.141) 300(328) bytes of data.

308 bytes from 192.168.0.141: icmp_seq=1 ttl=128 time=0.517 ms

 

36

ifconfig

 

ifconfig 选项[-a][网卡设备标识]

         -a 显示全部网卡信息

功能:查看网络设置信息

范例:ifconfig –a

eth0 本机物理网卡

lo 回环网卡地址

ifconfig eth0 192.168.9.4

修改ip,仅本次生效

Linux基本:只有写入配置文件才会永久生效

 

 

37

shutdown

只有root能够执行

 

[root@localhost test]# shutdown -h now最好不要使用,立马关机

关机前wall一下你们保存,而后shutdown,有缓冲时间

 

38

reboot

重启,root,服务器一般不随便开关

 

 

 

 

 

 

1.7 Shell应用技巧

一般使用bash,查看cat /etc/shells

命令补全

按Tab,若是是惟一的则直接补全,若是不惟一则按两下以后出现候选命令

清屏

clear 或者Ctrl+l

清除光标前字符

Ctrl+u

查看之前的命令

history

!123 执行第123条命令

方向键上下能够找到历史命令

定义别名

 

alias copy=cp

alias xrm=”rm –r”组合要括起来

 

清除别名:unalias copy

[root@localhost test]# alias

alias cp='cp -i'

alias l.='ls -d .* --color=tty'

alias ll='ls -l --color=tty'

alias ls='ls --color=tty'

alias mv='mv -i'

alias rm='rm -i'

alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

这是系统定义的别名

 

[root@localhost test]# alias copy=cp   自定义别名

[root@localhost test]# copy /etc/inittab .  拷贝到当前目录

[root@localhost test]# ls

etc      issue       new     newdir2.tar.gz  newdir.zip  newfile.bz2

inittab  lost+found  newdir  newdir.tar.gz   newfile

 

 

输入、输出重定向

 

通标准I/O同样,Shell对于每个进程预先定义3个文件描述字(0,1,2),分别对应:

0         (STDIN)标准输入

1         (STDOUT)标准输出

2         (STDERR)标准错误输出

 

>或>>输出重定向

范例: ---------------------------------------》》

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<输入重定向

 

 

 

 

 

 

 

2>错误除数重定向

 

 

 

 

 

 

[root@localhost test]# ls -l /tmp >tmp.msg

[root@localhost test]# date > /tmp.msg

[root@localhost test]# cat /tmp.msg

Thu Feb 26 16:49:57 CST 2015 原内容被覆盖

 

使用>>追加进去

[root@localhost test]# ls -l /tmp >> /tmp.msg

[root@localhost test]# cat /tmp.msg

Thu Feb 26 16:49:57 CST 2015

total 92

drwx------ 3 root root 4096 Feb 13 20:52 gconfd-root

drwx------ 2 root root 4096 Feb 25 10:19 keyring-djsYy2

drwx------ 2 root root 4096 Feb 13 20:52 keyring-z1fmdW

srwxr-xr-x 1 root root    0 Feb 25 10:19 mapping-root

drwx------ 2 root root 4096 Feb 26 14:32 orbit-root

-rw-r--r-- 1 root root    6 Feb 26 16:32 scim-bridge-0.3.0.lockfile-0@localhost:0.0

srwxr-xr-x 1 root root    0 Feb 26 14:32 scim-bridge-0.3.0.socket-0@localhost:0.0

srw------- 1 root root    0 Feb 25 10:19 scim-helper-manager-socket-root

srw------- 1 root root    0 Feb 25 10:19 scim-panel-socket:0-root

srw------- 1 root root    0 Feb 25 10:19 scim-socket-frontend-root

drwx------ 2 root root 4096 Feb 25 10:19 ssh-khlNme4534

drwx------ 2 root root 4096 Feb 25 10:19 virtual-root.U2Qf0Y

drwxr-xr-x 2 root root 4096 Feb 25 09:34 vmware-root

drwx------ 2 root root 4096 Feb 25 10:19 vmware-root-592157060

 

<输入重定向

能够写一个定时脚本,而后自动输出

[root@localhost test]# wall < /etc/issue

 

Broadcast message from root (Thu Feb 26 17:08:07 2015):

 

CentOS release 5.5 (Final)

Kernel \r on an \m

 

2>错误除数重定向

晚上按期备份,若是出错,保存错误信息

[root@localhost test]# cp -R /usr /backup/usr.bak 2> /bak.error

 

[root@localhost test]# ls /kdls

ls: /kdls: No such file or directory

[root@localhost test]# ls /kdls 2> ls.err   将错误信息写入,这个在写自动化脚本时很是有用

[root@localhost test]# cat ls.err

ls: /kdls: No such file or directory

[root@localhost test]# ls /tmp 2> ls.err  若是不错则没有

gconfd-root                                 scim-helper-manager-socket-root

keyring-djsYy2                              scim-panel-socket:0-root

keyring-z1fmdW                              scim-socket-frontend-root

mapping-root                                ssh-khlNme4534

orbit-root                                  virtual-root.U2Qf0Y

scim-bridge-0.3.0.lockfile-0@localhost:0.0  vmware-root

scim-bridge-0.3.0.socket-0@localhost:0.0    vmware-root-592157060

 

管道

将一个命令的输出传送给另外一个命令,做为另外一个命令的输入

 

[root@localhost test]# ls -l /etc | more 将ls -l /etc的输出传送给more,能够空格翻页,enter换行,q退出

[root@localhost test]# ls -l /etc | grep init 包含init的行

lrwxrwxrwx  1 root root      11 Feb 14 03:18 init.d -> rc.d/init.d

-rw-r--r--  1 root root     658 Sep 29  2009 initlog.conf

-rw-r--r--  1 root root    1666 Feb 14 04:02 inittab

lrwxrwxrwx  1 root root      15 Feb 14 03:25 rc.sysinit -> rc.d/rc.sysinit

 

[root@localhost test]# wc -l /etc/services wc能够查看行数 –l表示line行

9249 /etc/services

[root@localhost test]# ls -l /etc | grep init | wc –l 多个管道 这里是说:查看etc下包含init多少行

4

 

命令链接符

;

用; 间隔的各命令按顺序依次执行。

&&

先后命令的执行存在逻辑与关系,只有&&前面的命令执行成功后,它后面的命令才被执行。

||

先后命令的执行存在逻辑或关系,只有||前面的命令执行失败后,它后面的命令才被执行。

 

顺序执行

[root@localhost test]# pwd ; ls ;date

/test

etc      issue       ls.err  newdir2.tar.gz  newdir.zip  newfile.bz2

inittab  lost+found  new     newdir.tar.gz   newfile     tmp.msg

Thu Feb 26 17:27:57 CST 2015

能够将长时间的命令,好比升级内核,顺序执行,错误记录

 

逻辑与

[root@localhost test]# write Mary < /home/helen/love.txt && rm /home/helen/love.txt

小伙定时表白,若是发送成功,则毁灭证据

[root@localhost test]# ls && pwd

etc      issue       ls.err  newdir2.tar.gz  newdir.zip  newfile.bz2

inittab  lost+found  new     newdir.tar.gz   newfile     tmp.msg

/test

[root@localhost test]# lslsl && pwd

bash: lslsl: command not found

 

逻辑或

相反,只有一个能执行成功。

[root@localhost test]# write Mary < /home/helen/love.txt || mail Mary < /home/helen/love.txt

若是发情书成功就好了,若是发情书失败则发邮件

[root@localhost test]# ls || pwd

etc      issue       ls.err  newdir2.tar.gz  newdir.zip  newfile.bz2

inittab  lost+found  new     newdir.tar.gz   newfile     tmp.msg

[root@localhost test]# sfld || pwd

bash: sfld: command not found

/test

 

 

命令替换符

将一个命令的输出做为另外一个命令的参数

键盘1左边的符号`

[root@localhost test]# which touch  查看touch所在

/bin/touch

[root@localhost test]# ls -l /bin/touch 查看详情

-rwxr-xr-x 1 root root 42284 Mar  1  2010 /bin/touch

[root@localhost test]# ls -l `which touch` 能够直接作参数

-rwxr-xr-x 1 root root 42284 Mar  1  2010 /bin/touch

 

 

 

2.    Vim/Vi

[root@localhost ~]# vi /root/.vimrc

      1 set nu

      2 map ^P I#<ESC>

      3

[root@localhost ~]# vi /etc/inittab

[root@localhost ~]# grep -v "^#" /etc/inittab | more   能够把以#开头的行排除

第一级 存活

  1. 安装 vim
  2. 启动 vim
  3. 什么也别干!请先阅读

当你安装好一个编辑器后,你必定会想在其中输入点什么东西,而后看看这个编辑器是什么样子。但vim不是这样的,请按照下面的命令操做:

  • 动Vim后,vim在 Normal 模式下。
  • 让咱们进入 Insert 模式,请按下键 i 。(陈皓注:你会看到vim左下角有一个–insert–字样,表示,你能够以插入的方式输入了)
  • 此时,你能够输入文本了,就像你用“记事本”同样。
  • 若是你想返回 Normal 模式,请按 ESC 键。

如今,你知道如何在 Insert 和 Normal 模式下切换了。下面是一些命令,可让你在 Normal 模式下幸存下来:

  • i → Insert 模式,按 ESC 回到 Normal 模式.
  • x → 删当前光标所在的一个字符。
  • :wq → 存盘 + 退出 (:w 存盘, :q 退出)   (陈皓注::w 后能够跟文件名)
  • dd → 删除当前行,并把删除的行存到剪贴板里
  • p → 粘贴剪贴板

推荐:

  • hjkl (强例推荐使用其移动光标,但没必要需) →你也可使用光标键 (←↓↑→). 注: j 就像下箭头。
  • :help <command> → 显示相关命令的帮助。你也能够就输入 :help 而不跟命令。(陈皓注:退出帮助须要输入:q

你能在vim幸存下来只须要上述的那5个命令,你就能够编辑文本了,你必定要把这些命令练成一种下意识的状态。因而你就能够开始进阶到第二级了。

当是,在你进入第二级时,须要再说一下 Normal 模式。在通常的编辑器下,当你须要copy一段文字的时候,你须要使用 Ctrl 键,好比:Ctrl-C。也就是说,Ctrl键就好像功能键同样,当你按下了功能键Ctrl后,C就不在是C了,并且就是一个命令或是一个快键键了,在VIM的Normal模式下,全部的键就是功能键了。这个你须要知道。

标记:

  • 下面的文字中,若是是 Ctrl-λ我会写成 <C-λ>.
  • 以 : 开始的命令你须要输入 <enter>回车,例如 — 若是我写成 :q 也就是说你要输入 :q<enter>.

第二级 感受良好

上面的那些命令只能让你存活下来,如今是时候学习一些更多的命令了,下面是个人建议:(陈皓注:全部的命令都须要在Normal模式下使用,若是你不知道如今在什么样的模式,你就狂按几回ESC键)

  1. 各类插入模式
    • a → 在光标后插入
    • o → 在当前行后插入一个新行
    • O → 在当前行前插入一个新行
    • cw → 替换从光标所在位置后到一个单词结尾的字符
  2. 简单的移动光标
    • 0 → 数字零,到行头
    • ^ → 到本行第一个不是blank字符的位置(所谓blank字符就是空格,tab,换行,回车等)
    • $ → 到本行行尾
    • g_ → 到本行最后一个不是blank字符的位置。
    • /pattern → 搜索 pattern 的字符串(陈皓注:若是搜索出多个匹配,可按n键到下一个)
  3. 拷贝/粘贴 (陈皓注:p/P均可以,p是表示在当前位置以后,P表示在当前位置以前)
    • P → 粘贴
    • yy → 拷贝当前行当行于 ddP
  4. Undo/Redo
    • u → undo
    • <C-r> → redo
  5. 打开/保存/退出/改变文件(Buffer)
    • :e <path/to/file> → 打开一个文件
    • :w → 存盘
    • :saveas <path/to/file> → 另存为 <path/to/file>
    • :x, ZZ 或 :wq → 保存并退出 (:x 表示仅在须要时保存,ZZ不须要输入冒号并回车)
    • :q! → 退出不保存 :qa! 强行退出全部的正在编辑的文件,就算别的文件有更改。
    • :bn 和 :bp → 你能够同时打开不少文件,使用这两个命令来切换下一个或上一个文件。(陈皓注:我喜欢使用:n到下一个文件)

花点时间熟悉一下上面的命令,一旦你掌握他们了,你就几乎能够干其它编辑器都能干的事了。可是到如今为止,你仍是以为使用vim仍是有点笨拙,不过不要紧,你能够进阶到第三级了。

第三级 更好,更强,更快

先恭喜你!你干的很不错。咱们能够开始一些更为有趣的事了。在第三级,咱们只谈那些和vi能够兼容的命令。

更好

下面,让咱们看一下vim是怎么重复本身的:

  1. . → (小数点) 能够重复上一次的命令
  2. N<command> → 重复某个命令N

下面是一个示例,找开一个文件你能够试试下面的命令:

  • 2dd → 删除2
  • 3p → 粘贴文本3
  • 100idesu [ESC] → 会写下 “desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu “
  • . → 重复上一个命令—— 100 “desu “.
  • 3. → 重复 3 次 “desu” (注意:不是 300,你看,VIM多聪明啊).

更强

你要让你的光标移动更有效率,你必定要了解下面的这些命令,千万别跳过。

  1. NG → 到第 N (陈皓注:注意命令中的G是大写的,另我通常使用 : N 到第N行,如 :137 到第137行)
  2. gg → 到第一行。(陈皓注:至关于1G,或 :1
  3. G → 到最后一行。
  4. 按单词移动:
    1. w → 到下一个单词的开头。
    2. e → 到下一个单词的结尾。

> 若是你认为单词是由默认方式,那么就用小写的e和w。默认上来讲,一个单词由字母,数字和下划线组成(陈皓注:程序变量)

> 若是你认为单词是由blank字符分隔符,那么你须要使用大写的E和W。(陈皓注:程序语句)

 

下面,让我来讲说最强的光标移动:

  • % : 匹配括号移动,包括 (, {, [. (陈皓注:你须要把光标先移到括号上)
  • 和 #:  匹配光标当前所在的单词,移动光标到下一个(或上一个)匹配单词(*是下一个,#是上一个)

相信我,上面这三个命令对程序员来讲是至关强大的。

更快

你必定要记住光标的移动,由于不少命令均可以和这些移动光标的命令连动。不少命令均可以以下来干:

<start position><command><end position>

例如 0y$ 命令意味着:

  • 0 → 先到行头
  • y → 从这里开始拷贝
  • $ → 拷贝到本行最后一个字符

你可能够输入 ye,从当前位置拷贝到本单词的最后一个字符。

你也能够输入 y2/foo 来拷贝2个 “foo” 之间的字符串。

还有不少时间并不必定你就必定要按y才会拷贝,下面的命令也会被拷贝:

  • d (删除 )
  • v (可视化的选择)
  • gU (变大写)
  • gu (变小写)
  • 等等

(陈皓注:可视化选择是一个颇有意思的命令,你能够先按v,而后移动光标,你就会看到文本被选择,而后,你可能d,也可y,也能够变大写等)

第四级 – Vim 超能力

你只须要掌握前面的命令,你就能够很舒服的使用VIM了。可是,如今,咱们向你介绍的是VIM杀手级的功能。下面这些功能是我只用vim的缘由。

在当前行上移动光标: 0 ^ $ f F t T , ;

  • 0 → 到行头
  • ^ → 到本行的第一个非blank字符
  • $ → 到行尾
  • g_ → 到本行最后一个不是blank字符的位置。
  • fa → 到下一个为a的字符处,你也能够fs到下一个为s的字符。
  • t, → 到逗号前的第一个字符。逗号能够变成其它字符。
  • 3fa → 在当前行查找第三个出现的a
  • 和 T → 和 f 和 t 同样,只不过是相反方向。

还有一个颇有用的命令是 dt" → 删除全部的内容,直到遇到双引号—— "

区域选择 <action>a<object> 或 <action>i<object>

在visual 模式下,这些命令很强大,其命令格式为

<action>a<object> 和 <action>i<object>

  • action能够是任何的命令,如 d (删除), y (拷贝), v (能够视模式选择)
  • object 多是: w 一个单词, W 一个以空格为分隔的单词, s 一个句字, p 一个段落。也能够是一个特别的字符:"、 '、 )、 }、 ]

假设你有一个字符串 (map (+) ("foo")).而光标键在第一个 o 的位置。

  • vi" → 会选择 foo.
  • va" → 会选择 "foo".
  • vi) → 会选择 "foo".
  • va) → 会选择("foo").
  • v2i) → 会选择 map (+) ("foo")
  • v2a) → 会选择 (map (+) ("foo"))

 

块操做: <C-v>

块操做,典型的操做: 0 <C-v> <C-d> I-- [ESC]

  • ^ → 到行头
  • <C-v> → 开始块操做
  • <C-d> → 向下移动 (你也可使用hjkl来移动光标,或是使用%,或是别的)
  • I-- [ESC] → I是插入,插入“--”,按ESC键来为每一行生效。

 

在Windows下的vim,你须要使用 <C-q> 而不是 <C-v> ,<C-v> 是拷贝剪贴板。

自动提示: <C-n> 和 <C-p>

在 Insert 模式下,你能够输入一个词的开头,而后按 <C-p>或是<C-n>,自动补齐功能就出现了……

 

宏录制: qa 操做序列 q, @a, @@

  • qa 把你的操做记录在寄存器 a
  • 因而 @a 会replay被录制的宏。
  • @@ 是一个快捷键用来replay最新录制的宏。

示例

在一个只有一行且这一行只有“1”的文本中,键入以下命令:

  • qaYp<C-a>q→
    • qa 开始录制
    • Yp 复制行.
    • <C-a> 增长1.
    • 中止录制.
  • @a → 在1下面写下 2
  • @@ → 在2 正面写下3
  • 如今作 100@@ 会建立新的100行,并把数据增长到 103.

 

可视化选择: v,V,<C-v>

前面,咱们看到了 <C-v>的示例 (在Windows下应该是<C-q>),咱们可使用 v 和 V。一但被选好了,你能够作下面的事:

  • J → 把全部的行链接起来(变成一行)
  • 或 > → 左右缩进
  • = → 自动给缩进 (陈皓注:这个功能至关强大,我太喜欢了)

 

在全部被选择的行后加上点东西:

  • <C-v>
  • 选中相关的行 (可以使用 j 或 <C-d> 或是 /pattern 或是 % 等……)
  • 到行最后
  • A, 输入字符串,按 ESC

 

分屏: :split 和 vsplit.

下面是主要的命令,你可使用VIM的帮助 :help split. 你能够参考本站之前的一篇文章VIM分屏

  • :split → 建立分屏 (:vsplit建立垂直分屏)
  • <C-w><dir> : dir就是方向,能够是 hjkl 或是 ←↓↑→ 中的一个,其用来切换分屏。
  • <C-w>_ (或 <C-w>|) : 最大化尺寸 (<C-w>| 垂直分屏)
  • <C-w>+ (或 <C-w>-) : 增长尺寸

 

结束语

  • 上面是做者最经常使用的90%的命令。
  • 我建议你天天都学1到2个新的命令。
  • 在两到三周后,你会感到vim的强大的。
  • 有时候,学习VIM就像是在死背一些东西。
  • 幸运的是,vim有不少很不错的工具和优秀的文档。
  • 运行vimtutor直到你熟悉了那些基本命令。
  • 其在线帮助文档中你应该要仔细阅读的是 :help usr_02.txt.
  • 你会学习到诸如  !, 目录,寄存器,插件等不少其它的功能。

 

 

 

3.    引导

在 centOS 中的修改方法以下:

1.root登录,省得总是sudo

2.打开/etc/inittab 文件

   #vim /etc/inittab
3.在默认的 run level 设置中,能够看到第一行书写如:id:5:initdefault:(默认的 run level 等级为 5,即图形
界面)
4.将第一行的 5 修改成 3 便可。

5.保存文件后重启系统你就能够看见是启动的文本界面了。

 

 

 

 

 

 

 

#

id:5:initdefault:

 

# System initialization.

si::sysinit:/etc/rc.d/rc.sysinit

 

l0:0:wait:/etc/rc.d/rc 0

l1:1:wait:/etc/rc.d/rc 1

l2:2:wait:/etc/rc.d/rc 2

l3:3:wait:/etc/rc.d/rc 3

l4:4:wait:/etc/rc.d/rc 4

l5:5:wait:/etc/rc.d/rc 5

l6:6:wait:/etc/rc.d/rc 6

 

[root@localhost ~]# runlevel

5 3

# Default runlevel. The runlevels used by RHS are:

#   0 - halt (Do NOT set initdefault to this)

#   1 - Single user mode

#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)

#   3 - Full multiuser mode

#   4 - unused

#   5 - X11

#   6 - reboot (Do NOT set initdefault to this)

#

 

关机

单用户模式,只有root能够登陆,没有界面

多用模式,没有界面,无NFS

多用户模式,没有图形界面,最多

可用户本身定义

系统缺省的,x11

reboot,重启

 

查看运行级别

 

[root@localhost ~]# ls /etc/rc.d/rc3.d

K01dnsmasq         K80kdump            S19rpcgssd

K02avahi-dnsconfd  K85mdmpd            S22messagebus

K02NetworkManager  K87multipathd       S23setroubleshoot

K02oddjobd         K87named            S25bluetooth

K05conman          K88wpa_supplicant   S25netfs

K05innd            K89dund             S25pcscd

K05saslauthd       K89netplugd         S26acpid

K05wdaemon         K89pand             S26apmd

K10dc_server       K89rdisc            S26haldaemon

K10psacct          K91capi             S26hidd

K10tcsd            K99readahead_later  S26lm_sensors

K12dc_client       S00microcode_ctl    S28autofs

K15httpd           S02lvm2-monitor     S50hplip

K20nfs             S03vmware-tools     S55sshd

K20rwhod           S04readahead_early  S56cups

K24irda            S05kudzu            S56rawdevices

K25squid           S08ip6tables        S56xinetd

K30spamassassin    S08iptables         S57vmware-tools-thinprint

K35dovecot         S08mcstrans         S58ntpd

K35smb             S09isdn             S80sendmail

K35vncserver       S10network          S85gpm

K35winbind         S11auditd           S90crond

K36lisa            S12restorecond      S90xfs

K50ibmasm          S12syslog           S95anacron

K50netconsole      S13cpuspeed         S95atd

K50tux             S13irqbalance       S97yum-updatesd

K50vsftpd          S13portmap          S98avahi-daemon

K69rpcsvcgssd      S14nfslock          S99firstboot

K73ypbind          S15mdmonitor        S99local

K74nscd            S18rpcidmapd        S99smartd

[root@localhost ~]#

[root@localhost ~]# ls -ld /etc/rc3.d

lrwxrwxrwx 1 root root 10 Feb 14 03:25 /etc/rc3.d -> rc.d/rc3.d

 

[root@localhost ~]# /etc/rc.d/init.d/sshd

Usage: /etc/rc.d/init.d/sshd {start|stop|restart|reload|condrestart|status}

[root@localhost ~]# /etc/rc.d/init.d/sshd start

Starting sshd:                                             [  OK  ]

[root@localhost ~]# /etc/rc.d/init.d/sshd stop

Stopping sshd:                                             [  OK  ]

[root@localhost ~]# /etc/rc.d/init.d/sshd restart

Stopping sshd:                                             [FAILED]

Starting sshd:                                             [  OK  ]

[root@localhost ~]# /etc/rc.d/init.d/sshd condrestart

Stopping sshd:                                             [  OK  ]

Starting sshd:                                             [  OK  ]

[root@localhost ~]# /etc/rc.d/init.d/sshd status

openssh-daemon (pid  28037) is running...

[root@localhost ~]# /etc/rc.d/init.d/sshd reload

Reloading sshd:                                            [  OK  ]

[root@localhost ~]#

S22messagebus

关于启动,对应级别的配置

S-start 表示启动

K-kill   表示不启动

之因此设置kill是为了方便切换用户级别的时候关闭哪些服务

22   表示启动顺序,越小越先

messagebus  表示脚本名称

 

关闭启动

[root@localhost ~]# mv S03vmware-tools s03vmvare-tools

修改脚本或删除脚本,只要不是S开头就好

 

firmvare CMOS/BIOS  --POST

  |

BootLoader  Grub root-/boot kernel- initrd-

  |

Kernel  hardware

  |

init  PID=1

  |

/etc/inittab  id:runlebels:action:process

  |

initdefault

  |

/etc/rc.d/rc.sysinit

  |

/etc/rc.d/rc

  |

/etc/rc.d/rcN.d

 

 

 

 

软链接

 

开启与关闭方法

使用方法

 

[root@localhost ~]# ntsysv

[root@localhost ~]# ntsysv --level 3

 

设置启动仍是关闭

空格改变是否启动,*表示启动,空白表示不启动

Tab选择是否保存与返回

 

[root@localhost ~]# dmesg | grep eth0

eth0: no IPv6 routers present

eth0: no IPv6 routers present

eth0: no IPv6 routers present

[root@localhost ~]# dmeg | grep eth1

bash: dmeg: command not found

[root@localhost ~]# dmesg | grep eth1

[root@localhost ~]# dmesg | grep sda

SCSI device sda: 41943040 512-byte hdwr sectors (21475 MB)

sda: Write Protect is off

sda: Mode Sense: 61 00 00 00

sda: cache data unavailable

sda: assuming drive cache: write through

SCSI device sda: 41943040 512-byte hdwr sectors (21475 MB)

sda: Write Protect is off

sda: Mode Sense: 61 00 00 00

sda: cache data unavailable

sda: assuming drive cache: write through

 sda: sda1 sda2 sda3 sda4 < sda5 >

sd 0:0:0:0: Attached scsi disk sda

SELinux: initialized (dev sda1, type ext3), uses xattr

EXT3 FS on sda1, internal journal

EXT3 FS on sda5, internal journal

SELinux: initialized (dev sda5, type ext3), uses xattr

EXT3 FS on sda2, internal journal

SELinux: initialized (dev sda2, type ext3), uses xattr

Adding 2096472k swap on /dev/sda3.  Priority:-1 extents:1 across:2096472k

 

判断硬件是否识别

 

[root@localhost ~]# ls /var /log

ls: /log: No such file or directory

/var:

account  crash  empty  games  lib    lock  mail   nis  preserve  run    tmp  www

cache    db     ftp    gdm    local  log   named  opt  racoon    spool  tux  yp

[root@localhost ~]# grep sshd /var/log/messages

[root@localhost ~]# grep syslog /var/log/messages

Feb 25 10:39:53 localhost syslogd 1.4.1: restart.

Feb 27 11:17:11 localhost syslogd 1.4.1: restart.

 

查看引导时文件错误

忘记密码

 

重启,5s倒计时,按Esc,进入启动项选择,

选择内核编辑,第二行

按e编辑

按e编辑

后面空格 1,表示进入单用户模式,单用户模式只有root能够登陆且不须要密码

按b启动

 

 

 

 

 

给grub添加密码

 

 

123456加密md5

 

 

4软件包的安装

4.1挂载光盘

安装sudo这个软件

 

挂载光盘:

 

mkdir /mnt/cdrom

mount /dev/cdrom /mnt/cdrom

前提是有光盘镜像,也就是VMware要设置光盘为镜像文件

查询:

 

rpm –q sudo

rpm –qa |grep samba

[root@localhost CentOS]# rpm -qa | grep samba

samba-3.0.33-3.28.el5

system-config-samba-1.2.41-5.el5

samba-common-3.0.33-3.28.el5

samba-client-3.0.33-3.28.el5

 

查看和samba相关的软件包

误删文件

 

 

 

     

 

5.用户管理

用户管理

 

[root@DBserver ~]# more /etc/passwd

root:x:0:0:root:/root:/bin/bash

用户名:密码位:UID:GID:描述信息:宿主信息:shell

 

三种用户:

超级用户(root,uid=0)

普通用户

伪用户

uid改成0便可得到root权限,后门

用户密码放在 /etc/shadow

root:$1$Gy//UTmq$00qIJOFSX5brjnPoERd91/:15552:0:99999:7:::

用户名:加密密码:最后一次修改时间(以天为单位19700701以后):最小时间间隔(一般为0,表示两次修改的最小天数)

:最大时间间隔:警告时间(快到期提醒,默认7天):闲置时间(空白表示每天登陆):

将shadow密码删除后不须要密码就能够登陆

为何普通用户能够更改密码

 

[root@localhost ~]# ls -l /usr/bin/passwd

-rwsr-xr-x. 1 root root 25980 2月  22 2012 /usr/bin/passwd

SetUID权限,用户执行这个命令的时候将以这个程序的

全部者root的身份执行。

5.1组管理

[root@localhost ~]# more /etc/group

sys:x:3:bin,adm

组名:组密码位:GID:组成员

 

5.2批量添加用户

vi /test/user.info

miao01::1001:1::/home/miao01:/bin/bash

miao02::1002:1::/home/miao02:/bin/bash

miao03::1003:1::/home/miao03:/bin/bash

miao04::1004:1::/home/miao04:/bin/bash

 

yy复制

p粘贴

dd删除

newusers < user.info

 

[root@localhost test]# tail -8 /etc/passwd

webalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologin

sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

tcpdump:x:72:72::/:/sbin/nologin

helen:x:500:500:yue:/home/helen:/bin/bash

miao01:x:1001:501::/home/miao01:/bin/bash

miao02:x:1002:501::/home/miao02:/bin/bash

miao03:x:1003:501::/home/miao03:/bin/bash

miao04:x:1004:501::/home/miao04:/bin/bash

 

[root@localhost test]# ls /home

helen  miao01  miao02  miao03  miao04

 

[root@localhost test]# pwunconv 取消shadow password功能

 

[root@localhost test]# vi pass.info

      1 miao01:miaoruifeng

      2 miao02:miaoruifeng

      3 miao03:miaoruifeng

      4 miao04:miaoruifeng

 

[root@localhost test]# chpasswd < pass.info

 

[root@localhost test]# tail -5 /etc/passwd

helen:$6$hAI2Non/v8ILJHUB$hZRdcI84l6l8Z00SSSC47g/bZDvbw82elFrlkzw9/mgPzhtZ0DUZxEBZaKE.bg01YJ4KzC40enFZ9ICkQPK/U1:500:500:yue:/home/helen:/bin/bash

miao01:$6$ss3Y3rTq5J/ZsM$RM4MxoMQY0hKQVoiYoDdIxd.rOxIvhhDX4KSAtwx/wz8HDi4R/6XPJjSFbaPF3GKOXhfp/4yxM42iqp3uudTi0:1001:501::/home/miao01:/bin/bash

miao02:$6$v.82xwjZ0BM2$ALGUvJjUsccS6y.yE/S0gntEKtmvpriBL6Jd5sbr5AnySNrPi1Ay8gI4CDDNFr3U2X/i.Ai5sZqYFkFtu6rYV/:1002:501::/home/miao02:/bin/bash

miao03:$6$SMGHf/SO2JW/M$8qFnwvCejx30Wg6RzpTVXyB3.hh7vYnOwkASEFQwowFZz7cZUQfYYLeTWCzspuJH8AbkWkdca4gQ3fwvhNWwZ0:1003:501::/home/miao03:/bin/bash

miao04:$6$5JzRLvtHoJCYs3KG$0JuxD5CbBxMq1vIn49Xv/HGtiF.z.JW9PbdshbylEpTv6iMu7mBM2k8z2BOUi.i8prODMl/vGyNEXsRqcSq7C0:1004:501::/home/miao04:/bin/bash

 

[root@localhost test]# tail -5 /etc/shadow

tail: cannot open `/etc/shadow' for reading: No such file or directory   由于取消了shadow,须要打开

 

[root@localhost test]# pwconv  开启shadow

 

[root@localhost test]# tail -5 /etc/shadow     密码添加成功

helen:$6$hAI2Non/v8ILJHUB$hZRdcI84l6l8Z00SSSC47g/bZDvbw82elFrlkzw9/mgPzhtZ0DUZxEBZaKE.bg01YJ4KzC40enFZ9ICkQPK/U1:16498:0:99999:7:::

miao01:$6$ss3Y3rTq5J/ZsM$RM4MxoMQY0hKQVoiYoDdIxd.rOxIvhhDX4KSAtwx/wz8HDi4R/6XPJjSFbaPF3GKOXhfp/4yxM42iqp3uudTi0:16498:0:99999:7:::

miao02:$6$v.82xwjZ0BM2$ALGUvJjUsccS6y.yE/S0gntEKtmvpriBL6Jd5sbr5AnySNrPi1Ay8gI4CDDNFr3U2X/i.Ai5sZqYFkFtu6rYV/:16498:0:99999:7:::

miao03:$6$SMGHf/SO2JW/M$8qFnwvCejx30Wg6RzpTVXyB3.hh7vYnOwkASEFQwowFZz7cZUQfYYLeTWCzspuJH8AbkWkdca4gQ3fwvhNWwZ0:16498:0:99999:7:::

miao04:$6$5JzRLvtHoJCYs3KG$0JuxD5CbBxMq1vIn49Xv/HGtiF.z.JW9PbdshbylEpTv6iMu7mBM2k8z2BOUi.i8prODMl/vGyNEXsRqcSq7C0:16498:0:99999:7:::

 

 

问题1newusers:conmmand not found/// newusers: cannot lock /etc/passwd; try again later.

答:因为多用户操做密码文件未关闭而上锁,解决方法:删除:rm –rf /etc/*.lock

问题2newusers: line 5: invalid line

答:第五行为空,删掉空行,不能空行。

 

 

 

限制su,用户受权

sudo可让普通用户以root身份执行命令,权限精细化

 

visudo

miao01 miao=/usr/sbin/useradd,/usr/sbin/userdel

用户主机名权限

 

sudo /usr/sbin/useradd miao  添加用户miao

 

 [sudo] password for miao01:  输入miao01的密码来验证

 

bash-4.1$ sudo –l  查看本身可使用哪些root权限

Matching Defaults entries for miao01 on this host:

    requiretty, !visiblepw, always_set_home, env_reset, env_keep="COLORS

    DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS", env_keep+="MAIL PS1

    PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE

    LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY

    LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL

    LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY",

    secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin

 

User miao01 may run the following commands on this host:

(root) /usr/sbin/useradd, (root) /usr/sbin/userdel

 

 

miao02 miao=/sbin/shutdown -h now 用户2只能够立刻关机:sudo使命令精确化!

 

 

受权用户使用Apache·

 

首先名字叫作httpd

  1. 1.       查看httpd.conf权限
  2. 2.       找到httpd.conf
  3. 3.       rpm –ql httpd | more
  4. 4.       根据找到的路径查看权限
  5. 5.       ls –l /etc/httpd/conf/httpd.conf

[root@miao ~]# ls -l /etc/httpd/conf/httpd.conf

-rw-r--r--. 1 root root 34418 Aug  2  2013 /etc/httpd/conf/httpd.conf

由此看出,只有root有写权限

 

目标:

  1. 1.       编辑Apache配置文件
  2. 2.       使用Apache启动脚本
  3. 3.       更新网页

目标1方法(3)

  1. 1.       设置用户为httpd全部者 chown
  2. 2.       改变所属组,把用户加入组,授予组w权限
  3. 3.       visudo 用户地址=/bin/vi /etc/httpd/conf/httpd.conf

 

 

bash-4.1$ sudo /bin/vi /etc/httpd/conf/httpd.conf 能够执行了

Error detected while processing /root/.vimrc:

line    1:

E518: Unknown option: nocopatible

Press ENTER or type command to continue

     目标2方法:

  1. 1.       查询httpd方法
  2. 1.       [root@miao ~]# /etc/rc.d/init.d/httpd
  3. 2.       Usage: httpd {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}
  4. 3.       给用户受权
  5. 4.       visudo 用户地址=/etc/rc.d/init.d/htppd start,/etc/rc,d/init.d/httpd reload,/etc/rc.d/init.d/httpd fullstatus,/etc/rc.d/init.d/httpd configtest
  6. 5.        

   

 

 

 

  1. 6.       进程管理

[root@miao ~]# pkill httpd 不用提取pid直接杀死进程

 

改变优先级

 

[root@miao ~]# ps -le | grep httpd

1 S     0  5683     1  0  80   0 -  5096 -      ?        00:00:00 httpd

5 S    48  5685  5683  0  80   0 -  5076 -      ?        00:00:00 httpd

5 S    48  5686  5683  0  80   0 -  5331 -      ?        00:00:00 httpd

5 S    48  5687  5683  0  80   0 -  5331 -      ?        00:00:00 httpd

5 S    48  5688  5683  0  80   0 -  5331 -      ?        00:00:00 httpd

5 S    48  5689  5683  0  80   0 -  5331 -      ?        00:00:00 httpd

5 S    48  5690  5683  0  80   0 -  5331 -      ?        00:00:00 httpd

5 S    48  5691  5683  0  80   0 -  5331 -      ?        00:00:00 httpd

5 S    48  5692  5683  0  80   0 -  5331 -      ?        00:00:00 httpd

5 S    48  5693  5683  0  80   0 -  5331 -      ?        00:00:00 httpd

[root@miao ~]# /etc/rc.d/init.d/httpd stop

Stopping httpd:                                            [  OK  ]

[root@miao ~]# nice --5 /etc/rc.d/init.d/httpd start

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

                                                           [  OK  ]

[root@miao ~]# ps -le | grep httpd

1 S     0  5715     1  2  75  -5 -  5096 -      ?        00:00:00 httpd

5 S    48  5717  5715  0  75  -5 -  5076 -      ?        00:00:00 httpd

5 S    48  5718  5715  0  75  -5 -  5331 -      ?        00:00:00 httpd

5 S    48  5719  5715  0  75  -5 -  5331 -      ?        00:00:00 httpd

5 S    48  5720  5715  0  75  -5 -  5331 -      ?        00:00:00 httpd

5 S    48  5721  5715  0  75  -5 -  5331 -      ?        00:00:00 httpd

5 S    48  5722  5715  0  75  -5 -  5331 -      ?        00:00:00 httpd

5 S    48  5723  5715  0  75  -5 -  5331 -      ?        00:00:00 httpd

5 S    48  5724  5715  0  75  -5 -  5331 -      ?        00:00:00 httpd

5 S    48  5725  5715  0  75  -5 -  5331 -      ?        00:00:00 httpd

 

 

 

 

用户退出后进程继续运行

 

[root@miao ~]# nohup find / -name init* > /root/find.init.20150305 &

 

Ctrl+c终止

ctrl+z挂起

 

转到挂起的进程,前台执行

 

[root@miao ~]# jobs               

[1]+  Stopped                 ps -aux | more

[root@miao ~]# fg 1

 

转到后台执行

 

bg 1

 

top

 

 

6.2计划任务   

at 时间

命令

 

若是这个进程没有启动,手动启动一下

 

 

执行计划任务,查看计划任务,删除计划任务

 

 

 

把具体的时间添上,不知道的都写*

分钟小时星期命令/脚本

0    4      * *   *    

0    18     * *   2,5                   每周二周五下午六点执行

0    18     * 1-3  2,5                   13月每周二周五下午六点执行

30   17     * *    1-5 /usr/bin/wall < /etc/issue

45   17     * *    1-5 /sbin/shutdown –h now

*/2  12-14   * 3-6,9-12 1-5 /bin/cp –r /etc/backup/etc.20150305 2>/backup/etc/etc.bak.err >/dev/null               2分钟执行,错误信息保存

 

crontab

 

[root@miao ~]# ps -le | grep crond

1 S     0  2290     1  0  80   0 -   989 -      ?        00:00:00 crond

[root@miao ~]# /etc/rc.d/init.d/crond start

 

  1. 7.       shell编程

7.1   hello world

[root@miao ~]# mkdir sh

[root@miao ~]# ls

Desktop    Music     Templates        find.init.20150305  sh

Documents  Pictures  Videos           install.log         ??????

Downloads  Public    anaconda-ks.cfg  install.log.syslog

[root@miao ~]# cd sh/

[root@miao sh]# vim hello.sh

 

#!/bin/bash

#miao the first

echo "Mr hello" world ,this is my first shell

~

 

[root@miao sh]# ./hello.sh   经过相对路径或者绝对路径执行

Mr hello world ,this is my first shell

 

7.2标准输入和输出

 

 

7.2变量,位置变量$! $$ $# $@ $* $?,环境变量,运算符

最好大写,以字母下划线开头,包含字母下划线数字。

查看变量

set | more

 

上面用的是分隔符,是键盘1左边的按键

 

 

 

 

 

 

 

$?表示上一个命令是否执行成功:0表示成功

 
 
 
 

sh -x 查看执行过程用+表示

 

 

201537日星期六

 

7.3if…else

因为服务器常常宕机(本身用pc作服务器的学校),须要常常查看Apache是否死掉,若死掉则重启,写了脚本以下

[root@miao test]# cat test.apache

#!/bin/sh

#"if ...else" usage

#Using this program to show your system's services.

 

echo "Now, the web services of this Linux system will be detext..."

echo

 

#Detect www service

 web=`/usr/bin/pgrep httpd`

 if [ "$web" != "" ]

 then

        echo "The Web service is running."

 else

        echo "The Web service is NOT running."

        /etc/rc.d/init.d/httpd start

 fi

 

效果以下:

 

7.4for

 

7.5awk

-F指定分隔符为:,若不指定则为空格,$1开始表明分割的每一部分

查找uid为0 的用户

 

查找用户密码位空的用户,注意长度的表示

 

 

7.6一个显示用户信息的脚本

 

 

 

 

7.7一个杀死登录用户的脚本

结果以下

 

脚本内容

 

 

 

7.8select case

select

 

 

select+case

 

 

 

case

 

 

 

 

7.9while

 

7.10批量添加用户

 

 

7.11批量删除用户

 

7.12break  .. continue

 

7.13 shift,参数累加求和

效果: 参数左移

 

 

 

 

 

7.14用户执行脚本的权限

sh script

  1. 对脚本有r权限
  2. 脚本所在目录要有r-x权限

 

脚本直接执行

  1. 1.       对脚本有rx权限
  2. 2.       脚本所在目录有rx权限

7.15正则表达式

 

 

 

 

 

 

7.16截取字符串awkcutset

 

 

 

 

awk 列操做

 

 

 

 

 

第一行不执行,第一行先读取的

 

因此加BEGIN

 

 

 

行操做

 

 

选取某一行

 

 

去掉某一行

 

追加某一行或几行

 

 

替换

 

 

 

 

 

7.17定时任务

 

 

 

 

 

 

  1. 8.       安装jdk

8.1卸载原装openjdk

[root@dc-01 java]#  rpm -qa | grep jdk

java-1.6.0-openjdk-1.6.0.0-1.45.1.11.1.el6.i686 

 

卸载之:

 [root@dc-01 java]# yum -y remove java-1.6.0-openjdk-1.6.0.0-1.45.1.11.1.el6.i686

 

 

8.2下载安装包

查看系统位数

 

下载对应的安装包

http://pan.baidu.com/s/1qWnzJCK

8.3安装

1.修改权限为可执行

 

2.rpm –ivh 安装包

 

3.vi /etc/profile 尾部添加环境变量

 

 

79 JAVA_HOME=/usr/java/jdk1.7.0_67

 80 PATH=$JAVA_HOME/bin:$PATH

 81 CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

 82 export JAVA_HOME

 83 export PATH

     84 export CLASSPATH

4. 执行source /etc/profile命令让修改生效。

 

5.查看安装结果

 

 

 

至此,安装jdk成功

  1. 9.       安装Tomcat

1.下载安装包,千万选好安装源,由于安装包的问题,硬是让我调试了一天,真是傻逼,从新官网下载安装以后立马能够用了

http://tomcat.apache.org/download-70.cgi

2.解压到/usr/local 下,并重命名为tomcat

#tar zxvf apache-tomcat-7.0.35.tar.gz /解压

#mv apache-tomcat-7.0.35 apache-tomcat /改名

#cd /apache-tomcat/bin/ /打开此目录

#chmod 777 *.sh /777权限

#bash catalina.sh start /启动

相关文章
相关标签/搜索