OracleOCP认证 之 Linux基础

 

  Linux 基础

一、SHELL



1: Shell 简介

shell 是用户和Linux 操作系统之间的接口。Linux 中有多种shell, 其中缺省使用的是bash。
Linux 系统的shell 作为操作系统的外壳为用户提供使用操作系统的接口,它是一个命令语言解释器,拥有自己内建的shell 命令集。shell 也能被系统中其他应用程序所调用,用户在提示符下输入的命令都由shell 先解释然后传给Linux 核心。
Linux 中的shell 有多种类型,其中最常用的几种是Bourne shell(sh),C shell(csh) 和Korn shell(ksh)。
Redhat Linux 系统默认的shell 是bash,对普通用户用$作提示符,对超级用户root 用#作提示符,一旦出现了shell 提示符就可以键入命令名称及命令所需要的参数。

image

在系统中,人所输入到系统内部的命令,以字符类型的形式输入到系统当中,然而系统 只识别 2 进制码,就如以前 doc 界面为例,输入的都是字符类的英文字母作为输入的命令代 码,然而明显二进制码与我们平常所输入的命令式不一样的,就像语言不通的两个人,需要 进行翻译。

      1:基本上 shell 分两大类:

         1) 图形界面 shell(Graphical User Interface shell 即 GUI shell)

     例如: 应用最为广泛的 Windows Explorer (微软的 windows 系列制作系统),还有也包括广 为人知的 Linux shell,其中 linux shell 包括 X window manger (BlackBox 和 FluxBox),以及 功能更强大的 CDE、GNOME、KDE、 XFCE。

         2) 命令行式 shell(Command Line Interface shell ,即 CLI shell)

     例如: 

  •     bash / sh / ksh / csh(Unix/linux 系统)
  •     cmd.exe/ 命令提示字符(Windows NT 系统)
  •     Windows PowerShell(支援 .NET Framework 技术的 Windows NT 系统)
  •     传统意义上的 shell 指的是命令行式的 shell,以后如果不特别注明,shell 是指命令行式 的 shell。




2:Shell 控制台使用方法

       首先介绍一个名词“控制台console ”,它就是我们通常见到的使用字符操作界面的人机接口。例如dos。我们说控制台命令就是指通过字符界面输入的可以操作系统的命令。例如dos 命令就是控制台命令。我们现在要了解的是基于Linux 操作系统的基本控制台命令。
        Linux 是一个真正的多用户操作系统,这表示它可以同时接受多个用户登录。Linux 还允许一个用户进行多次登录,这是因为Linux和许多版本的UNIX 一样提供了“虚拟控制台”的访问方式,允许用户在同一时间从控制台(系统的控制台是与系统直接相连的监视器和键盘)进行多次登录。
虚拟控制台的选择可以通过按下 Alt 键和一个功能键来实现,通常使用F1-F6。例如用户登录后按一下Alt-F2 键,用户又可以看到"login:"提示符,说明用户看到了第二个虚拟控制台,然后只需按Alt-F1 键就可以回到第一个虚拟控制台。一个新安装的Linux 系统允许用户使用Alt-F1 到Alt-F6 键来访问前六个虚拟控制台



二:常用命令使用


1:登录和退出 Linux 系统

     用户登录系统时,为了使系统能够识别自己,必须输入用户名和密码,经系统验证无误后方能进入系统。

image

       1: 启动和登录系统

image

image

image

       2: 重启系统

image

       3:关闭系统

image

image

       4:关机示例

image








三、Linux 文件与目录管理

   (一)、目录树

在 Linux 底下,所有的文件与目录都是由根目录开始的。根目录是所有目录与文件的源头,再一个一个的分支下来,有点像是树枝状。因此,我们也称这种目录配置方式为:『目录树(directory tree)』。

  他主要的特性有:

  •   目录树的启始点为根目录 (/, root);
  • 每一个目录不止能使用本地端的 partition 的文件系统,也可以使用网络上的 filesystem 。(NFS)

如果我们将整个目录树以图标的方法来显示,并且将较为重要的文件数据列出来的话,那么目录树架构有点像这样:

image


      


(二)、绝对路径与相对路径

           除了需要特别注意的 FHS 目录配置外,在文件名部分我们也要特别注意喔!因为根据档名写法的不同,也可将所谓的路径(path)定义为绝对路径(absolute)与相对路径(relative)。

1. 绝对路径

大家都知道,在我们平时使用计算机时要找到需要的文件就必须知道文件的位置,而表示文件的位置的方式就是路径。绝对路径就是文件或目录在硬盘上真正的路径。 绝对路径名称表示的文件在文件系统里面唯一的名称。

例如,只要看到这个路径:"D:ORACLEOCP.doc"我们就知道"OCP.doc"文件是在 D 盘的"ORACLE"目录中。类似于这样完整的描述文件位置的路径就是绝对路径。在 linux 里面一样,/study/oracle/ocp/test.txt 通过这个目录呢我们就可以知道 test.txt 在根目录(/)下的 study 子目录下的 oracle 目录。我们可以用 cd /study/oracle/ocp 通过这个绝对路径的方式去查看到这个文件。

2. 相对路径

     相对路径是一个相对性的对于绝对路径来说的。绝对路径其实可以这么理解,既然我们在目录下,我要去到本目录下的其他子目录可以直达其他子目录的名字,而不需要经过本目录的再回到你想要的目录里面。比如说:我现在在/opt 下。然后/opt 下有个 oracle 目录,也就是说我现在的绝对目录是在/opt/oracle 下。然而,在/opt 下也有一个 ocp 目录就是说 ocp 绝对路径是/opt/ocp。那么我现在已经在/etc 目录下了。然而我们就可以同 cd ocp 去到同在/etc 下的 ocp 而不需要打入常常的一条/etc/ocp 的绝对路径去进入了。


image

(三)、Linux 目录结构

  1. FHS

    因为利用 Linux 来开发产品或 distributions 的社群/公司与个人实在太多了, 如果每个人都用自己的想法来配置文件放置的目录,那么将可能造成很多管理上的困扰。

    因此制订了 Filesystem Hierarchy Standard (FHS)文件系统层次标准。

    根据 FHS(http://www.pathname.com/fhs/)的官方文件指出, 他们的主要目的是希望让使用者可以了解到已安装软件通常放置于那个目录下, 所以他们希望独立的软件开发商、操作系统制作者、以及想要维护系统的用户,都能够遵循 FHS 的标准。 也就是说,FHS 的重点在于规范每个特定的目录下应该要放置什么样子的数据而已。 这样做好处非常多,因为 Linux 操作系统就能够在既有的面貌下(目录架构不变)发展出开发者想要的独特风格。

    事实上,FHS 是根据过去的经验一直再持续的改版的,FHS 依据文件系统使用的频繁与否与是否允许使用者随意更动, 而将目录定义成为四种交互作用的形态,用表格来说有点像底下这样:

image

      可分享的:可以分享给其他系统挂载使用的目录,所以包括执行文件与用户的邮件等数据,是能够分享给网络上其他主机挂载用的目录;

     不可分享的:自己机器上面运作的装置文件或者是与程序有关的 socket 文件等, 由于仅与自身机器有关,所以当然就不适合分享给其他主机了。

     不变的:有些数据是不会经常变动的,跟随着 distribution 而不变动。 例如函式库、文件说明文件、系统管理员所管理的主机服务配置文件等等;

     可变动的:经常改变的数据,例如登录文件、一般用户可自行收受的新闻组等。事实上,FHS 针对目录树架构仅定义出三层目录底下应该放置什么数据而已,

        分别是底下这三个目录的定义:

  • / (root, 根目录):与开机系统有关;
  • /usr (unix software resource):与软件安装/执行有关;
  • /var (variable):与系统运作过程有关。

2. Linux 重要的目录


image

image

3. Linux 中比较特殊的目录

  在 Linux 当中也是非常重要的目录:

image

image

4. 两个非常重要的目录 

1) /usr 的意义与内容:

        很多读者都会误会/usr 为 user 的缩写,其实 usr 是 Unix Software Resource 的缩写, 也就是『Unix 操作系统软件资源』所放置的目录,而不是用户的数据啦!这点要注意。 FHS 建议所有软件开发者,应该将他们的数据合理的分别放置到这个目录下的次目录,而不要自行建立该软件自己独立的目录。

      因为是所有系统默认的软件(distribution 发布者提供的软件)都会放置到/usr 底下,因此这个目录有点类似 Windows 系统的『C:Windows + C:Program files』这两个目录的综合体,系统刚安装完毕时,这个目录会占用最多的硬盘容量。 一般来说,/usr 的次目录建议有底下这些:

image


2) /var 的意义与内容:

   如果/usr 是安装时会占用较大硬盘容量的目录,那么/var 就是在系统运作后才会渐渐占用硬盘容量的目录。

    因为/var 目录主要针对常态性变动的文件,包括缓存(cache)、登录档(log file)以及某些软件运作所产生的文件,

    包括程序文件(lock file, run file),或者例如 MySQL 数据库的文件等等。常见的次目录有:

image

 

四:有关目录的命令

1. 查看帮助  man cd

  1 [root@oracle ~]# man cd //查看 cd 指令的帮助文档

 

2. 显示当前工作目录   pwd

  1 [root@oracle ~]# pwd
  2 /root

3. 列出当前目录下的内容:ls

  1 [root@oracle ~]# ls [-aAdfFhilnrRSt] 目录名称
  2 [root@oracle ~]# ls [--color={never,auto,always}] 目录名称
  3 [root@oracle ~]# ls [--full-time] 目录名称
  4 选项与参数:
  5 -a :全部的文件,连同隐藏档( 开头为 . 的文件) 一起列出来(常用)
  6 -A :全部的文件,连同隐藏档,但不包括 . 与 .. 这两个目录
  7 -d :仅列出目录本身,而不是列出目录内的文件数据(常用)
  8 -l :长数据串列出,包含文件的属性与权限等等数据;(常用)(ll)
  9 -n :列出 UID 与 GID 而非使用者与群组的名称 (UID 与 GID 会在帐号管理提到!)
 10 -r :将排序结果反向输出,例如:原本档名由小到大,反向则为由大到小;
 11 -R :连同子目录内容一起列出来,等於该目录下的所有文件都会显示出来;
 12 -S :以文件容量大小排序,而不是用档名排序;
 13 -t :依时间排序,而不是用档名。
 14 --color=never :不要依据文件特性给予颜色显示;
 15 --color=always :显示颜色
 16 --color=auto :让系统自行依据配置来判断是否给予颜色
 17 --full-time :以完整时间模式 (包含年、月、日、时、分) 输出

4. 切换目录 cd

  1 [root@oracle ~]# cd / //切换到根目录

5. 创建目录 mkdir

  1 [root@oracle ~]# mkdir oracle //在当前目录下创建 oracle 目录
  2 选项与参数:
  3 -m :对新建目录设置存取权限,也可以用 chmod 命令设置
  4 -p :可以是一个路径名称。此时若路径中的某些目录尚不存在,加上此选项后,系统将
  5 自动建立好那些尚不存在的目录,即一次可以建立多个目录(级联创建)
  6 [root@oracle ~]# mkdir -p study/oracle/OC{A,P,M}
  7 //在当前目录下创建 study 目录,在 study 目录下创建 oracle 目录,oracle 目录下创建
  8 OCA、OCP、OCM 目录


6. 删除目录 rmdir

  1 [root@oracle ~]# rmdir oracle //删除 oracle 目录

7. 创建文件 touch

  1 [root@oracle ~]# touch oracle //创建名为 oracle 的文件

8. 删除文件/目录 rm

  1 [root@oracle ~]# rm oracle //删除名为 oracle 的文件
  2 选项与参数:
  3 -i :删除前逐一询问确认。
  4 -f :即使原档案属性设为唯读,亦直接删除,无需逐一确认。
  5 -r :将目录及以下之档案亦逐一删除。
  6 [root@oracle ~]# rm *.log //删除所有以“.log”结尾的文件
  7 [root@oracle ~]# rm -rf oracle/ //删除 oracle 目录并级联删除 oracle 目录内的档案

9. 移动文件/目录  mv

  1 [root@oracle ~]# mv oracle /opt //将档案 oracle 移动至目录/opt 下

10. 拷贝文件/目录  cp

  1 [root@oracle ~]# cp [-adfilprsu] 来源档(source) 目标档(destination)
  2 [root@oracle ~]# cp [options] source1 source2 source3 .... directory
  3 选项与参数:
  4 -a :相当於 -pdr 的意思,至於 pdr 请参考下列说明;(常用)
  5 -d :若来源档为连结档的属性(link file),则复制连结档属性而非文件本身;
  6 -i :若目标档(destination)已经存在时,在覆盖时会先询问动作的进行(常用)
  7 -p :连同文件的属性一起复制过去,而非使用默认属性(备份常用);
  8 -r :递回持续复制,用於目录的复制行为;(常用)
  9 最后需要注意的,如果来源档有两个以上,则最后一个目的档一定要是『目录』才行!

11. 打开文件  more   less  tail  cat

  1 [root@oracle ~]# more oracle.log
  2 [root@oracle ~]# less oracle.log
  3 [root@oracle ~]# tail -20f oracle.log //文件尾部输出
  4 [root@oracle ~]# cat oracle.log

五、用户和组


(一)、用户

image

         1. UID 和 GID

      Linux 是通过 UID(USER ID)和 GID(GROUP ID)来识别用户的。账号只是为了方便用户记忆。而 ID 与账号的对应就在 /etc/passwd 当中。登录 Linux 时,Linux 都干了些啥?

           1) 先找寻 /etc/passwd 里面是否有这个账号?如果没有则跳出,如果有的话则将该账号对应的 UID ( User ID )与 GID ( Group ID )读出来,另外,该账号的家目录与 shell 设定也一并读出;

           2) 再来则是核对密码表啦!这时 Linux 会进入 /etc/shadow 里面找出对应的账号与 UID,然后核对一下你刚刚输入的密码与里头的密码是否相符? 3) 如果一切都 OK 的话,就进入 Shell 控管的阶段啰!        

         2. /etc/passwd和/etc/shadow

                  1) 用户账号信息文件  /etc/passwd

                这个档案的构造是这样的:每一行都代表一个账号, 有几行就代表有几个账号在你的系统中!

               不过需要特别留意的是, 里头很多账号本来就是系统中必须要的,我们可以简称他为系统账号, 例如 bin, daemon, adm, nobody 等等,这些账号是系统正常运作时所需要的。


  1 root:x:0:0:root:/root:/bin/bash
  2 bin:x:1:1:bin:/bin:/sbin/nologin
  3 daemon:x:2:2:daemon:/sbin:/sbin/nologin
  4 adm:x:3:4:adm:/var/adm:/sbin/nologin

image

                   image

image

改变用户ID 的实验:

  1 root@linux ~]# vi /etc/passwd
  2 .....(前面省略).....
  3 dmtsai:x:501:501::/home/dmtsai:/bin/bash <==将原本的501:501 改成3000:501
  4 [root@linux ~]# ls -ld /home/
  5 drwxr-xr-x 3 501 dmtsai 4096 Aug 30 10:37 dmtsai
  6 # 瞧!这里就能够知道,其实档案记录的是UID 啦~

                  2) 用户口令信息文件  /etc/shadow


               上面约略提到,由于每个程序都需要取得uid 与gid 来判断权限的问题,所以, /etc/passwd 的权限必须要设定成为只读的权限。在这样的情况下,即使这个档案内的密码 栏是加密的,坏心肠的朋友也可能利用暴力破解法去找出您的密码数据...... 因为这样的 关系,所以后来发展出将密码移动到/etc/shadow 这个档案分隔开来的技术。

  1 root:$1$i9Ejldjfjio389u9sjl$jljsoi45QE/:12959:0:99999:7:::
  2 bin:*:12959:0:99999:7:::
  3 daemon:*:12959:0:99999:7:::
  4 adm:*:12959:0:99999:7:::

              基本上, shadow 同样以『:』作为分隔符,共有九个字段。   

imageimage

image

image


 

(二)、组


          1. /etc/group和/etc/gshadow

image

也是以冒号『:』作为字段的分隔符,共分为四栏,每一字段的意义是:

image

比较重要的特色在于第四栏啦,因为每个使用者都可以拥有多个支持的群组, 这就好 比在学校念书的时候,我们可以加入多个社团一样! ^_^。不过这里您或许会觉得奇怪的, 那就是:『假如我同时加入多个群组, 那么我在作业的时候,到底是以那个群组为准?』底 下我们就来谈一谈这个『有效群组』的概念。

         2. 有效群组(effective group)与初始群组(initial group)


还记得每个使用者在他的/etc/passwd 里面的第四栏有所谓的GID 吧?那个GID 就 是所谓的『初始群组( initial group ) 』了!也就是说,当使用者一登入系统,立刻就 拥有这个群组的相关权限的意思。举例来说,我们上面提到dmtsai 这个使用者的 /etc/passwd 与/etc/group 还有/etc/gshadow 相关的内容如下:

image

             仔细看到上面这个表格,在/etc/passwd 里面,dmtsai 这个使用者所属的群组为 GID=501 , 也就是/etc/group 里头dmtsai 那个群组啦~因为这是initial group ,所 以, 使用者一登入就会主动取得,不需要在/etc/group 的第四个字段写入该账号的! 但 是非initial group 的其它群组可就不同了。
            举上面这个例子来说,我将dmtsai 加入users 这个群组当中,由于users 这个群组 并非是dmtsai 的初始群组,因此, 我必须要在/etc/group 这个档案中,找到users 那 一行,并且将dmtsai 这个账号加入第四栏,这样dmtsai 才能够支持users 这个群组啊。 那么在这个例子当中,因为我的dmtsai 这个账号同时支持dmtsai 与users 这两个群组, 因此,在读取/写入/执行档案时,针对群组部分,只要是users 与dmtsai 这两个群组拥 有的功能, 我dmtsai 这个使用者都能够拥有喔!这样瞭呼?不过,这是针对已经存在的 档案而言, 如果今天我要建立一个新的档案或者是新的目录,请问一下,新档案的群组是 dmtsai 还是users ? 呵呵!这就得要检查一下当时的有效群组了(effective group)。
如果我以dmtsai 这个使用者的身份登入后,该如何知道我所有支持的群组呢? 很简单啊, 直接输入groups 就可以了!

  1 实验:
  2 [root@oracle etc]# groupadd test
  3 [root@oracle etc]# groupadd test1
  4 [root@oracle etc]# useradd test -g test -G test1
  5 [root@oracle etc]# grep test /etc/passwd /etc/group /etc/gshadow
  6 [root@oracle etc]# su - test
  7 [test@oracle ~]$ groups
  8 test test1



(三)、有关用户和组的指令


          1. 添加用户useradd

image

         2. 修改用户usermod

image


         3. 修改密码passwd

image

       先来谈一谈上面的两个范例。要注意的是, passwd 这个指令由于使用者的身份而有两 种用法, 如果是root ,由于root 具有至高无上的权力,所以root 可以利用passwd [username] 来帮使用者修改他们的密码!因此,『如果使用者的密码不见了, root 是可以 帮他们进行密码的修改,而不需要知道旧密码。』 另外,也只有root 可以随便设定密码,即使该密码并不符合系统的密码验证要求~ 假 如我帮dmtsai 建立的密码太简单,所以其实系统是『警告』过root 的。但在重复输入 两次密码后,嘿嘿!您还是会看到successfully 这个成功的字样呢! 那么如果是一般身 份使用者,或者是root 想要修改自己的密码时,直接输入『passwd 』, 就能够修改自己 的密码了。一般身份使用者输入的密码会经过系统的验证, 验证的机制除了 /etc/login.defs 里头规定的最小密码字符数之外,还会受到/etc/pam.d/passwd 这个 PAM 模块的检验呢!一般来说,您输入的密码最好要符合底下的要求:

  • 密码不能与账号相同;
  • 密码尽量不要选用字典里面会出现的字符串
  • 密码需要超过8 个字符;


     如果无法经过验证,那么该密码就不被接受,当然还是只能使用旧密码啰! 此外,仅 能接受三次密码输入,如果输入的密码都不被接受,那只好....重新执行一次passwd 啊! 而, 经过这个passwd [username] 的动作后,您的账号就会有密码啰,此时, 如果察看 一下/etc/shadow ,你就会知道密码内容被改过啰~ ^_^


  1 实验:
  2 [root@oracle etc]# passwd test
  3 Changing password for user test.
  4 New UNIX password:
  5 BAD PASSWORD: it is too short
  6 Retype new UNIX password:
  7 passwd: all authentication tokens updated successfully.
  8 [test@oracle ~]$ passwd
  9 Changing password for user test.
 10 Changing password for test
 11 (current) UNIX password:
 12 New UNIX password:
 13 BAD PASSWORD: it is based on a dictionary word
 14 New UNIX password:
 15 BAD PASSWORD: it is based on a dictionary word
 16 New UNIX password:

         4. 删除用户Userdel

image


               这个指令下达的时候要小心了!通常我们要移除一个账号的时候,你可以手动的将 /etc/passwd 与/etc/shadow 里头的该账号取消即可!一般而言,如果该账号只是『暂时 不启用』的话,那么将/etc/shadow 里头最后倒数一个字段设定为0 就可以让该账号无法 使用,但是所有跟该账号相关的数据都会留下来! 使用userdel 的时机通常是『你真的 确定不要让该用户在主机上面使用任何数据了!』另外,其实使用者如果在系统上面操作过 一阵子了,那么该使用者其实在系统内可能会含有其它档案的。

         5. 显示用户所属的组groups

image

         6. 创建组groupadd

image

         7. 修改组groupmod


image

         8. 删除组groupdel

image

         9. 显示用户信息id

image




六、权限


(一)、三种用户

    • 档案所属用户user u
    • 档案所属组group g
    • 其他人other o

    •      用户组就是用户存在的组,一个用户可以存在一多个组里面,而且用户已生成之后,系 统默认给予他一个私有组。 组的话,就是可以说成一个公司的项目一样,我公司通过派遣一个组去进行一个项目的 操作,当然啦,项目里面有很多个项目人员进行对项目的一个处理。这个就等于我们的在用 户里面的组一样,各个用户可以通过拥有组的权限对项目进行一个管理,而且只有组里面的 人才可以对项目进行修改的。这样的组就作用了。方便我们去管理。
      其他人就是组与文件拥有者之外的用户。


(二)、三种基本权限

image

     读:r 写:w 可执行:x
目录只有可执行操作的话,只可以进入目录,而不可以对目录进行一个信息的查询,也就是 不能用ll 命令查看。 目录只有读的操作,就只可以ll 指定目录,对目录里面的东西进行查看,而不可以进入目 录。
实验:

  1 [root@oracle tmp]# chmod o=rw a
  2 [test@oracle tmp]$ cd a
  3 -bash: cd: a: Permission denied

只有读与可执行的操作才可以对目录进行cd 或者ll 的操作

image




(三)、有关权限的指令


          1. chmod


通过线索来理解
who : u g o
what: - + =
which: r w x
字符法修改:
chmod u+r dir
g+r
o+r
u-r
g-r
o-r
如此类推
数值法:
r=4
w=2
x=1
比如说一个文件里面的权限是rwxrwxr-x 那么它的权限数值就等于775(4+2+1=7 4+2+1=7
4+0+1=5)
如chmod 775 dir

          2. chown


chown 修改文档的拥有者。
如:语法:
chown username(用户名) dirfile 修改单个目录或文档的
chown -R username dir 对目录里面的东西可以进行一个递归的修改,也就是说该目录下的
文件的拥有者也一样修改成username
chown username:groupname dirfile 同时修改该目录或者改文档下的拥有者与拥有组。

          3. chgrp


chgrp :修改文档的拥有组。
语法:
chgrp groupname filedir

(四)、特殊权限


          1:特殊权限:


suid(setuid)强制位    -----》加在可执行文件上面
guid(setgid)强制位   -----》加在可执行文件上面
sticky(冒险位)           -----》加在目录上面

文件有读写执行权限以外,ext3 文件系统还支持强制位(setuid 和setgid)与冒险位(sticky) 的特别权限。针对u,g,o,分别有set uid,set gid,及sticky。 强制位与冒险位添加在执行权限的位置上。如果该位置上原已有执行权限。则强制位与冒险 位以小写字母的方式表示,否则,以大写字母表示。 set uid 与set gid 在u 和g 的x 位置上各采用一个s,sticky 使用一个t。

image

         2:Linux 强制位对文件的作用:


         在可执行文件上,用户可以添加set uid 和set gid。 默认情况下,用户执行一个指令,会以该用户的身份来运行进程。 指令文件上的强制位,可以让用户执行的指令,以指令文件的拥有者或所属组的身份运行进程。/bin/ping /usr/bin/passwd 默认情况下,用户建立的文件属于用户当前所在的组。 目录上设置了setgid,表示在此目录中,任何人建立的文件,都会属于目录所属的组。

实验:

  1 [root@oracle ~]# cd /usr/bin/
  2 [root@oracle bin]# ls -l passwd
  3 -r-s--x--x 1 root root 21200 Oct 7 2006 passwd
  4 [root@oracle bin]# chmod u-s passwd
  5 [test@oracle ~]$ passwd
  6 Changing password for user test.
  7 Changing password for test
  8 (current) UNIX password:
  9 passwd: Authentication token manipulation error


         3:Linux 冒险位对目录作用


默认情况下,如果一个目录上有w 和x 权限,则任何人可以在此目录中建立与删除文件。 一旦目录上设置了冒险位,则表示在此目录中,只有文件的拥有者、目录的拥有者与系统管 理员可以删除文件。

  1 实验:
  2 [root@oracle tmp]# chmod 1777 a
  3 [test@oracle a]$ touch b
  4 [test@oracle a]$ chmod 777 b
  5 [test@oracle a]$ rm -rf c
  6 rm: cannot remove `c': Operation not permitted
  7 
  8 [oracle@oracle a]$ touch c
  9 [oracle@oracle a]$ ll
 10 total 0
 11 -rw-rw-r-- 1 test test 0 Mar 7 23:30 b
 12 -rw-r--r-- 1 oracle oinstall 0 Mar 7 23:30 c
 13 [oracle@oracle a]$ vim b
 14 [oracle@oracle a]$ chmod 777 c
 15 [oracle@oracle a]$ vim b
 16 [oracle@oracle a]$ rm b
 17 rm: cannot remove `b': Operation not permitted


/tmp

          4:通过字符的方式添加到目录或文件里的权限方法:


通过加入suid
chmod u+s dir/file
加入sgid
chmod g+s dir/file
加入sticky
chmod o+t dir/file
强制位与冒险位的数值表示:
suid=4 sgid=2 sticky=1
通过数值的方式加入权限
如:我要把suid,就是4 加入到权限为775 的dir 里面
我可以通过
chmod 4775 dir(4 就是强制位suid)
如此类推:
chmod 2775 dir (就把2 的强制位guid 加入到dir 里面)
chmod 1775 dir (就把1 的冒险位sticky 加入大dir 里面)
组合加入的话一样与权限的775 一样,就是三个权限加起来的和,比如说我要对dir 加入强
制位suid 与冒险位sticky ,那么guid 就为0 了因为我不加入sgid。所以我要加入的数值是
5775 如此类推



七、VIM


1: vim工作模式

vim 可以执行输出、删除、查找、替换等文本操作,vim 不是一个排版程序,它不象 word 那样对字体、格式、段落等其它属性进行编排,它只是一个文本编辑程序。vim 没有菜单,只有命令,且命令繁多。

vim 有三种基本工作模式,命令模式、文本输入模式和末行模式。

2:vim 启动与退出

vim

vi filename

vi +n filename(将光标置于文件的第 n 行)

末行模式下:

--退出

:q 

--保存退出

:wq 

--保存退出

:x (:wq)

--强制退出。

:q!

--

Z

Z (:wq)

:n,m w filename

:w

:w filename

3:光标移动

使用键盘上的四个方向键移动光标,还可以使用 hjkl 这四个键

代替四个方向键移动光标

0(零)光标移动行首

$光标移动行尾

H 光标移动屏幕上显示的第一行(不是文件头)

L 光标移到屏幕上显示的最后一行(不是文件尾)

M 光标移到屏幕的中间一行

nG 光标移到第 n

n 光标移到文件的第 n

$光标移到文件的最后一行

0 光标移到第一行

gg 光标移到文件头

G 光标移到文件尾

n 回车 光标移动 n

ctrl+G 显示当前编辑文档的状态


4:文本插入

如果用户要将输入的字符当作文本内容,则首先将工作模式从命

令模式切换到输入模式。

I i A a O o

5:文本删除

  1 X 删除光标前面的那个字符
  2 
  3 x 删除光标处的字符
  4 
  5 
  6 dd 删除光标所在的整行
  7 
  8 ndd 删除当前行及其后 n-1 行
  9 
 10 D 或 d$删除从光标所在处开始到行尾的内容
 11 
 12 d0 删除从光标前一个字符开始到行首的内容
 13 
 14 dG 删除所有内容
 15 
 16 dgg	删除当前行的内容
 17 
 18 ndgg 删除当前行前及 n 行
 19 
 20 :d 删除当前行
 21 
 22 :nd 删除第 n 行
 23 
 24 :n, md 删除 n 至 m 行内容
 25 
 26 删除空行
 27 
 28 :g/^s*$/d
 29 
 30 删除行尾空格
 31 
 32 :%s/s*$//g
 33 
 34 删除行首空格
 35 
 36 :%s/^s+//g
 37 


6:文本复制

yy 复制光标所在的整行

nyy 复制当前行及其后 n-1

y$ 复制行的剩余部分

:n copy n

:n,m copy n


7:文本移动

:n move n

:n,m move n

8:文本粘贴

p P


9:文本撤销

u 把当前行恢复成被编辑前的状态,不管行被编辑多少次

U 只能取消前一步操作

10:重复

.再次执行一次前面刚完成的某个命令


11:文本保存

:w

:w file name

:w >>file

:n,m w >> file

:n,m w file

12:文本查找

/从光标当前所在位置向文件尾部搜索

? 从光标当前所在位置向文件头部搜索

n 搜索下一个匹配

N 搜索上一个匹配

如果用户在所要搜索的关键字包含特殊字符,需要用作为特殊

字符进行转译,以取消特殊字符的功能。如/man.


13:文本替换

:s/查找的内容/替换的内容 当前行的第一个单词

:s/查找的内容/替换的内容/g 对当前行全局替换

:n,ms/查找的内容/替换的内容

:n,ms/查找的内容/替换的内容/g

:1,$s/查找的内容/替换的内容/g

:%s/查找的内容/替换的内容/g

过滤条件:

:g/过滤条/s/查找的内容/替换的内容/g

14:读入文本

:n read file name


15:文本加密

:(大写)


16:块操作

vim 的命令模式下使用V键,可以激活以行为单位的块选择方

式,光标经过的地方,就是被选中的内容。用户还可以在 vim 的命令

行模式内激活以指定长方形或正方形的选择内容,使用 ctrl+v




0 这是数字『0 』:移动到这一行的最前面字符处
$ 移动到这一行的最后面字符处
G 移动到这个档案的最后一行
nG n 为数字。移动到这个档案的第n 行。例如20G 则会移动到这个档案的第
20 行(可配合:set nu)
gg 移动到这个档案的第一行,相当于1G 啊!
n<Enter> n 为数字。光标向下移动n 行
/word 向光标之下寻找一个字符串名称为word 的字符串。例如要在档案内搜寻
vbird 这个字符串,就输入/vbird 即可!
:n1,n2s/word1/word2/g
n1 与n2 为数字。在第n1 与n2 行之间寻找word1 这个字符串,并将该
字符串取代为word2 !举例来说,在100 到200 行之间搜寻vbird 并取代
为VBIRD 则: 『:100,200s/vbird/VBIRD/g』。
:1,$s/word1/word2/g
从第一行到最后一行寻找word1 字符串,并将该字符串取代为word2 !
:1,$s/word1/word2/gc
从第一行到最后一行寻找word1 字符串,并将该字符串取代为word2 !且
在取代前显示提示字符给使用者确认(conform) 是否需要取代!
x, X 在一行字当中,x 为向后删除一个字符(相当于[del] 按键), X 为向前删除
一个字符(相当于[backspace] 亦即是退格键)
dd 删除游标所在的那一整行
ndd n 为数字。删除光标所在的向下n 行,例如20dd 则是删除20 行
yy 复制游标所在的那一行
nyy n 为数字。复制光标所在的向下n 行,例如20yy 则是复制20 行
p, P p 为将已复制的数据在光标下一行贴上,P 则为贴在游标上一行!
举例来说,我目前光标在第20 行,且已经复制了10 行数据。
则按下p 后, 那10 行数据会贴在原本的20 行之后,亦即由21 行开
始贴。但如果是按下P 呢? 那么原本的第20 行会被推到变成30 行。
u 复原前一个动作。
[Ctrl]+r 重做上一个动作。
:w 将编辑的数据写入硬盘档案中(常用)
:w! 若档案属性为『只读』时,强制写入该档案。不过,到底能不能写入, 还是
跟您对该档案的档案权限有关啊!
:q 离开vi (常用)
:q! 若曾修改过档案,又不想储存,使用! 为强制离开不储存档案。
:wq 储存后离开,若为:wq! 则为强制储存后离开(常用)
:w [filename] 将编辑的数据储存成另一个档案(类似另存新档)
:set nu 显示行号,设定之后,会在每一行的前缀显示该行的行号
:set nonu 与set nu 相反,为取消行号!
i、a 插入
. 不要怀疑!这就是小数点!意思是重复前一个动作的意思。如果您想要重复
删除、重复贴上等等动作,按下小数点『.』就好了! (常用)



八:进程及任务管理命令

image



1:PS 命令

image

image

             示例1: 在控制台输入PS 命令

image


             示例2:在控制台输入 ps –ef

image


2: top 命令


image

image


3:kill 命令

image









九:磁盘及文件系统管理命令

image

1:显示 磁盘剩余空间 df

image

image



2: 挂在磁盘 mount     卸载磁盘  umount 命令

image

image

3:查看文件和文件夹大小 du

image


4: 查看当前磁盘分区情况  fdisk

image

image

5: 手动添加 swap 分区


image


6:查看磁盘挂载情况 df 命令

image

image


7:挂载磁盘并分区操作步骤

        1: 用 vm 虚拟机创建1个新的磁盘

image

image

image

image

image

image

image

image

        2:查看新增加的磁盘情况

先查看磁盘信息情况:

  1 [root@localhost ~]# fdisk -l
  2 
  3 Disk /dev/sda: 107.3 GB, 107374182400 bytes
  4 255 heads, 63 sectors/track, 13054 cylinders
  5 Units = cylinders of 16065 * 512 = 8225280 bytes
  6 
  7    Device Boot      Start         End      Blocks   Id  System
  8 /dev/sda1   *           1         517     4152771   83  Linux
  9 /dev/sda2             518       13054   100703452+  8e  Linux LVM
 10 [root@localhost ~]# 
 11 

   从上述信息来看,刚新增的磁盘并没有加载进系统。

   对于新增加的磁盘 想要显示从来 有2个操作情况:

  1. 就是重启系统                      reboot           
  2. 就是 实现手动挂载磁盘      [root@localhost ~]# echo "- - -"> /sys/class/scsi_host/host0/scan          
  1 [root@localhost ~]# echo "- - -"> /sys/class/scsi_host/host0/scan 
  2 [root@localhost ~]# fdisk -l
  3 
  4 Disk /dev/sda: 107.3 GB, 107374182400 bytes
  5 255 heads, 63 sectors/track, 13054 cylinders
  6 Units = cylinders of 16065 * 512 = 8225280 bytes
  7 
  8    Device Boot      Start         End      Blocks   Id  System
  9 /dev/sda1   *           1         517     4152771   83  Linux
 10 /dev/sda2             518       13054   100703452+  8e  Linux LVM
 11 
 12 Disk /dev/sdb: 214.7 GB, 214748364800 bytes
 13 255 heads, 63 sectors/track, 26108 cylinders
 14 Units = cylinders of 16065 * 512 = 8225280 bytes
 15 #表示已经在线识别了新增加的磁盘信息
 16 Disk /dev/sdb doesn't contain a valid partition table
 17 [root@localhost ~]# 


        3:对新增加的磁盘2 进行磁盘分区

一个磁盘在linux系统下最多可以分4个主分区(3个系统主分区+一个逻辑主分区)。逻辑分区可以分很多磁盘分区。

  1 
  2 # 把新增加的磁盘写入系统文件中。启动自动加载的意义
  3 [root@localhost ~]# echo "- - -"> /sys/class/scsi_host/host0/scan 
  4 #查看 文件列表 
  5 [root@localhost ~]# fdisk -l
  6 Disk /dev/sda: 107.3 GB, 107374182400 bytes
  7 255 heads, 63 sectors/track, 13054 cylinders
  8 Units = cylinders of 16065 * 512 = 8225280 bytes
  9 
 10    Device Boot      Start         End      Blocks   Id  System
 11 /dev/sda1   *           1         517     4152771   83  Linux
 12 /dev/sda2             518       13054   100703452+  8e  Linux LVM
 13 
 14 Disk /dev/sdb: 214.7 GB, 214748364800 bytes
 15 255 heads, 63 sectors/track, 26108 cylinders
 16 Units = cylinders of 16065 * 512 = 8225280 bytes
 17 #显示出:新增加的磁盘信息
 18 Disk /dev/sdb doesn't contain a valid partition table
 19 #对新增加的磁盘进行磁盘分区
 20 [root@localhost ~]# fdisk /dev/sdb
 21 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
 22 Building a new DOS disklabel. Changes will remain in memory only,
 23 until you decide to write them. After that, of course, the previous
 24 content won't be recoverable.
 25 
 26 
 27 The number of cylinders for this disk is set to 26108.
 28 There is nothing wrong with that, but this is larger than 1024,
 29 and could in certain setups cause problems with:
 30 1) software that runs at boot time (e.g., old versions of LILO)
 31 2) booting and partitioning software from other OSs
 32    (e.g., DOS FDISK, OS/2 FDISK)
 33 Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 34 #查看磁盘分区命令
 35 Command (m for help): m
 36 Command action
 37    #调整硬盘的启动分区
 38    a   toggle a bootable flag
 39 
 40    b   edit bsd disklabel
 41    c   toggle the dos compatibility flag
 42    #删除磁盘分区
 43    d   delete a partition
 44    #列出所有支持的分区类型
 45    l   list known partition types
 46    # 列出所有命令
 47    m   print this menu
 48    #创建一个新的分区
 49    n   add a new partition
 50    o   create a new empty DOS partition table
 51    #列出硬盘分区表
 52    p   print the partition table
 53    #  退出fdisk,不保存更改
 54    q   quit without saving changes
 55    s   create a new empty Sun disklabel
 56    #更改分区类型
 57    t   change a partition's system id
 58    #切换所显示的分区大小的单位
 59    u   change display/entry units
 60    v   verify the partition table
 61    # 把设置写入硬盘分区表,然后退出
 62    w   write table to disk and exit
 63    x   extra functionality (experts only)
 64 
 65 #查看磁盘分区
 66 Command (m for help): p
 67 
 68 Disk /dev/sdb: 214.7 GB, 214748364800 bytes
 69 255 heads, 63 sectors/track, 26108 cylinders
 70 Units = cylinders of 16065 * 512 = 8225280 bytes
 71 
 72    Device Boot      Start         End      Blocks   Id  System
 73 #创建磁盘分区
 74 Command (m for help): n
 75 Command action
 76    e   extended
 77    p   primary partition (1-4)
 78 p
 79 #创建分区1 
 80 Partition number (1-4): 1
 81 First cylinder (1-26108, default 1): 50G
 82 Last cylinder or +size or +sizeM or +sizeK (50-26108, default 26108): +50G
 83 #查看磁盘主分区 1
 84 Command (m for help): p
 85 
 86 Disk /dev/sdb: 214.7 GB, 214748364800 bytes
 87 255 heads, 63 sectors/track, 26108 cylinders
 88 Units = cylinders of 16065 * 512 = 8225280 bytes
 89 
 90    Device Boot      Start         End      Blocks   Id  System
 91 /dev/sdb1              50        6129    48837600   83  Linux
 92 
 93 
 94  #创建磁盘主分区 2
 95 
 96 Command (m for help): n
 97 Command action
 98    e   extended
 99    p   primary partition (1-4)
100 e
101 Partition number (1-4):
102 Value out of range.
103 Partition number (1-4): 2
104 First cylinder (1-26108, default 1): 26108
105 
106 Command (m for help): p
107 
108 Disk /dev/sdb: 214.7 GB, 214748364800 bytes
109 255 heads, 63 sectors/track, 26108 cylinders
110 Units = cylinders of 16065 * 512 = 8225280 bytes
111 
112    Device Boot      Start         End      Blocks   Id  System
113 /dev/sdb1            6108        6108        8032+  83  Linux
114 /dev/sdb2           26108       26108        8032+   5  Extended
115 #删除磁盘分区2 
116 Command (m for help): d 2
117 Partition number (1-5): 2
118 
119 Command (m for help): p
120 
121 Disk /dev/sdb: 214.7 GB, 214748364800 bytes
122 255 heads, 63 sectors/track, 26108 cylinders
123 Units = cylinders of 16065 * 512 = 8225280 bytes
124 
125    Device Boot      Start         End      Blocks   Id  System
126 /dev/sdb1            6108        6108        8032+  83  Linux
127 #创建磁盘扩展分区4
128 
129 Command (m for help): p
130 
131 Disk /dev/sdb: 214.7 GB, 214748364800 bytes
132 255 heads, 63 sectors/track, 26108 cylinders
133 Units = cylinders of 16065 * 512 = 8225280 bytes
134 
135    Device Boot      Start         End      Blocks   Id  System
136 /dev/sdb1            6108        6108        8032+  83  Linux
137 
138 Command (m for help): n
139 Command action
140    e   extended
141    p   primary partition (1-4)
142 e
143 Partition number (1-4): 4
144 First cylinder (1-26108, default 1):
145 Using default value 1
146 Last cylinder or +size or +sizeM or +sizeK (1-6107, default 6107):
147 Using default value 6107
148 #查看磁盘分区
149 Command (m for help): p
150 
151 Disk /dev/sdb: 214.7 GB, 214748364800 bytes
152 255 heads, 63 sectors/track, 26108 cylinders
153 Units = cylinders of 16065 * 512 = 8225280 bytes
154 
155    Device Boot      Start         End      Blocks   Id  System
156 /dev/sdb1            6108        6108        8032+  83  Linux
157 /dev/sdb4               1        6107    49054446    5  Extended
158 
159 Partition table entries are not in disk order
160 #创建磁盘逻辑分区5
161 Command (m for help): n
162 Command action
163    l   logical (5 or over)
164    p   primary partition (1-4)
165 l
166 First cylinder (1-6107, default 1): 1
167 Last cylinder or +size or +sizeM or +sizeK (1-6107, default 6107): 1024
168 #查看磁盘分区
169 Command (m for help): p
170 
171 Disk /dev/sdb: 214.7 GB, 214748364800 bytes
172 255 heads, 63 sectors/track, 26108 cylinders
173 Units = cylinders of 16065 * 512 = 8225280 bytes
174 
175    Device Boot      Start         End      Blocks   Id  System
176 /dev/sdb1            6108        6108        8032+  83  Linux
177 /dev/sdb4               1        6107    49054446    5  Extended
178 /dev/sdb5               1        1024     8225217   83  Linux
179 
180 Partition table entries are not in disk order
181 #创建磁盘逻辑分区6
182 Command (m for help): n
183 Command action
184    l   logical (5 or over)
185    p   primary partition (1-4)
186 l
187 First cylinder (1025-6107, default 1025):
188 Using default value 1025
189 Last cylinder or +size or +sizeM or +sizeK (1025-6107, default 6107):
190 Using default value 6107
191 #查看磁盘分区
192 Command (m for help): p
193 
194 Disk /dev/sdb: 214.7 GB, 214748364800 bytes
195 255 heads, 63 sectors/track, 26108 cylinders
196 Units = cylinders of 16065 * 512 = 8225280 bytes
197 
198    Device Boot      Start         End      Blocks   Id  System
199 /dev/sdb1            6108        6108        8032+  83  Linux
200 /dev/sdb4               1        6107    49054446    5  Extended
201 /dev/sdb5               1        1024     8225217   83  Linux
202 /dev/sdb6            1025        6107    40829166   83  Linux
203 
204 Partition table entries are not in disk order
205 #  列出所有支持的分区类型
206 Command (m for help): l
207 
208  0  Empty           1e  Hidden W95 FAT1 80  Old Minix       bf  Solaris
209  1  FAT12           24  NEC DOS         81  Minix / old Lin c1  DRDOS/sec (FAT-
210  2  XENIX root      39  Plan 9          82  Linux swap / So c4  DRDOS/sec (FAT-
211  3  XENIX usr       3c  PartitionMagic  83  Linux           c6  DRDOS/sec (FAT-
212  4  FAT16 <32M      40  Venix 80286     84  OS/2 hidden C:  c7  Syrinx
213  5  Extended        41  PPC PReP Boot   85  Linux extended  da  Non-FS data
214  6  FAT16           42  SFS             86  NTFS volume set db  CP/M / CTOS / .
215  7  HPFS/NTFS       4d  QNX4.x          87  NTFS volume set de  Dell Utility
216  8  AIX             4e  QNX4.x 2nd part 88  Linux plaintext df  BootIt
217  9  AIX bootable    4f  QNX4.x 3rd part 8e  Linux LVM       e1  DOS access
218  a  OS/2 Boot Manag 50  OnTrack DM      93  Amoeba          e3  DOS R/O
219  b  W95 FAT32       51  OnTrack DM6 Aux 94  Amoeba BBT      e4  SpeedStor
220  c  W95 FAT32 (LBA) 52  CP/M            9f  BSD/OS          eb  BeOS fs
221  e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi ee  EFI GPT
222  f  W95 Ext'd (LBA) 54  OnTrackDM6      a5  FreeBSD         ef  EFI (FAT-12/16/
223 10  OPUS            55  EZ-Drive        a6  OpenBSD         f0  Linux/PA-RISC b
224 11  Hidden FAT12    56  Golden Bow      a7  NeXTSTEP        f1  SpeedStor
225 12  Compaq diagnost 5c  Priam Edisk     a8  Darwin UFS      f4  SpeedStor
226 14  Hidden FAT16 <3 61  SpeedStor       a9  NetBSD          f2  DOS secondary
227 16  Hidden FAT16    63  GNU HURD or Sys ab  Darwin boot     fb  VMware VMFS
228 17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
229 18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
230 1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep
231 1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT
232 #更改分区类型  把 6 分区的linux 分区改为  Linux swap / Solaris 分区
233 Command (m for help): t
234 Partition number (1-6): 6
235 Hex code (type L to list codes): 82
236 Changed system type of partition 6 to 82 (Linux swap / Solaris)
237 
238 Command (m for help): p
239 
240 Disk /dev/sdb: 214.7 GB, 214748364800 bytes
241 255 heads, 63 sectors/track, 26108 cylinders
242 Units = cylinders of 16065 * 512 = 8225280 bytes
243 
244    Device Boot      Start         End      Blocks   Id  System
245 /dev/sdb1            6108        6108        8032+  83  Linux
246 /dev/sdb4               1        6107    49054446    5  Extended
247 /dev/sdb5               1        1024     8225217   83  Linux
248 /dev/sdb6            1025        6107    40829166   82  Linux swap / Solaris
249 
250 Partition table entries are not in disk order
251 #保存分区结果
252 Command (m for help): w
253 The partition table has been altered!
254 
255 Calling ioctl() to re-read partition table.
256 Syncing disks.
257 [root@localhost ~]# 


        4:磁盘格式化


  1 #主分区(linux分区)磁盘格式化: 
  2 [root@localhost ~]# mkfs.ext3 /dev/sdb1
  3 mke2fs 1.39 (29-May-2006)
  4 Filesystem label=
  5 OS type: Linux
  6 Block size=1024 (log=0)
  7 Fragment size=1024 (log=0)
  8 2008 inodes, 8032 blocks
  9 401 blocks (4.99%) reserved for the super user
 10 First data block=1
 11 Maximum filesystem blocks=8388608
 12 1 block group
 13 8192 blocks per group, 8192 fragments per group
 14 2008 inodes per group
 15 
 16 Writing inode tables: done
 17 Creating journal (1024 blocks): done
 18 Writing superblocks and filesystem accounting information: done
 19 
 20 This filesystem will be automatically checked every 27 mounts or
 21 180 days, whichever comes first.  Use tune2fs -c or -i to override.
 22 #swap linux 分区磁盘格式化
 23 [root@localhost ~]# mkswap /dev/sdb6 
 24 Setting up swapspace version 1, size = 41809059 kB
 25 #逻辑分区(linux分区)磁盘格式化:  (注:扩展分区不可以格式化)
 26 [root@localhost ~]# mkfs.ext3 /dev/sdb5
 27 mke2fs 1.39 (29-May-2006)
 28 Filesystem label=
 29 OS type: Linux
 30 Block size=4096 (log=2)
 31 Fragment size=4096 (log=2)
 32 1028160 inodes, 2056304 blocks
 33 102815 blocks (5.00%) reserved for the super user
 34 First data block=0
 35 Maximum filesystem blocks=2109734912
 36 63 block groups
 37 32768 blocks per group, 32768 fragments per group
 38 16320 inodes per group
 39 Superblock backups stored on blocks:
 40         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
 41 
 42 Writing inode tables: done
 43 Creating journal (32768 blocks): done
 44 Writing superblocks and filesystem accounting information: done
 45 
 46 This filesystem will be automatically checked every 20 mounts or
 47 180 days, whichever comes first.  Use tune2fs -c or -i to override.
 48 [root@localhost ~]# 


        5:磁盘挂载使用:

磁盘挂载使用的挂载方式:

  1. 手动挂载 : 使用的是mount命令
  2. 自动挂载 : 修改的是 fstab 这个文件内容


  1 #查看文件挂载点文件夹
  2 [root@localhost ~]# ls /mnt
  3 cdrom  hgfs
  4 #创建文件挂载点 sdb1 文件夹
  5 [root@localhost ~]# mkdir /mnt/sdb1
  6 [root@localhost ~]# ls /mnt
  7 cdrom  hgfs  sdb1
  8 #将 /dev/sdb1  磁盘挂载到  /mnt/sdb1 挂载点上(手动挂载)
  9 [root@localhost ~]# mount /dev/sdb1 /mnt/sdb1/                                                                                                   
 10                    swap    defaults        0 0
 11 #创建 /dev/sdb5 的文件挂载点  /mnt/sdb5 
 12 [root@localhost ~]# mkdir /mnt/sdb5 
 13 #自动挂载:  1:查看挂载文件 /etc/fstab 
 14 [root@localhost ~]# cat /etc/fstab 
 15 /dev/VolGroup00/LogVol01 /                       ext3    defaults        1 1
 16 LABEL=/boot             /boot                   ext3    defaults        1 2
 17 tmpfs                   /dev/shm                tmpfs   defaults        0 0
 18 devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
 19 sysfs                   /sys                    sysfs   defaults        0 0
 20 proc                    /proc                   proc    defaults        0 0
 21 /dev/VolGroup00/LogVol00 swap
 22 #在 磁盘挂载系统配置文件中 fstab 中新增:“/dev/sdb5              /mnt/sdb5                ext3     defaults       0 0”   内容
 23 [root@localhost ~]# vi /etc/fstab 
 24 #查看 fstab 文件新增的磁盘挂载信息
 25 [root@localhost ~]# cat /etc/fstab 
 26 /dev/VolGroup00/LogVol01 /                       ext3    defaults        1 1
 27 LABEL=/boot             /boot                   ext3    defaults        1 2
 28 tmpfs                   /dev/shm                tmpfs   defaults        0 0
 29 devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
 30 sysfs                   /sys                    sysfs   defaults        0 0
 31 proc                    /proc                   proc    defaults        0 0
 32 /dev/VolGroup00/LogVol00 swap                    swap    defaults        0 0
 33 /dev/sdb5              /mnt/sdb5                ext3     defaults       0 0
 34 #开始 加载挂载配置信息
 35 [root@localhost ~]# mount -a
 36 [root@localhost ~]# mount 
 37 /dev/mapper/VolGroup00-LogVol01 on / type ext3 (rw)
 38 proc on /proc type proc (rw)
 39 sysfs on /sys type sysfs (rw)
 40 devpts on /dev/pts type devpts (rw,gid=5,mode=620)
 41 /dev/sda1 on /boot type ext3 (rw)
 42 tmpfs on /dev/shm type tmpfs (rw)
 43 none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
 44 none on /proc/fs/vmblock/mountPoint type vmblock (rw)
 45 sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
 46 none on /var/lib/xenstored type tmpfs (rw)
 47 # 该内容信息表示 手动挂载的和自动挂载的磁盘 都 已经挂载成功
 48 /dev/sdb1 on /mnt/sdb1 type ext3 (rw)
 49 /dev/sdb5 on /mnt/sdb5 type ext3 (rw)
 50 #进入挂载的磁盘里面创建文件
 51 [root@localhost ~]# cd /mnt
 52 [root@localhost mnt]# ls
 53 cdrom  hgfs  sdb1  sdb2  sdb5
 54 [root@localhost mnt]# cd sdb1
 55 [root@localhost sdb1]# ls
 56 lost+found
 57 [root@localhost sdb1]# touch sd1
 58 [root@localhost sdb1]# cd ../sdb5
 59 [root@localhost sdb5]# ls
 60 lost+found
 61 [root@localhost sdb5]# cd ../sdb2
 62 [root@localhost sdb2]# ls
 63 [root@localhost sdb2]# 

        6: 卸载 磁盘

  1 # 卸载 挂载掉的磁盘
  2 [root@localhost sdb2]# umount /dev/sdb1
  3 [root@localhost sdb2]# cd ../
  4 [root@localhost mnt]# ls
  5 cdrom  hgfs  sdb1  sdb2  sdb5
  6 [root@localhost mnt]# cd sdb1
  7 [root@localhost sdb1]# ls
  8 # 挂载 磁盘
  9 [root@localhost sdb1]# mount /dev/sdb1 /mnt/sdb1
 10 [root@localhost sdb1]# ls
 11 [root@localhost sdb1]# cd ..
 12 [root@localhost mnt]# ls
 13 cdrom  hgfs  sdb1  sdb2  sdb5
 14 [root@localhost mnt]# cd sdb1
 15 [root@localhost sdb1]# ls
 16 lost+found  sd1
 17 [root@localhost sdb1]# 

        7: 新增交换换区

当在安装oracle数据库的时候 如果出现了 交换分区没有建立或者是交换分区不足的时候,可以来创建一个交换分区

  • 利用分区的方式来增加交换分区的大小
  1  #swap linux 分区磁盘格式化
  2  23 [root@localhost ~]# mkswap /dev/sdb6 
  3  24 Setting up swapspace version 1, size = 41809059 kB
  1 #查看分区使用情况
  2 [root@localhost sdb1]#  free
  3              total       used       free     shared    buffers     cached
  4 Mem:       2966528    2607140     359388          0      39976    2122400
  5 -/+ buffers/cache:     444764    2521764
  6 Swap:      8519672          0    8519672
  7 #开启交换分区
  8 [root@localhost sdb1]# swapon /dev/sdb6
  9 #查看分区使用情况
 10 [root@localhost sdb1]# free
 11              total       used       free     shared    buffers     cached
 12 Mem:       2966528    2630700     335828          0      40136    2122500
 13 -/+ buffers/cache:     468064    2498464
 14 Swap:     49348828          0   49348828
 15 [root@localhost sdb1]# 
  • 利用文件的方式来增加交换分区的大小
  1 #卸载 swap 交换分区 
  2 [root@localhost sdb1]# swapoff /dev/sdb6
  3 #查看磁盘空闲使用情况 
  4 [root@localhost sdb1]# free
  5              total       used       free     shared    buffers     cached
  6 Mem:       2966528    2611604     354924          0      40496    2122504
  7 -/+ buffers/cache:     448604    2517924
  8 Swap:      8519672          0    8519672
  9 #从空闲的 0 磁盘空间中 连续取出大小为10M的 swapfile 文件
 10 [root@localhost sdb1]# dd if=/dev/zero of=/swapfile bs=10M count=2
 11 2+0 records in
 12 2+0 records out
 13 20971520 bytes (21 MB) copied, 0.051647 seconds, 406 MB/s
 14 [root@localhost sdb1]# 
  1 #查看生成的 swapfile 文件大小信息
  2 [root@localhost sdb1]# du -h /swapfile
  3 21M     /swapfile
  4 [root@localhost sdb1]#
  1 #格式化 swapfile 文件
  2 [root@localhost sdb1]# mkswap /swapfile
  3 Setting up swapspace version 1, size = 20967 kB
  4 [root@localhost sdb1]# 



  1 
  2 [root@localhost sdb1]# free
  3              total       used       free     shared    buffers     cached
  4 Mem:       2966528    2631504     335024          0      40984    2143120
  5 -/+ buffers/cache:     447400    2519128
  6 Swap:      8519672          0    8519672
  7 #挂载 swapfile 文件为 swap交换分区 
  8 [root@localhost sdb1]# swapon /swapfile
  9 [root@localhost sdb1]# free
 10              total       used       free     shared    buffers     cached
 11 Mem:       2966528    2631380     335148          0      40996    2143124
 12 -/+ buffers/cache:     447260    2519268
 13 Swap:      8540144          0    8540144
 14 #卸载 swapfile 文件为 swap交换分区 
 15 
 16 [root@localhost sdb1]# swapoff /swapfile
 17 
 18 [root@localhost sdb1]# free
 19              total       used       free     shared    buffers     cached
 20 Mem:       2966528    2632496     334032          0      41008    2143124
 21 -/+ buffers/cache:     448364    2518164
 22 Swap:      8519672          0    8519672
 23 [root@localhost sdb1]# 


        8: 查看磁盘使用情况


  1 [root@localhost sdb1]# df
  2 Filesystem           1K-blocks      Used Available Use% Mounted on
  3 /dev/mapper/VolGroup00-LogVol01
  4                       89289592  53751404  30929372  64% /
  5 /dev/sda1              4022656    100424   3714596   3% /boot
  6 tmpfs                  1483044    785916    697128  53% /dev/shm
  7 none                   1482956        72   1482884   1% /var/lib/xenstored
  8 /dev/sdb5              8096120    149304   7535556   2% /mnt/sdb5
  9 /dev/sdb1                 7776      1075      6300  15% /mnt/sdb1
 10 [root@localhost sdb1]# df -h
 11 Filesystem            Size  Used Avail Use% Mounted on
 12 /dev/mapper/VolGroup00-LogVol01
 13                        86G   52G   30G  64% /
 14 /dev/sda1             3.9G   99M  3.6G   3% /boot
 15 tmpfs                 1.5G  768M  681M  53% /dev/shm
 16 none                  1.5G   72K  1.5G   1% /var/lib/xenstored
 17 /dev/sdb5             7.8G  146M  7.2G   2% /mnt/sdb5
 18 /dev/sdb1             7.6M  1.1M  6.2M  15% /mnt/sdb1
 19 [root@localhost sdb1]# 





十:RPM 和 tar 包


1: Linux 下软件包的安装和卸载

image


             1:RPM安装操作

image


             2:RPM 查询操作

imageimage

             3:RPM卸载操作

image

             4:RPM 升级操作

image



             5:RPM 验证操作

imageimage


             6:RPM 的其他附加命令

image

             7:安装示例(VM虚拟机中演示)


                         1:加载系统安装光碟

image

image

image

                         2:把 光盘内容直接挂载到

  1 [root@oracle ~]# mount /dev/cdrom -o loop /mnt//将光盘挂载到/mnt 目录下

注:我这里是把光盘的内容复制到了 /root/Cdrom_copy  目录下

                         3:安装 、卸载 、查询  rpm  包的安装情况

  1 3进入 media 目录
  2 [root@localhost ~]# cd /media/
  3 [root@localhost media]# ls
  4 Enterprise Linux dvd 20090908
  5 [root@localhost media]# cd Enterprise Linux dvd 20090908/
  6 [root@localhost Enterprise Linux dvd 20090908]# ls
  7 blafdoc.css  ClusterStorage  eula.en_US  GPL     isolinux   README-en.html    RELEASE-NOTES-en.html  RPM-GPG-KEY-oracle  supportinfo  VT
  8 Cluster      EULA            eula.py     images  README-en  RELEASE-NOTES-en  RPM-GPG-KEY            Server              TRANS.TBL
  9  #进入 Server 查看安装包 
 10 [root@localhost Enterprise Linux dvd 20090908]# cd Server/
 11 [root@localhost Server]# ls
 12 a2ps-4.13b-57.2.el5.i386.rpm                                           libwnck-devel-2.16.0-4.fc6.i386.rpm
 13 acl-2.2.39-3.el5.i386.rpm                                              libwvstreams-4.2.2-2.1.0.1.i386.rpm
 14 acpid-1.0.4-9.el5.i386.rpm                                             libwvstreams-devel-4.2.2-2.1.0.1.i386.rpm
 15 adaptx-0.9.13-3jpp.1.i386.rpm                                          libX11-1.0.3-11.el5.i386.rpm
 16 adaptx-doc-0.9.13-3jpp.1.i386.rpm                                      libX11-devel-1.0.3-11.el5.i386.rpm
 17 
 18 ...........还有居多安装包 省略不显示
 19 
 20 #  rpm -ivh  包名  ;安装新包
 21 [root@localhost Server]# rpm -ivh vsftpd-2.0.5-16.el5.i386.rpm 
 22 warning: vsftpd-2.0.5-16.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
 23 Preparing...                ########################################### [100%]
 24    1:vsftpd                 ########################################### [100%]
 25 
 26 #    rpm -qa|grep 文件名 ;查看包的安装情况
 27 [root@localhost Server]# rpm -qa |grep ftp
 28 lftp-3.7.11-4.el5
 29 vsftpd-2.0.5-16.el5
 30 tftp-server-0.49-2.0.1
 31 ftp-0.17-35.el5
 32 
 33 # rpm -e  安装包文件名 ;删除某个安装好的包
 34 [root@localhost Server]# rpm -e vsftpd-2.0.5-16.el5
 35 
 36 #    rpm -qa|grep 文件名 ;查看包的安装情况
 37 [root@localhost Server]# rpm -qa |grep ftp         
 38 lftp-3.7.11-4.el5
 39 tftp-server-0.49-2.0.1
 40 ftp-0.17-35.el5
 41 [root@localhost Server]# 


             9:yum 安装配置

Oracle Vm VirtualBox 搭建 yum 环境 》  《  Vmware Workstation _linux yum 仓库搭建   》  《  CentOS7.2 创建本地YUM源和局域网YUM源    》



2:打包/压缩工具 tar

                  1:tar 命令介绍

imageimageimage

可选的选项:

image

image

image


                  2:示例:打包 、查看压缩包


  1 #
  2 [root@localhost ~]# cd Cdrom_copy/
  3 [root@localhost Cdrom_copy]# ls
  4 blafdoc.css  ClusterStorage  eula.en_US  GPL     isolinux   README-en.html    RELEASE-NOTES-en.html  RPM-GPG-KEY-oracle  supportinfo  VT
  5 Cluster      EULA            eula.py     images  README-en  RELEASE-NOTES-en  RPM-GPG-KEY            Server              TRANS.TBL
  6 [root@localhost Cdrom_copy]# cd VT/
  7 [root@localhost VT]# ls
  8 gnome-applet-vm-0.1.2-1.el5.i386.rpm  libvirt-cim-0.5.5-2.el5.i386.rpm          python-virtinst-0.400.3-5.0.1.el5.noarch.rpm  virt-viewer-0.0.2-3.el5.i386.rpm
  9 libcmpiutil-0.4-2.el5.i386.rpm        libvirt-devel-0.6.3-20.0.1.el5.i386.rpm   repodata                                      xen-3.0.3-94.el5.i386.rpm
 10 libcmpiutil-devel-0.4-2.el5.i386.rpm  libvirt-python-0.6.3-20.0.1.el5.i386.rpm  TRANS.TBL                                     xen-devel-3.0.3-94.el5.i386.rpm
 11 libvirt-0.6.3-20.0.1.el5.i386.rpm     perl-Sys-Virt-0.2.0-4.el5.i386.rpm        virt-manager-0.6.1-8.el5.i386.rpm
 12 [root@localhost VT]# cd repodata/
 13 [root@localhost repodata]# ls
 14 comps-rhel5-vt.xml  filelists.xml.gz  other.xml.gz  primary.xml.gz  repomd.xml  TRANS.TBL
 15 # tar -cvf 压缩包名  文件名(*,多个/单个 文件名) ;显示打包过程:  -c  创建包  -v 显示创建过程  -f  文件
 16 [root@localhost repodata]# tar -cvf reodata.tar *
 17 comps-rhel5-vt.xml
 18 filelists.xml.gz
 19 other.xml.gz
 20 primary.xml.gz
 21 repomd.xml
 22 TRANS.TBL
 23 [root@localhost repodata]# ls
 24 comps-rhel5-vt.xml  filelists.xml.gz  other.xml.gz  primary.xml.gz  reodata.tar  repomd.xml  TRANS.TBL
 25 # tar -cvf 压缩包名  文件名(*,多个/单个 文件名) ;不显示打包过程:  -c  创建包  -v 显示创建过程  -f  文件
 26 
 27 [root@localhost repodata]# tar -cf reodataa.tar *
 28 [root@localhost repodata]# ls
 29 comps-rhel5-vt.xml  filelists.xml.gz  other.xml.gz  primary.xml.gz  reodataa.tar  reodata.tar  repomd.xml  TRANS.TBL
 30 #查看tar 包里面的文件信息  tar -tvf 压缩包名
 31 [root@localhost repodata]# tar -tvf reodata.tar 
 32 -rw-r--r-- root/root     15618 2009-09-09 06:55:31 comps-rhel5-vt.xml
 33 -rw-r--r-- root/root      9146 2009-09-09 06:55:30 filelists.xml.gz
 34 -rw-r--r-- root/root     41431 2009-09-09 06:55:30 other.xml.gz
 35 -rw-r--r-- root/root      7065 2009-09-09 06:55:30 primary.xml.gz
 36 -rw-r--r-- root/root      1149 2009-09-09 06:55:31 repomd.xml
 37 -rw-r--r-- root/root      1130 2009-09-09 08:29:58 TRANS.TBL
 38 #-----------给压缩包增加需要压缩的文件-------------------------
 39 #创建一个新文件 aa  
 40 [root@localhost repodata]# touch aa
 41 #tar -rvf 压缩包名 :给压缩包增加新的文件
 42 [root@localhost repodata]# tar -rvf reodata.tar 
 43 #查看压缩包的内容
 44 [root@localhost repodata]# tar -tvf reodata.tar 
 45 -rw-r--r-- root/root     15618 2009-09-09 06:55:31 comps-rhel5-vt.xml
 46 -rw-r--r-- root/root      9146 2009-09-09 06:55:30 filelists.xml.gz
 47 -rw-r--r-- root/root     41431 2009-09-09 06:55:30 other.xml.gz
 48 -rw-r--r-- root/root      7065 2009-09-09 06:55:30 primary.xml.gz
 49 -rw-r--r-- root/root      1149 2009-09-09 06:55:31 repomd.xml
 50 -rw-r--r-- root/root      1130 2009-09-09 08:29:58 TRANS.TBL
 51 [root@localhost repodata]# 

                  3:示例:解压缩

  1 [root@localhost repodata]# ls
  2 aa  comps-rhel5-vt.xml  filelists.xml.gz  other.xml.gz  primary.xml.gz  reodataa.tar  reodata.tar  repomd.xml  TRANS.TBL
  3 [root@localhost repodata]# mkdir test
  4 [root@localhost repodata]# ls
  5 aa  comps-rhel5-vt.xml  filelists.xml.gz  other.xml.gz  primary.xml.gz  reodataa.tar  reodata.tar  repomd.xml  test  TRANS.TBL
  6 [root@localhost repodata]# mv reodata* test/
  7 [root@localhost repodata]# ls
  8 aa  comps-rhel5-vt.xml  filelists.xml.gz  other.xml.gz  primary.xml.gz  repomd.xml  test  TRANS.TBL
  9 [root@localhost repodata]# cd test/
 10 [root@localhost test]# ls
 11 reodataa.tar  reodata.tar
 12 [root@localhost test]# tar -xvf reodata.tar 
 13 comps-rhel5-vt.xml
 14 filelists.xml.gz
 15 other.xml.gz
 16 primary.xml.gz
 17 repomd.xml
 18 TRANS.TBL
 19 [root@localhost test]# ls
 20 comps-rhel5-vt.xml  filelists.xml.gz  other.xml.gz  primary.xml.gz  reodataa.tar  reodata.tar  repomd.xml  TRANS.TBL
 21 [root@localhost test]# 

                   4:示例:打包压缩包 并查看包信息   tar -jcvf ;tar -zcvf ;


  1 [root@localhost test]# pwd
  2 /root/Cdrom_copy/VT/repodata/test
  3 [root@localhost test]# ls
  4 comps-rhel5-vt.xml  filelists.xml.gz  other.xml.gz  primary.xml.gz  repomd.xml  TRANS.TBL
  5 [root@localhost test]# tar -zcvf a.tar.gz * 
  6 comps-rhel5-vt.xml
  7 filelists.xml.gz
  8 other.xml.gz
  9 primary.xml.gz
 10 repomd.xml
 11 TRANS.TBL
 12 [root@localhost test]# s
 13 -bash: s: command not found
 14 [root@localhost test]# ls
 15 a.tar.gz  comps-rhel5-vt.xml  filelists.xml.gz  other.xml.gz  primary.xml.gz  repomd.xml  TRANS.TBL
 16 [root@localhost test]# tar -jcvf a1.tar.gz *
 17 a.tar.gz
 18 comps-rhel5-vt.xml
 19 filelists.xml.gz
 20 other.xml.gz
 21 primary.xml.gz
 22 repomd.xml
 23 TRANS.TBL
 24 [root@localhost test]# ls
 25 a1.tar.gz  a.tar.gz  comps-rhel5-vt.xml  filelists.xml.gz  other.xml.gz  primary.xml.gz  repomd.xml  TRANS.TBL
 26 [root@localhost test]# tar -jcvf a2.tar.gz2 * 
 27 a1.tar.gz
 28 a.tar.gz
 29 comps-rhel5-vt.xml
 30 filelists.xml.gz
 31 other.xml.gz
 32 primary.xml.gz
 33 repomd.xml
 34 TRANS.TBL
 35 [root@localhost test]# ls
 36 a1.tar.gz  a2.tar.gz2  a.tar.gz  comps-rhel5-vt.xml  filelists.xml.gz  other.xml.gz  primary.xml.gz  repomd.xml  TRANS.TBL
 37 [root@localhost test]# tar ztvf a1.tar.gz 
 38 
 39 gzip: stdin: not in gzip format
 40 tar: Child returned status 1
 41 tar: Error exit delayed from previous errors
 42 [root@localhost test]# tar ztvf a.tar.gz 
 43 -rw-r--r-- root/root     58086 2018-04-15 16:30:14 comps-rhel5-vt.xml
 44 -rw-r--r-- root/root      9146 2009-09-09 06:55:30 filelists.xml.gz
 45 -rw-r--r-- root/root     41431 2009-09-09 06:55:30 other.xml.gz
 46 -rw-r--r-- root/root      7065 2009-09-09 06:55:30 primary.xml.gz
 47 -rw-r--r-- root/root      1149 2009-09-09 06:55:31 repomd.xml
 48 -rw-r--r-- root/root      1130 2009-09-09 08:29:58 TRANS.TBL
 49 [root@localhost test]# tar jtvf a1.tar.gz 
 50 -rw-r--r-- root/root    116335 2018-04-15 16:32:01 a.tar.gz
 51 -rw-r--r-- root/root     58086 2018-04-15 16:30:14 comps-rhel5-vt.xml
 52 -rw-r--r-- root/root      9146 2009-09-09 06:55:30 filelists.xml.gz
 53 -rw-r--r-- root/root     41431 2009-09-09 06:55:30 other.xml.gz
 54 -rw-r--r-- root/root      7065 2009-09-09 06:55:30 primary.xml.gz
 55 -rw-r--r-- root/root      1149 2009-09-09 06:55:31 repomd.xml
 56 -rw-r--r-- root/root      1130 2009-09-09 08:29:58 TRANS.TBL
 57 [root@localhost test]# 



3:示例:安装一个 rlwrap-0.37.tar.gz 包

介绍rlwrap-0.37.tar.gz  的作用:

                  1 :把rlwrap-0.37.tar.gz  包 上传到 linux服务器中。

image

image

                  2:把rlwrap-0.37.tar.gz  包 解压缩

  1 
  2 [root@localhost ~]# ls
  3 4000  aaa  aaaaa.txt  alter  anaconda-ks.cfg  Cdrom_copy  Desktop  install.log  install.log.syslog  rlwrap-0.37  rlwrap-0.37.tar.gz  select  show  shutdown  startup
  4 [root@localhost ~]# ll
  5 total 328
  6 -rw-r--r-- 1 root   root      0 Mar 22 23:09 4000
  7 -rw-r--r-- 1 root   root      0 Apr  3 16:29 aaa
  8 -rw-r--r-- 1 root   root    422 Apr  3 16:34 aaaaa.txt
  9 -rw-r--r-- 1 root   root      0 Mar 22 23:10 alter
 10 -rw------- 1 root   root   1537 Nov 30  2016 anaconda-ks.cfg
 11 drwxr-xr-x 8 root   root   4096 Apr 15 15:12 Cdrom_copy
 12 drwxr-xr-x 2 root   root   4096 Nov 29  2016 Desktop
 13 -rw-r--r-- 1 root   root  42079 Nov 30  2016 install.log
 14 -rw-r--r-- 1 root   root      0 Nov 30  2016 install.log.syslog
 15 drwxrwxr-x 8 oracle dba    4096 Dec  8  2016 rlwrap-0.37
 16 -rw-r--r-- 1 root   root 251438 Feb 18  2014 rlwrap-0.37.tar.gz
 17 -rw-r--r-- 1 root   root      0 Mar 22 23:10 select
 18 -rw-r--r-- 1 root   root      0 Mar 22 23:10 show
 19 -rw-r--r-- 1 root   root      0 Mar 22 23:10 shutdown
 20 -rw-r--r-- 1 root   root      0 Mar 22 23:10 startup
 21 [root@localhost ~]# tar -zxvf rlwrap-0.37.tar.gz 
 22 rlwrap-0.37/
 23 rlwrap-0.37/completions/
 24 rlwrap-0.37/completions/testclient
 25 rlwrap-0.37/completions/coqtop
 26 rlwrap-0.37/doc/
 27 rlwrap-0.37/doc/rlwrap.man.in
 28 rlwrap-0.37/doc/Makefile.am
 29 rlwrap-0.37/doc/Makefile.in
 30 rlwrap-0.37/filters/
 31 rlwrap-0.37/filters/README
 32 rlwrap-0.37/filters/RlwrapFilter.pm
 33 rlwrap-0.37/filters/RlwrapFilter.3pm
 34 rlwrap-0.37/filters/count_in_prompt
 35 rlwrap-0.37/filters/pipeto
 36 rlwrap-0.37/filters/logger
 37 rlwrap-0.37/filters/null
 38 rlwrap-0.37/filters/unbackspace
 39 rlwrap-0.37/filters/pipeline
 40 rlwrap-0.37/filters/ftp_filter
 41 rlwrap-0.37/filters/history_format
 42 rlwrap-0.37/filters/simple_macro
 43 rlwrap-0.37/filters/template
 44 rlwrap-0.37/filters/scrub_prompt
 45 rlwrap-0.37/filters/paint_prompt
 46 rlwrap-0.37/filters/censor_passwords
 47 rlwrap-0.37/filters/listing
 48 rlwrap-0.37/filters/Makefile.am
 49 rlwrap-0.37/filters/Makefile.in
 50 rlwrap-0.37/src/
 51 rlwrap-0.37/src/rlwrap.h
 52 rlwrap-0.37/src/redblack.h
 53 rlwrap-0.37/src/malloc_debug.h
 54 rlwrap-0.37/src/completion.rb
 55 rlwrap-0.37/src/Makefile.am
 56 rlwrap-0.37/src/Makefile.in
 57 rlwrap-0.37/src/main.c
 58 rlwrap-0.37/src/signals.c
 59 rlwrap-0.37/src/readline.c
 60 rlwrap-0.37/src/pty.c
 61 rlwrap-0.37/src/completion.c
 62 rlwrap-0.37/src/term.c
 63 rlwrap-0.37/src/ptytty.c
 64 rlwrap-0.37/src/utils.c
 65 rlwrap-0.37/src/string_utils.c
 66 rlwrap-0.37/src/malloc_debug.c
 67 rlwrap-0.37/src/filter.c
 68 rlwrap-0.37/test/
 69 rlwrap-0.37/test/testclient
 70 rlwrap-0.37/test/testit
 71 rlwrap-0.37/tools/
 72 rlwrap-0.37/tools/config.guess
 73 rlwrap-0.37/tools/config.sub
 74 rlwrap-0.37/tools/depcomp
 75 rlwrap-0.37/tools/install-sh
 76 rlwrap-0.37/tools/missing
 77 rlwrap-0.37/README
 78 rlwrap-0.37/configure.ac
 79 rlwrap-0.37/aclocal.m4
 80 rlwrap-0.37/Makefile.am
 81 rlwrap-0.37/Makefile.in
 82 rlwrap-0.37/config.h.in
 83 rlwrap-0.37/configure
 84 rlwrap-0.37/AUTHORS
 85 rlwrap-0.37/COPYING
 86 rlwrap-0.37/ChangeLog
 87 rlwrap-0.37/INSTALL
 88 rlwrap-0.37/NEWS
 89 rlwrap-0.37/TODO
 90 rlwrap-0.37/BUGS
 91 rlwrap-0.37/PLEA
 92 [root@localhost ~]# ls
 93 4000  aaa  aaaaa.txt  alter  anaconda-ks.cfg  Cdrom_copy  Desktop  install.log  install.log.syslog  rlwrap-0.37  rlwrap-0.37.tar.gz  select  show  shutdown  startup
 94 [root@localhost ~]# 


                  3:把rlwrap-0.37.tar.gz  包   进行 源码方式安装


  1 
  2 [root@localhost ~]# ls
  3 4000  aaa  aaaaa.txt  alter  anaconda-ks.cfg  Cdrom_copy  Desktop  install.log  install.log.syslog  rlwrap-0.37  rlwrap-0.37.tar.gz  select  show  shutdown  startup
  4 [root@localhost ~]# cd rlwrap-0.37
  5 [root@localhost rlwrap-0.37]# ls
  6 aclocal.m4  BUGS       completions  config.h.in  config.status  configure.ac  doc      INSTALL   Makefile.am  NEWS  _profile  src       test  tools
  7 AUTHORS     ChangeLog  config.h     config.log   configure      COPYING       filters  Makefile  Makefile.in  PLEA  README    stamp-h1  TODO
  8 [root@localhost rlwrap-0.37]# cat INSTALL 
  9 PREREQUISITES
 10 
 11 To build rlwrap, you'll need an ANSI C compiler (gcc will certainly
 12 do) and GNU readline 4.2 or later. rlwrap should compile on most
 13 unices and unix-like environments like linux, the BSDs, OS/X, solaris,
 14 HP/UX, QNX, AIX and cygwin (special thanks to PolarHome for their
 15 "dinosaur zoo" of ageing Unix systems!)
 16 
 17 INSTALLATION
 18 
   ./configure
   make
   make install
 22 
 23 CONFIGURATION OPTIONS
 24 
 25 configure can be called with a number of options (e.g. if you want to
 26 install rlwrap in a non-standard place). Do
 27 
 28 ./configure --help
 29 
 30 to see them all. Most of them are not specific to rlwrap, except the
 31 following three:
 32 
 33 --enable-spy-on-readline : If we want to keep the display tidy when
 34 re-sizing the terminal window or printing multi-line prompts, we have
 35 to know whether or not readline is in horizontal-scroll-mode
 36 (i.e. wheter long lines are scrolled or wrapped). At present, this
 37 involves a look at a private readline variable - if you feel guilty
 38 about that, disable this option.
 39 
 40 --enable-homegrown-redisplay: some people report ddouble echoing of
 41 user input. Enabling this option will cure the problem - though the
 42 display will then flicker over slow connections (cf. BUGS)
 43 
 44 --enable-debug: Adds a --debug option to rlwrap's repertoire. This
 45 will make rlwrap write debug information to a file /tmp/rlwrap.debug
 46 (cf. the output of rlwrap --help for more info)
 47 
 48 
 49 UNINSTALLATION
 50 
 51 To uninstall, do 'make uninstall'
 52 
 53 INSTALLING AS NON-ROOT
 54 
 55 If you want to install rlwrap as non-root, you should call configure with
 56 the --prefix option, like:
 57 
 58 ./configure --prefix=$HOME
 59 
 60 after which 'make install' will install rlwrap in $HOME/bin
 61 
 62 You may have to install GNU readline  (e.g using ./configure
 63 --prefix=$HOME in the readline source directory)
 64 
 65 rlwrap's configure script will not find this installation automatically, but
 66 
 67 ./configure --prefix=$HOME CFLAGS=-I$HOME/include CPPFLAGS=-I$HOME/include LDFLAGS=-L$HOME/lib
 68 
 69 should work. You can add '-static' to LDFLAGS if you want to build a statically linked rlwrap.
 70 
 71 
 72 [root@localhost rlwrap-0.37]# ./configure
 73 make
 74 make install checking build system type... i686-pc-linux-gnu
 75 checking host system type... i686-pc-linux-gnu
 76 checking for a BSD-compatible install... /usr/bin/install -c
 77 checking whether build environment is sane... yes
 78 checking for a thread-safe mkdir -p... /bin/mkdir -p
 79 checking for gawk... gawk
 80 checking whether make sets $(MAKE)... yes
 81 checking whether make sets $(MAKE)... (cached) yes
 82 checking whether build environment is sane... yes
 83 checking for style of include used by make... GNU
 84 checking for gcc... gcc
 85 checking for C compiler default output file name... a.out
 86 checking whether the C compiler works... yes
 87 checking whether we are cross compiling... no
 88 checking for suffix of executables...
 89 checking for suffix of object files... o
 90 checking whether we are using the GNU C compiler... yes
 91 checking whether gcc accepts -g... yes
 92 checking for gcc option to accept ISO C89... none needed
 93 checking dependency style of gcc... gcc3
 94 checking how to run the C preprocessor... gcc -E
 95 checking for grep that handles long lines and -e... /bin/grep
 96 checking for egrep... /bin/grep -E
 97 checking for ANSI C header files... yes
 98 checking for sys/types.h... yes
 99 checking for sys/stat.h... yes
100 checking for stdlib.h... yes
101 checking for string.h... yes
102 checking for memory.h... yes
103 checking for strings.h... yes
104 checking for inttypes.h... yes
105 checking for stdint.h... yes
106 checking for unistd.h... yes
107 checking minix/config.h usability... no
108 checking minix/config.h presence... no
109 checking for minix/config.h... no
110 checking whether it is safe to define __EXTENSIONS__... yes
111 checking for gcc... (cached) gcc
112 checking whether we are using the GNU C compiler... (cached) yes
113 checking whether gcc accepts -g... (cached) yes
114 checking for gcc option to accept ISO C89... (cached) none needed
115 checking dependency style of gcc... (cached) gcc3
116 checking how to run the C preprocessor... gcc -E
117 checking for perl... /usr/bin/perl
118 checking for strip... strip
119 checking for ANSI C header files... (cached) yes
120 checking for sys/wait.h that is POSIX.1 compatible... yes
121 checking errno.h usability... yes
122 checking errno.h presence... yes
123 checking for errno.h... yes
124 checking fcntl.h usability... yes
125 checking fcntl.h presence... yes
126 checking for fcntl.h... yes
127 checking libutil.h usability... no
128 checking libutil.h presence... no
129 checking for libutil.h... no
130 checking for stdlib.h... (cached) yes
131 checking for string.h... (cached) yes
132 checking sched.h usability... yes
133 checking sched.h presence... yes
134 checking for sched.h... yes
135 checking sys/ioctl.h usability... yes
136 checking sys/ioctl.h presence... yes
137 checking for sys/ioctl.h... yes
138 checking for sys/wait.h... (cached) yes
139 checking sys/resource.h usability... yes
140 checking sys/resource.h presence... yes
141 checking for sys/resource.h... yes
142 checking stddef.h usability... yes
143 checking stddef.h presence... yes
144 checking for stddef.h... yes
145 checking termios.h usability... yes
146 checking termios.h presence... yes
147 checking for termios.h... yes
148 checking for unistd.h... (cached) yes
149 checking for stdint.h... (cached) yes
150 checking time.h usability... yes
151 checking time.h presence... yes
152 checking for time.h... yes
153 checking getopt.h usability... yes
154 checking getopt.h presence... yes
155 checking for getopt.h... yes
156 checking regex.h usability... yes
157 checking regex.h presence... yes
158 checking for regex.h... yes
159 checking curses.h usability... yes
160 checking curses.h presence... yes
161 checking for curses.h... yes
162 checking termcap.h usability... yes
163 checking termcap.h presence... yes
164 checking for termcap.h... yes
165 checking for term.h... yes
166 checking for ncurses/term.h... yes
167 checking argument type of tputs putc function... int
168 checking whether your getopt() correctly understands double colons in option string... yes
169 checking for an ANSI C-conforming const... yes
170 checking for pid_t... yes
171 checking whether time.h and sys/time.h may both be included... yes
172 checking whether gcc needs -traditional... no
173 checking return type of signal handlers... void
174 checking for getopt_long... yes
175 checking for getopt_long... (cached) yes
176 checking for isastream... yes
177 checking for mkstemp... yes
178 checking for pselect... yes
179 checking for putenv... yes
180 checking for readlink... yes
181 checking for sched_yield... yes
182 checking for setenv... yes
183 checking for setitimer... yes
184 checking for setsid... yes
185 checking for setrlimit... yes
186 checking for sigaction... yes
187 checking for snprintf... yes
188 checking for strlcpy... no
189 checking for strlcat... no
190 checking for strnlen... yes
191 checking for system... yes
192 checking for openpty in -lutil... yes
193 checking for openpty... yes
194 checking for getpty... no
195 checking for grantpt... yes
196 checking for unlockpt... yes
197 checking for getpt... yes
198 checking for pty/tty type... checking pty.h usability... yes
199 checking pty.h presence... yes
200 checking for pty.h... yes
201 OPENPTY
202 configure: checking for pty ranges...
203 checking for tgetent... no
204 checking for tgetent in -lcurses... yes
205 checking for readline in -lreadline... yes
206 checking whether your readline headers know about rl_set_screen_size... yes
207 checking whether your readline library knows about rl_set_screen_size... checking for rl_set_screen_size... yes
208 checking whether your readline knows about rl_variable_value... yes
209 checking whether your readline knows about rl_readline_version... yes
210 Will rlwrap find command's working directory under /proc/<commands pid>/cwd? let's see...
211 checking for /proc/15586/cwd/configure.ac... yes
212 
213 
214 configure: creating ./config.status
215 config.status: creating Makefile
216 config.status: creating filters/Makefile
217 config.status: creating doc/Makefile
218 config.status: creating src/Makefile
219 config.status: creating doc/rlwrap.man
220 config.status: creating config.h
221 config.status: config.h is unchanged
222 config.status: executing depfiles commands
223 
224 Now do:
225     make (or gmake)  to build rlwrap
226     make check       for instructions how to test it
227     make install     to install it
228 
229 [root@localhost rlwrap-0.37]# make
230 make  all-recursive
231 make[1]: Entering directory `/root/rlwrap-0.37'
232 Making all in doc
233 make[2]: Entering directory `/root/rlwrap-0.37/doc'
234 sed -e 's#@DATADIR@#/usr/local/share#'  rlwrap.man > rlwrap.1
235 make[2]: Leaving directory `/root/rlwrap-0.37/doc'
236 Making all in src
237 make[2]: Entering directory `/root/rlwrap-0.37/src'
238 make[2]: Nothing to be done for `all'.
239 make[2]: Leaving directory `/root/rlwrap-0.37/src'
240 Making all in filters
241 make[2]: Entering directory `/root/rlwrap-0.37/filters'
242 make[2]: Nothing to be done for `all'.
243 make[2]: Leaving directory `/root/rlwrap-0.37/filters'
244 make[2]: Entering directory `/root/rlwrap-0.37'
245 make[2]: Leaving directory `/root/rlwrap-0.37'
246 make[1]: Leaving directory `/root/rlwrap-0.37'
247 [root@localhost rlwrap-0.37]# make install .
248 Making install in doc
249 make[1]: Entering directory `/root/rlwrap-0.37/doc'
250 make[2]: Entering directory `/root/rlwrap-0.37/doc'
251 make[2]: Nothing to be done for `install-exec-am'.
252 test -z "/usr/local/share/man/man1" || /bin/mkdir -p "/usr/local/share/man/man1"
253  /usr/bin/install -c -m 644 rlwrap.1 '/usr/local/share/man/man1'
254 make[2]: Leaving directory `/root/rlwrap-0.37/doc'
255 make[1]: Leaving directory `/root/rlwrap-0.37/doc'
256 Making install in src
257 make[1]: Entering directory `/root/rlwrap-0.37/src'
258 make[2]: Entering directory `/root/rlwrap-0.37/src'
259 test -z "/usr/local/bin" || /bin/mkdir -p "/usr/local/bin"
260   /usr/bin/install -c rlwrap '/usr/local/bin'
261 make[2]: Nothing to be done for `install-data-am'.
262 make[2]: Leaving directory `/root/rlwrap-0.37/src'
263 make[1]: Leaving directory `/root/rlwrap-0.37/src'
264 Making install in filters
265 make[1]: Entering directory `/root/rlwrap-0.37/filters'
266 make[2]: Entering directory `/root/rlwrap-0.37/filters'
267 make[2]: Nothing to be done for `install-exec-am'.
268 test -z "/usr/local/share/man/man3" || /bin/mkdir -p "/usr/local/share/man/man3"
269  /usr/bin/install -c -m 644 RlwrapFilter.3pm '/usr/local/share/man/man3'
270 make[2]: Leaving directory `/root/rlwrap-0.37/filters'
271 make[1]: Leaving directory `/root/rlwrap-0.37/filters'
272 make[1]: Entering directory `/root/rlwrap-0.37'
273 make[2]: Entering directory `/root/rlwrap-0.37'
274 make[2]: Nothing to be done for `install-exec-am'.
275 test -z "/usr/local/share/rlwrap" || /bin/mkdir -p "/usr/local/share/rlwrap"
276 /bin/mkdir -p '/usr/local/share/rlwrap/filters'
277  /usr/bin/install -c -m 644  filters/README filters/RlwrapFilter.pm filters/RlwrapFilter.3pm filters/count_in_prompt filters/pipeto filters/logger filters/null filters/unbackspace filters/pipeline filters/ftp_filter filters/history_format filters/simple_macro filters/template filters/scrub_prompt filters/paint_prompt filters/censor_passwords filters/listing '/usr/local/share/rlwrap/filters'
278 /bin/mkdir -p '/usr/local/share/rlwrap/completions'
279  /usr/bin/install -c -m 644  completions/testclient completions/coqtop '/usr/local/share/rlwrap/completions'
280 make  install-data-hook
281 make[3]: Entering directory `/root/rlwrap-0.37'
282 chmod a+x /usr/local/share/rlwrap/filters/*
283 make[3]: Leaving directory `/root/rlwrap-0.37'
284 make[2]: Leaving directory `/root/rlwrap-0.37'
285 make[1]: Leaving directory `/root/rlwrap-0.37'
286 make: Nothing to be done for `.'.
287 [root@localhost rlwrap-0.37]# 



十一:网络配置及操作

image 

1: ifconfig 查看ip地址信息

image


image

image

image

image


2: Ping 命令

imageimage


3:常用网络配置文件

image

image

image

   

                  1:/etc/sysconfig/network 网络配置

image


                  2:/etc/hosts  Ip 地址和主机名的映射

imageimage

image

                  3:/etc/sysconfig/network-scripts/ifcfg-ethN 文件

image


4:常用网络操作方法

image

                 1:ftp 远程文件传输

image

image

imageimageimage

image


十二  : 系统信息及运行状态监控

imageimage

                 1:查看linux文件系统信息  df 命令

image


                 2:查看文件或者文件夹的大小   du 命令

image


                 3:统计并输出 CPU 使用信息及特定设置或分区IO的信息  iostat 命令

image

image



                 4: swap 命令

image

image




十三: linux 标准输入输出和重定向


1: 标准输入和输出

        执行一个shell命令行时通常会自动打开三个标准文件,即标准输入文件(stdin),通常对应终端的键盘;标准输出文件(stdout)和标准错误输出文件(stderr),这两个文件都对应终端的屏幕。进程将从标准输入文件中得到输入数据,将正常输出数据输出到标准输出文件,而将错误信息送到标准错误文件中。
        以cat命令为例,cat命令的功能是从命令行给出的文件中读取数据,并将这些数据直接送到标准输出。若使用如下命令:

  1 $ cat config

        将会把文件config的内容依次显示到屏幕上。但是,如果cat的命令行中没有参数,它就会从标准输入中读取数据,并将其送到标准输出。例如:

  1 $ cat
  2 Hello world
  3 Hello world
  4 Bye
  5 Bye
  6 <ctrl+d>
  7 $

       用户输入的每一行都立刻被cat命令输出到屏幕上。
        另一个例子,命令sort按行读入文件正文(当命令行中没有给出文件名时,表示从标准输入读入),将其排序,并将结果送到标准输出。下面的例子是从标准输入读入一个采购单,并将其排序。

  1 $ sort
  2 bananas
  3 carrots
  4 apples
  5 <ctrl+d>
  6 apples
  7 bananas
  8 carrots
  9 $

       这时我们在屏幕上得到了已排序的采购单。
        直接使用标准输入/输出文件存在以下问题:
        输入数据从终端输入时,用户费了半天劲输入的数据只能用一次。下次再想用这些数据时就得重新输入。而且在终端上输入时,若输入有误修改起来不是很方便。
        输出到终端屏幕上的信息只能看不能动。我们无法对此输出作更多处理,如将输出作为另一命令的输入进行进一步的处理等。
为了解决上述问题,Linux系统为输入、输出的传送引入了另外两种机制,即输入/输出重定向和管道。


2:输入重定向

       输入重定向是指把命令(或可执行程序)的标准输入重定向到指定的文件中。也就是说,输入可以不来自键盘,而来自一个指定的文件。所以说,输入重定向主要用于改变一个命令的输入源,特别是改变那些需要大量输入的输入源。
        例如,命令wc统计指定文件包含的行数、单词数和字符数。如果仅在命令行上键入:

  1 $ wc

       wc将等待用户告诉它统计什么,这时shell就好象死了一样,从键盘键入的所有文本都出现在屏幕上,但并没有什么结果,直至按下<ctrl+d>,wc才将命令结果写在屏幕上。
        如果给出一个文件名作为wc命令的参数,如下例所示,wc将返回该文件所包含的行数、单词数和字符数。

  1 $ wc /etc/passwd
  2 20 23 726 /etc/passwd
  3 $

       另一种把/etc/passwd文件内容传给wc命令的方法是重定向wc的输入。输入重定向的一般形式为:命令<文件名。可以用下面的命令把wc命令的输入重定向为/etc/passwd文件

  1 $ wc < /etc/passwd
  2 20 23 726
  3 $

       另一种输入重定向称为here文档,它告诉shell当前命令的标准输入来自命令行。here文档的重定向操作符使用<<。它将一对分隔符(本例中用delim表示)之间的正文重定向输入给命令。下例将一对分隔符delim之间的正文作为wc命令的输入,统计出正文的行数、单词数和字符数。

  1 $ wc<<delim
  2 >this text forms the content
  3 >of the here document,which
  4 >continues until the end of
  5 >text delimter
  6 >delim
  7 4 17 98

       在<<操作符后面,任何字符都可以作为正文开始前的分隔符,本例中使用delim作为分隔符。here文档的正文一直延续到遇见另一个分隔符为止。第二个分隔符应出现在新行的开头。这时here文档的正文(不包括开始和结束的分隔符)将重新定向送给命令wc作为它的标准输入。
由于大多数命令都以参数的形式在命令行上指定输入文件的文件名,所以输入重定向并不经常使用。尽管如此,当要使用一个不接受文件名作为输入参数的命令,而需要的输入内容又存在一个文件里时,就能用输入重定向解决问题


3:输出重定向

       输出重定向是指把命令(或可执行程序)的标准输出或标准错误输出重新定向到指定文件中。这样,该命令的输出就不显示在屏幕上,而是写入到指定文件中。
        输出重定向比输入重定向更常用,很多情况下都可以使用这种功能。例如,如果某个命令的输出很多,在屏幕上不能完全显示,那么将输出重定向到一个文件中,然后再用文本编辑器打开这个文件,就可以查看输出信息;如果想保存一个命令的输出,也可以使用这种方法。还有,输出重定向可以用于把一个命令的输出当作另一个命令的输入(还有一种更简单的方法,就是使用管道,将在下面介绍)。

       输出重定向的一般形式为:命令>文件名。例如:

  1 $ ls > directory.out
  2 $ cat directory.out
  3 ch1.doc ch2.doc ch3.doc chimp config mail/ test/
  4 $

       将ls命令的输出保存为一个名为directory.out的文件。
        注:如果>符号后边的文件已存在,那么这个文件将被重写。
        为避免输出重定向中指定文件只能存放当前命令的输出重定向的内容,shell提供了输出重定向的一种追加手段。输出追加重定向与输出重定向的功能非常相似,区别仅在于输出追加重定向的功能是把命令(或可执行程序)的输出结果追加到指定文件的最后,而该文件原有内容不被破坏。
如果要将一条命令的输出结果追加到指定文件的后面,可以使用追加重定向操作符>>。形式为:命令>>文件名。例如:

  1 $ ls *.doc>>directory.out
  2 $ cat directory.out
  3 ch1.doc ch2.doc ch3.doc chimp config mail/ test/
  4 ch1.doc ch2.doc ch3.doc
  5 $

      和程序的标准输出重定向一样,程序的错误输出也可以重新定向。使用符号2>(或追加符号2>>)表示对错误输出设备重定向。例如下面的命令:

  1 $ ls /usr/tmp 2> err.file


      可在屏幕上看到程序的正常输出结果,但又将程序的任何错误信息送到文件err.file中,以备将来检查用。
       还可以使用另一个输出重定向操作符(&>)将标准输出和错误输出同时送到同一文件中。例如:

  1 $ ls /usr/tmp &> output.file

      利用重定向将命令组合在一起,可实现系统单个命令不能提供的新功能。例如使用下面的命令序列

  1 $ ls /usr/bin > /tmp/dir
  2 $ wc –w < /tmp/dir
  3 459

      统计了/usr/bin目录下的文件个数。


4:管道

      将一个程序或命令的输出作为另一个程序或命令的输入,有两种方法,一种是通过一个临时文件将两个命令或程序结合在一起,例如上个例子中的/tmp/dir文件将ls和wc命令联在一起;另一种是Linux所提供的管道功能。这种方法比前一种方法更好。
       管道可以把一系列命令连接起来,这意味着第一个命令的输出会作为第二个命令的输入通过管道传给第二个命令,第二个命令的输出又会作为第三个命令的输入,以此类推。显示在屏幕上的是管道行中最后一个命令的输出(如果命令行中未使用输出重定向)。
       通过使用管道符“|”来建立一个管道行。用管道重写上面的例子:

  1 $ ls /usr/bin|wc -w
  2 1789
  3 #再如:
  4 $ cat sample.txt|grep "High"|wc -l


      管道将cat命令(列出一个文件的内容)的输出送给grep命令。grep命令在输入里查找单词High,grep命令的输出则是所有包含单词High的行,这个输出
又被送给wc命令,wc命令统计出输入中的行数。假设sample.txt文件的内容如下:

  1 Things to do today:
  2 Low:Go grocery shopping
  3 High:Return movie
  4 High:Clear level 3 in Alien vs. Predator
  5 Medium:Pick up clothes from dry cleaner

     那么该管道行的结果是2。

5:命令替换

     命令替换和重定向有些相似,但区别在于命令替换是将一个命令的输出作为另外一个命令的参数。常用命令格式为:

  1 command1 `command2`










------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

原文地址:https://www.cnblogs.com/ios9/p/7584134.html