马哥教育网络班21期-第二周课程练习

第二周课程练习

1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示?

    1.1 目录管理类命令:cd,pwd,ls,mkdir,rmdir,tree

         1.1.1 cd:主要功能是改变当前目录,可使用此命令在linux进行目录跳转。

            命令格式:cd 目录

            使用实例:

            1、跳转至用户主目录

[tom@CentOS6 /]$ id
uid=507(tom) gid=508(tom) 组=508(tom),2001(mygrp)
[tom@CentOS6 /]$ pwd
/
[tom@CentOS6 /]$ cd ~
[tom@CentOS6 ~]$ pwd
/home/tom

            2、跳转至用户主目录  

[tom@CentOS6 /]$ pwd
/
[tom@CentOS6 /]$ cd
[tom@CentOS6 ~]$ pwd
/home/tom

            3、切换至指定用户的主目录

[root@CentOS6 /]# cd ~jeery
[root@CentOS6 jeery]# pwd
/home/jeery
[root@CentOS6 jeery]#

            4、在上一个目录和当前目录之间来回切换

[root@CentOS6 ~]# pwd
/root
[root@CentOS6 ~]# cd /var
[root@CentOS6 var]# pwd
/var
[root@CentOS6 var]# cd -
/root
[root@CentOS6 ~]# cd -
/var

        1.1.2 pwd:显示当前工作目录。           

                命令格式:pwd [选项]

                 常用参数:

                    -L:目录连接链接时,输出连接路径

                        -P:输出物理路径

                 使用实例:

                 1、显示当前路径

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

                 2、显示当前物理路径

1
2
3
4
5
6
7
[root@CentOS6 ~]# cd /etc/init.d/
[root@CentOS6 init.d]
[root@CentOS6 init.d]# pwd -P
/etc/rc.d/init.d
[root@CentOS6 init.d]
[root@CentOS6 init.d]# pwd 
/etc/init.d

                 3、显示链接路径

1
2
3
4
[root@CentOS6 init.d]# pwd -L
/etc/init.d
[root@CentOS6 init.d]# pwd
/etc/init.d

        1.1.3 ls:显示指定路径下的文件列表。

            命令格式:ls [选项]… [DIR]…

              常用参数:

            -a:显示所有档案及目录(ls内定将档案名或目录名称为“.”的视为隐藏,不会列出); 

              -A:显示除隐藏文件“.”和“..”以外的所有文件列表; 

              -C:多列显示输出结果。这是默认选项; 

              -l:与“-C”选项功能相反,所有输出信息用单列格式输出,不输出为多列;

              -h, –human-readable:与-l 一起,以易于阅读的格式输出 

              -F:在每个输出项后追加文件的类型标识符,具体含义:“*”表示具有可执行权限的普通文件,“/”表示目录,“@”表示符号链接,“|”表示命令管道FIFO,“=”表示sockets套接字。当文件为普通文件时,不输出任何标识符;  

              -c:与“-lt”选项连用时,按照文件状态时间排序输出目录内容,排序的依据是文件的索引节点中的ctime字段。与“-l”选项连用时,则排序的一句是文件的状态改变时间; 

              -d:仅显示目录名,而不显示目录下的内容列表。显示符号链接文件本身,而不显示其所指向的目录列表;  

              -i:显示文件索引节点号(inode)。一个索引节点代表一个文件; –file-type:与“-F”选项的功能相同,但是不显示“*”; 

              -k:以KB(千字节)为单位显示文件大小; 

              -l:以长格式显示目录下的内容列表。输出的信息从左到右依次包括文件名,文件类型、权限模式、硬连接数、所有者、组、文件大小和文件的最后修改时间等;  

              -r:以文件名反序排列并输出目录内容列表; 

              -s:显示文件和目录的大小,以区块为单位; 

              -t:用文件和目录的更改时间排序; 

              -L:如果遇到性质为符号链接的文件或目录,直接列出该链接所指向的原始文件或目录; 

              -R:递归处理,将指定目录下的所有文件及子目录一并处理; 

              –full-time:列出完整的日期与时间; 

              –color[=WHEN]:使用不同的颜色高亮显示不同类型的。

            使用实例:

            1、以列的形式显示当前目录下的目录和文件

[root@CentOS6 ~]# ls -l
总用量 116
-rw------- 1 root root  1762 6月   6 2015 anaconda-ks.cfg
-rw-r--r-- 1 root root    54 10月 17 2015 bashrc_logout
-rw-r--r-- 1 root root 50263 6月   6 2015 install.log
-rw-r--r-- 1 root root 11308 6月   6 2015 install.log.syslog

输出解释:-rw——- 1 root root  1762 6月   6 2015 anaconda-ks.cfg    

    -:文件类型,-表示普通文件,d表示文件夹,l表示符号链接文件,c表示字符或块设备,b表示区块设备二进制文件,s表示数据接口文件,-p表示数据传送文件(FIFO,pipe);

    rw——-:访问权限:perm   

    1:文件被硬链接的次数;

    左root:文件的属主;

    右root:文件的属组;

    1762:文件的大小;             

          6月   6 2015:文件最近一次被修改时间;

          anaconda-ks.cfg:文件名

            2、列出根目录的所有文件,并且以列形式,按修改时间排序,以人类易看的格式显示出来

[root@CentOS6 /]# ls -lhta
总用量 108K
drwxrwxrwt   6 root root 4.0K 6月  28 15:26 tmp
dr-xr-x---  32 root root 4.0K 6月  28 11:41 root
drwxr-xr-x  21 root root 4.0K 6月  28 08:10 home
drwxr-xr-x 123 root root  12K 6月  28 07:24 etc
drwxr-xr-x   7 root root    0 10月 26 2015 selinux
drwxr-xr-x  13 root root    0 10月 26 2015 sys
dr-xr-xr-x 196 root root    0 10月 26 2015 proc
drwxr-xr-x  19 root root 3.9K 10月 26 2015 dev
drwxr-xr-x   2 root root    0 10月 26 2015 net
drwxr-xr-x   2 root root    0 10月 26 2015 misc
dr-xr-xr-x  25 root root 4.0K 10月 26 2015 .
dr-xr-xr-x  25 root root 4.0K 10月 26 2015 ..
-rw-r--r--   1 root root    0 10月 26 2015 .autofsck
drwxr-xr-x   3 root root 4.0K 10月 26 2015 media
-rw-r--r--   1 root root    0 10月 12 2015 .autorelabel
drwxr-xr-x   4 root root 4.0K 9月   1 2015 mnt
drwxr-xr-x   3 root root 4.0K 8月  26 2015 srv
dr-xr-xr-x   2 root root 4.0K 6月   8 2015 bin
dr-xr-xr-x   2 root root  12K 6月   8 2015 sbin
dr-xr-xr-x  18 root root  12K 6月   8 2015 lib
drwx------   3 root root 4.0K 6月   6 2015 .dbus
dr-xr-xr-x   5 root root 1.0K 6月   6 2015 boot
drwxr-xr-x   3 root root 4.0K 6月   6 2015 opt
drwxr-xr-x  23 root root 4.0K 6月   6 2015 var
drwxr-xr-x  12 root root 4.0K 6月   6 2015 usr
drwxr-xr-x   3 root root 1.0K 6月   6 2015 myshare
drwx------   2 root root  16K 6月   6 2015 lost+found

        1.1.4 mkdir:创建目录

            命令格式:mkdir [选项]… 目录…

               常用参数:

              -m, –mode:设置权限模式(类似chmod) 

                -p, –parents:需要时创建目标目录的上层目录,但即使这些目录已存在也不当作错误处理

                -v, –verbose:每次创建新目录都显示详细信息

            使用实例:

            1、创建test目录,设置权限为所有人读写执行,并显示创建过程;

[root@localhost tmp]# mkdir -v -m 777 test
mkdir: 已创建目录 "test"
[root@localhost tmp]# ll
总用量 4
-rw-r--r--. 1 root root    0 8月  25 08:01 attrtest
drwxrwxrwx. 2 root root 4096 8月  31 20:30 test

        1.1.5 rmdir:删除目录,该命令只能删除空目录;

            命令格式:rmdir [选项]… 目录…

            使用实例:

            1、删除test目录

[root@localhost tmp]# ll
总用量 4
-rw-r--r--. 1 root root    0 8月  25 08:01 attrtest
drwxrwxrwx. 2 root root 4096 8月  31 20:30 test
[root@localhost tmp]# rmdir test
[root@localhost tmp]# ll
总用量 0
-rw-r--r--. 1 root root 0 8月  25 08:01 attrtest
[root@localhost tmp]#

          1.1.6 tree:以树形图列出文件的层级结构  

            命令格式:tree [选项]… 目录…

                常用参数:

                  -d:只显示目录;

                      -L:level:指定显示的层级数目;

                     -P pattern:只显示由指定pattern匹配到的路径;

            使用实例:

            1、列出根目录下的子目录1级树形结构

[root@localhost tmp]# tree -dL 1 /
/
├── bin
├── boot
├── dev
├── etc
├── home
├── lib
├── lost+found
├── media
├── misc
├── mnt
├── myshare
├── net
├── opt
├── proc
├── root
├── sbin
├── selinux
├── srv
├── sys
├── tmp
├── usr
└── var
22 directories
[root@localhost tmp]#

    1.2 文件查看类命令:cat,tac,more,less,tail,head

        1.2.1 cat:连结文件并输出打印,一口气将一个文本文件内容全部打印到屏幕上,日志文件慎用; 

            命令格式:cat [选项]… [文件]…    

            常用参数:         

            -A, –show-all:等同于-vET

              -n 或 –number 由 1 开始对所有输出的行数编号;
              -b 或 –number-nonblank 和 -n 相似,只不过对于空白行不编号;
              -s 或 –squeeze-blank 当遇到有连续两行以上的空白行,就代换为一行的空白行;  

              -T, –show-tabs:将跳格字符显示为 ^I;    

              -E, –show-ends:在每行结束处显示$;

              -v,–show-nonprinting:使用^和 M- 引用,除了 LFD 和 TAB 之外;

            使用实例:

            1、显示/etc/hosts的文件内容,并编号和显示每行的结束符;

[root@localhost tmp]# cat -nE /etc/hosts
     1127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4$
     2::1         localhost localhost.localdomain localhost6 localhost6.localdomain6$
[root@localhost tmp]#

        1.2.2 tac:和cat功能差不多,但是反序显示内容;

            命令格式:tac [OPTION]… [FILE]…

            使用实例:显示/etc/hosts的文件内容;

[root@localhost tmp]# tac /etc/hosts
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
[root@localhost tmp]#

        1.2.3 more:跟cat一样显示文件内容,但是more会以一页一页的显示文件内容,比较方便查看;

            命令格式:more [OPTION] FILE……

            常用参数:                

       +n从笫n行开始显示

         -n定义屏幕大小为n行                                                        

+/pattern 在每个档案显示前搜寻该字串(pattern),然后从该字串前两行之后开始显示  

         -c从顶部清屏,然后显示

         -d显示翻页及退出提示            

                常用操作命令:

                Enter:向下n行,需要定义。默认为1行

                Ctrl+F:向下滚动一屏

                空格键:向下滚动一屏

                Ctrl+B:返回上一屏

                =:输出当前行的行号

                :f 输出文件名和当前行的行号

                V:调用vi编辑器

                !命令:调用Shell,并执行命令 

                q:退出more

            使用实例:

            1、设置每屏幕显示5行

[root@localhost tmp]# more -5 /etc/ssh/ssh_config 
#$OpenBSD: ssh_config,v 1.25 2009/02/17 01:28:32 djm E
xp $
# This is the ssh client system-wide configuration file.  See
# ssh_config(5) for more information.  This file provides def
--More--(8%)

            2、和管道|结合起来 显示/etc的目录内容

[root@localhost tmp]# ll /etc | more -5
总用量 2316
drwxr-xr-x.  3 root root     4096 6月   6 17:58 abrt
drwxr-xr-x.  4 root root     4096 6月   6 18:08 acpi
-rw-r--r--.  1 root root       51 8月  31 20:02 adjtime
drwxr-xr-x.  2 root root     4096 6月   6 17:56 akonadi
--More--

        1.2.4 less 具也是对文件或其它输出进行分页显示的工具,功能极其强大。less的用法比起more更加的有弹性。

            命令格式:less [参数] 文件

            常用参数:               

                -b <缓冲区大小> 设置缓冲区的大小

                -e  当文件显示结束后,自动离开

                -f  强迫打开特殊文件,例如外围设备代号、目录和二进制文件

                -g  只标志最后搜索的关键词

                -i  忽略搜索时的大小写

                -m  显示类似more命令的百分比

                -N  显示每行的行号

                -o <文件名> 将less 输出的内容在指定文件中保存起来

                -Q  不使用警告音

                -s  显示连续空行为一行

                -S  行过长时间将超出部分舍弃

                -x <数字> 将“tab”键显示为规定的数字空格

             常用操作命令:                

                字符串:向下搜索“字符串”的功能

                ?字符串:向上搜索“字符串”的功能

                n:重复前一个搜索(与 / 或 ? 有关)

                N:反向重复前一个搜索(与 / 或 ? 有关)

                b  向后翻一页

                d  向后翻半页

                h  显示帮助界面

                Q  退出less 命令

                u  向前滚动半页

                y  向前滚动一行

                空格键 滚动一行

                回车键 滚动一页

                [pagedown]: 向下翻动一页

                [pageup]:   向上翻动一页

               使用实例:

            1、显示/etc/hosts文件内容,并显示行号;

[root@localhost tmp]# less -N /etc/hosts

        1.2.5 head:输出文件前面一部分内容,可以设置只显示头几行;

            命令格式:head [OPTION]… [FILE]..

            常用参数:

                -c#:指令获取前#字节

                   -n: #或-#:指定获取前#行

            使用实例:

            1、显示文件前3行内容;

[root@localhost ssh]# head -n 3 ssh_config 
#$OpenBSD: ssh_config,v 1.25 2009/02/17 01:28:32 djm Exp $
# This is the ssh client system-wide configuration file.  See
[root@localhost ssh]#

        1.2.6 tail: 输出文件尾部的一部分内容,可以设置最显示最后几行;

               tail   [OPTION]… [FILE]..

            常用参数:

                  -c#:指令获取前#字节

                    -n #或-#:指定获取前#行

                使用实例:

            1、显示文件最后3行内容;

[root@localhost ssh]# tail -n 3 ssh_config 
SendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT 
SendEnv LC_IDENTIFICATION LC_ALL LANGUAGE
SendEnv XMODIFIERS

    1.3 文件的时间戳管理工具:touch

        1.3.1 touch:改变文件时间戳属性,并可以创建文件。

            使用格式: touch [选项]…文件…

            常用参数:

                 -a:only atime

                     -m:only mtime                        

                    -t STAMP:[[CC]YY]MMDDhhmm[.ss]

                   -c:如果文件不存在,则不予创建

            使用实例:

            1、更改1.txt文件的访问时间和修改时间;

[root@localhost tmp]# touch -t 201501121212.12 1.txt
[root@localhost tmp]# ll
总用量 0
-rw-r--r--. 1 root root 0 1月  12 2015 1.txt
-rw-r--r--. 1 root root 0 8月  25 2015 attrtest
[root@localhost tmp]#

            2、设置1.txt文件的修改时间跟当前时间同步;

[root@localhost tmp]# touch -m 1.txt 
[root@localhost tmp]# 
[root@localhost tmp]# 
[root@localhost tmp]# ll
总用量 0
-rw-r--r--. 1 root root 0 7月   2 21:50 1.txt

            3、创建2.txt空文件

[root@localhost tmp]# touch 2.txt
[root@localhost tmp]# ll 2.txt
-rw-r--r--. 1 root root 0 7月   2 21:53 2.txt
[root@localhost tmp]#

    1.4 文件管理类命令:cp,mv,rm            

        1.4.1 cp:复制命令

           cp [OPTION]… [-T] SOURCE DEST

            cp [OPTION]… SOURCE… DIRECTORY

            cp [OPTION]… -t DIRECTORY SOURCE..

              cp SRC DEST

               (SRC是文件)

                 如果目标不存在,新建DEST,并将SRC中内容填充至DEST中;

                 如果目标存在:

                如果DEST是文件:将SRC中的内容覆盖至DEST中;

                    此时建议为cp命令使用-i选项;

                    如果DEST是目录:在DEST下新建与原文件同名的文件,并将SRC中内容填充至新文件中;

               cp SRC……DEST

                 SRC……:多个文件

                 DEST必须存在,且为目录;其它情形均会出错;

                   cp SRC DEST

                   SRC是目录:

                     则使用选项:-r

                   如果DEST不存在:

                      如果DEST不存在,则创建指定目录,复制SRC目录中的所有文件至DEST中;

                   如果DEST存在:

                      如果DEST是文件:报错

                      如果DEST是目录:在目标目录下创建一个一源目录同名的目录,并且把源目录文件复制到目标目中;

            常用参数:

               -i:交互式;

               -r,-R:递归复制目录及内部的所有内容;

               -a:归档,相当于-dR –preserv=all

                        -d:–no-dereference  –preserv=links:不追踪符号链接  

                        –preserv=[=ATTR_LIST]

                                mode:权限

                                ownership:属主属组

                                timestamp:时间戳

                                links:链接属性

                                xattr:扩展属性

                                context:安全上下文

               -p: –preserve=mode,ownership,timestamps

               -v:–verbose

               -f:–force

            使用实例:

            1、复制/etc/hosts文件到tmp目录

[root@localhost test]# cp /etc/hosts /tmp/

            2、复制整个/etc目录到tmp目录

[root@localhost test]# cp -r /etc /tmp

        1.4.2 mv:move,移动文件

            mv [OPTION]… [-T] SOURCE DEST

              mv [OPTION]… SOURCE… DIRECTORY

              mv [OPTION]… -t DIRECTORY SOURCE…

            常用参数:

                -i:交换式

                   -f:强制

            使用实例:

            1、移动/tmp目录下的1.txt文件到/tmp/test文件夹下

[root@localhost tmp]# mv 1.txt /tmp/test

            2、将/tmp目录下1.txt改名为3.txt               

[root@localhost tmp]# mv 1.txt 3.txt
[root@localhost tmp]# ll
总用量 8
-rw-r--r--. 1 root root    0 7月   2 21:53 2.txt
-rw-r--r--. 1 root root    0 7月   2 22:38 3.txt
[root@localhost tmp]#

        1.4.3 rm:remove,删除

              rm [OPTION]… FILE…

                常用参数:

                    -i:交互式

                    -f:强制删除

                    -r:递归

            使用实例:

            1、删除/tmp目录下的2.txt文件

[root@localhost tmp]# rm 2.txt

            2、删除/tmp目下的test文件夹包含其子文件

[root@localhost tmp]# rm -r test/

2、bash的工作特性之命令执行状态返回值和命令行展开所涉及的内容及其示例演示?

      2.1 命令状态返回值:在linux系统上,命令在执行的时候,一般有成功和失败两种状态,如果执行成功将会得到命令执行后的结果和状态返回值0,如果失败将会得到1-255的错误号返回值;可以使用命令【echo $?】查看命令执行完成后的返回值,以下是从网上摘抄的一些错误返回值代表含义:

"OS error code   1:  Operation not permitted"
"OS error code   2:  No such file or directory"
"OS error code   3:  No such process"
"OS error code   4:  Interrupted system call"
"OS error code   5:  Input/output error"
"OS error code   6:  No such device or address"
"OS error code   7:  Argument list too long"
"OS error code   8:  Exec format error"
"OS error code   9:  Bad file descriptor"
"OS error code  10:  No child processes"
"OS error code  11:  Resource temporarily unavailable"
"OS error code  12:  Cannot allocate memory"
"OS error code  13:  Permission denied"
"OS error code  14:  Bad address"
"OS error code  15:  Block device required"
"OS error code  16:  Device or resource busy"
"OS error code  17:  File exists"
"OS error code  18:  Invalid cross-device link"
"OS error code  19:  No such device"
"OS error code  20:  Not a directory"
"OS error code  21:  Is a directory"
"OS error code  22:  Invalid argument"
"OS error code  23:  Too many open files in system"
"OS error code  24:  Too many open files"
"OS error code  25:  Inappropriate ioctl for device"
"OS error code  26:  Text file busy"
"OS error code  27:  File too large"
"OS error code  28:  No space left on device"
"OS error code  29:  Illegal seek"
"OS error code  30:  Read-only file system"
"OS error code  31:  Too many links"
"OS error code  32:  Broken pipe"
"OS error code  33:  Numerical argument out of domain"
"OS error code  34:  Numerical result out of range"
"OS error code  35:  Resource deadlock avoided"
"OS error code  36:  File name too long"
"OS error code  37:  No locks available"
"OS error code  38:  Function not implemented"
"OS error code  39:  Directory not empty"
"OS error code  40:  Too many levels of symbolic links"
"OS error code  42:  No message of desired type"
"OS error code  43:  Identifier removed"
"OS error code  44:  Channel number out of range"
"OS error code  45:  Level 2 not synchronized"
"OS error code  46:  Level 3 halted"
"OS error code  47:  Level 3 reset"
"OS error code  48:  Link number out of range"
"OS error code  49:  Protocol driver not attached"
"OS error code  50:  No CSI structure available"
"OS error code  51:  Level 2 halted"
"OS error code  52:  Invalid exchange"
"OS error code  53:  Invalid request descriptor"
"OS error code  54:  Exchange full"
"OS error code  55:  No anode"
"OS error code  56:  Invalid request code"
"OS error code  57:  Invalid slot"
"OS error code  59:  Bad font file format"
"OS error code  60:  Device not a stream"
"OS error code  61:  No data available"
"OS error code  62:  Timer expired"
"OS error code  63:  Out of streams resources"
"OS error code  64:  Machine is not on the network"
"OS error code  65:  Package not installed"
"OS error code  66:  Object is remote"
"OS error code  67:  Link has been severed"
"OS error code  68:  Advertise error"
"OS error code  69:  Srmount error"
"OS error code  70:  Communication error on send"
"OS error code  71:  Protocol error"
"OS error code  72:  Multihop attempted"
"OS error code  73:  RFS specific error"
"OS error code  74:  Bad message"
"OS error code  75:  Value too large for defined data type"
"OS error code  76:  Name not unique on network"
"OS error code  77:  File descriptor in bad state"
"OS error code  78:  Remote address changed"
"OS error code  79:  Can not access a needed shared library"
"OS error code  80:  Accessing a corrupted shared library"
"OS error code  81:  .lib section in a.out corrupted"
"OS error code  82:  Attempting to link in too many shared libraries"
"OS error code  83:  Cannot exec a shared library directly"
"OS error code  84:  Invalid or incomplete multibyte or wide character"
"OS error code  85:  Interrupted system call should be restarted"
"OS error code  86:  Streams pipe error"
"OS error code  87:  Too many users"
"OS error code  88:  Socket operation on non-socket"
"OS error code  89:  Destination address required"
"OS error code  90:  Message too long"
"OS error code  91:  Protocol wrong type for socket"
"OS error code  92:  Protocol not available"
"OS error code  93:  Protocol not supported"
"OS error code  94:  Socket type not supported"
"OS error code  95:  Operation not supported"
"OS error code  96:  Protocol family not supported"
"OS error code  97:  Address family not supported by protocol"
"OS error code  98:  Address already in use"
"OS error code  99:  Cannot assign requested address"
"OS error code 100:  Network is down"
"OS error code 101:  Network is unreachable"
"OS error code 102:  Network dropped connection on reset"
"OS error code 103:  Software caused connection abort"
"OS error code 104:  Connection reset by peer"
"OS error code 105:  No buffer space available"
"OS error code 106:  Transport endpoint is already connected"
"OS error code 107:  Transport endpoint is not connected"
"OS error code 108:  Cannot send after transport endpoint shutdown"
"OS error code 109:  Too many references: cannot splice"
"OS error code 110:  Connection timed out"
"OS error code 111:  Connection refused"
"OS error code 112:  Host is down"
"OS error code 113:  No route to host"
"OS error code 114:  Operation already in progress"
"OS error code 115:  Operation now in progress"
"OS error code 116:  Stale NFS file handle"
"OS error code 117:  Structure needs cleaning"
"OS error code 118:  Not a XENIX named type file"
"OS error code 119:  No XENIX semaphores available"
"OS error code 120:  Is a named type file"
"OS error code 121:  Remote I/O error"
"OS error code 122:  Disk quota exceeded"
"OS error code 123:  No medium found"
"OS error code 124:  Wrong medium type"
"OS error code 125:  Operation canceled"
"OS error code 126:  Required key not available"
"OS error code 127:  Key has expired"
"OS error code 128:  Key has been revoked"
"OS error code 129:  Key was rejected by service"
"OS error code 130:  Owner died"
"OS error code 131:  State not recoverable"
"MySQL error code 132: Old database file"
"MySQL error code 133: No record read before update"
"MySQL error code 134: Record was already deleted (or record file crashed)"
"MySQL error code 135: No more room in record file"
"MySQL error code 136: No more room in index file"
"MySQL error code 137: No more records (read after end of file)"
"MySQL error code 138: Unsupported extension used for table"
"MySQL error code 139: Too big row"
"MySQL error code 140: Wrong create options"
"MySQL error code 141: Duplicate unique key or constraint on write or update"
"MySQL error code 142: Unknown character set used"
"MySQL error code 143: Conflicting table definitions in sub-tables of MERGE table"
"MySQL error code 144: Table is crashed and last repair failed"
"MySQL error code 145: Table was marked as crashed and should be repaired"
"MySQL error code 146: Lock timed out; Retry transaction"
"MySQL error code 147: Lock table is full;  Restart program with a larger locktable"
"MySQL error code 148: Updates are not allowed under a read only transactions"
"MySQL error code 149: Lock deadlock; Retry transaction"
"MySQL error code 150: Foreign key constraint is incorrectly formed"
"MySQL error code 151: Cannot add a child row"
"MySQL error code 152: Cannot delete a parent row"

    2.2 命令展开内容:  

        ~:展开为用户的主目录,可以通过cd ~回到用户家目录;

        ~USERNAME:展开为指定用户的主目录,可以使用root用户使用cd ~USERNAME进入任意用户目录;

        {}:可承载一个以逗号分隔的列表,并将其展开为多个路径,使用这个符号可以更有效率的创建目录或者文件等……

          例子   /tmp/{a,b} = /tmp/a,/tmp/b

                /tmp/{tom,jerry}/hi = /tmp/tom/hi , /tmp/jerry/hi        

3、请使用命令行展开功能来完成以下练习?

   (1)、创建/tmp目录下的:a_c, a_d, b_c, b_d

[root@localhost tmp]# touch /tmp/{a,b}_{c,d}
[root@localhost tmp]# ll
总用量 16
drwxr-xr-x. 2 root root 4096 7月   2 23:53 a.c
drwxr-xr-x. 2 root root 4096 7月   2 23:53 a.d
-rw-r--r--. 1 root root    0 8月  25 2015 attrtest
drwxr-xr-x. 2 root root 4096 7月   2 23:53 b.c
drwxr-xr-x. 2 root root 4096 7月   2 23:53 b.d

   (2)、创建/tmp/mylinux目录下的:

mylinux/

    ├── bin

    ├── boot

    │   └── grub

    ├── dev

    ├── etc

    │   ├── rc.d

    │   │   └── init.d

    │   └── sysconfig

    │       └── network-scripts

    ├── lib

    │   └── modules

    ├── lib64

    ├── proc

    ├── sbin

    ├── sys

    ├── tmp

    ├── usr

    │   └── local

    │       ├── bin

    │       └── sbin

    └── var

        ├── lock

        ├── log

        └── run

[root@localhost tmp]# mkdir -pv /tmp/mylinux/{bin,boot/grub,dev,etc/>
{rc.d/init.d,sysconfig/network-scripts},lib/modules,lib64,proc,sbin,sys,tmp,usr/local/{bin,sbin},var/{lock,log,run}}

4、文件的元数据信息有哪些,分别表示什么含义,如何查看?如何修改文件的时间戳信息?

   使用 stat file命令可查看文件的元数据信息,元数据里面大致有以下这些信息:

[root@localhost tmp]# stat 1.txt 
  File: "1.txt"
  Size: 7872      Blocks: 16         IO Block: 4096   普通文件
Device: 802h/2050dInode: 389383      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-07-03 00:33:53.420132550 +0800
Modify: 2016-07-03 00:34:29.415134142 +0800
Change: 2016-07-03 00:34:29.417134044 +0800
[root@localhost tmp]#

    File:文件名

    Size:文件大小

    Blocks:块大小

    IO Block:?

    Device:?

    Inode:indoe号

    Links:连接数

    Access:文件权限 

    Uid:属主和属主ID 

    Gid:属组和属组ID

     Access: 2016-07-03 00:33:53.420132550 +0800:访问时间,atime,读取文件内容

     Modify: 2016-07-03 00:34:29.415134142 +0800:修改时间,mtime,改变文件内容(数据)

    Change: 2016-07-03 00:34:29.417134044 +0800:改变时间, ctime,元数据发生改变   

5、如何定义一个命令的别名,如何在命令中引用另一个命令的执行结果?

    5.1、命令别名(alias)

        通过alias命令实现

          (1)alias:显示当前shell进程所有可用的命令别名;

          (2)alias NAME='VALUE':定义别名NAME,其相当于执行命令VALUE;

          注意:在命令行中定义的别名,仅对当前shell进程有效;如果想永久有效,要定义在配置文件中;

                 仅对当前用户:~/.bashrc

               对所有用户有效:/etc/bashrc

        使用实例:

[root@localhost tmp]# alias gohome="cd ~"
[root@localhost tmp]# gohome 
[root@localhost ~]# pwd
/root

    5.2 在命令中引用另一个命令的执行结果

        使用管道符"|"可以实现该功能,例如我想提取/etc/passwd的前三列内容,并以UID从小到大进行排序显示:

[root@localhost ~]# cut -d: -f1-3 /etc/passwd | sort -n -k 3 -t:
root:x:0
bin:x:1
daemon:x:2
adm:x:3
lp:x:4
sync:x:5
shutdown:x:6
halt:x:7
mail:x:8
uucp:x:10
operator:x:11
games:x:12
gopher:x:13
ftp:x:14
mysql:x:27
rpcuser:x:29
rpc:x:32
ntp:x:38
gdm:x:42
apache:x:48
webalizer:x:67
haldaemon:x:68
vcsa:x:69
tcpdump:x:72
sshd:x:74
dbus:x:81

6、显示/var目录下所有以l开头,以一个小写字母结尾,且中间至少出现一位数字(可以有其它字符)的文件或目录?

[root@localhost ~]# ls -aR /var/1*[[:lower:]]

7、显示/etc目录下,以任意一个数字开头,且以非数字结尾的文件或目录?

[root@localhost ~]# ls -aR /etc/[[:digit:]]*[^[:digit:]]

8、显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录?

ls -aR /etc/[^[:alpha:]][[:alpha:]]*

9、在/tmp目录下创建以tfile开头,后跟当前日期和时间的文件,文件名形如:tfile-2016-05-27-09-32-22?

[root@localhost tmp]# touch /tmp/tfile-$(date +'%Y-%m-%d-%H-%M-%S')
[root@localhost tmp]# ll
总用量 0
-rw-r--r--. 1 root root 0 8月  25 2015 attrtest
-rw-r--r--. 1 root root 0 7月   3 02:42 tfile-2016-07-03-02-42-35
[root@localhost tmp]#

10、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中?

[root@localhost ~]# cp -av /etc/p*[^[:digit:]] /tmp/mytest1

11、复制/etc目录下所有以.d结尾的文件或目录至/tmp/mytest2目录中?

[root@localhost ~]# cp -av /etc/*.d /tmp/mytest2

12、复制/etc/目录下所有以l或m或n开头,以.conf结尾的文件至/tmp/mytest3目录中?

[root@localhost ~]# cp -av /etc/{1,m,n}*.conf /tmp/mytest3

  不足总结:

       1、在描述某个命令的时候,应减少一些不常见参数的描述,多增加一些实用的常用参数组合实例,避免华而不实;

       2、在一些理论题,还是缺少自己对该技术的个人见解,只能摘抄马哥和网上的理论知识作为答案回答,暂时只能加快学习速度增加知识广度,后期靠练习之前的作业和复习笔记、阅读参考书籍等增加个人的理论水平;

      3、语言组织能力很差,写出来的博客给人一种断断续续,无法首尾呼应,有种逻辑混乱的感觉,恩。。。。暂时只能向这方面比较强的人进行模仿,争取后期能够形成自己的一种有序的风格;

原创文章,作者:Net21_仲樂,如若转载,请注明出处:http://www.178linux.com/21503

(0)
上一篇 2016-07-04 11:34
下一篇 2016-07-04 11:34

相关推荐

  • Nginx配置进阶

    目录 ngx_http_rewrite_module模块 ngx_http_gzip_module模块 ngx_http_fastcgi_module模块 ngx_http_ssl_module模块 ngx_http_referer_module模块 ngx_http_rewrite_module模块 将用户某一次请求的URI当中的字符串是不是能够被我们给出…

    Linux干货 2016-11-05
  • nginx

    nginx: master/worker master:配置文件分析和加载、管理worker、平滑升级; worker:处理用户请求; cache loader, cache manager:缓存加载和缓存管理 user Syntax: user user [group];        …

    Linux干货 2017-06-19
  • vim、定时任务、脚本初步应用及详解

    1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#;   ~]#cp  /etc/rc.d/rc.sysinit   /tmp   在末行模式下输入:%s@^[[:space:]]\+[^[:space:]]@#&@g     &:匹配模式找到的全部…

    2016-12-04
  • 基于centos7的http的应用

     练习:分别使用CentOS 7和CentOS 6实现以下任务         (1) 配置三个基于名称的虚拟主机;             (a) discuzX             …

    Linux干货 2016-10-12
  • Shell编程if语句

    Shell编程if语句 条件选择if语句(#if输入keywork) 选择执行: 注意:if语句可嵌套 单分支 if 判断条件(#如果为真执行下一条);then 条件为真的分支代码 fi(结尾) 双分支 if 判断条件; then 条件为真的分支代码 else 条件为假的分支代码 fi if 语句 多分支 if 判断条件1; then 条件为真的分支代码 e…

    2018-01-01
  • Linux 基础知识(六.二)

    1、复制/etc/rc.d/rc.sysinit至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加# [root@server01 tmp]# cp /etc/rc.d/rc.sysinit /tmp/ [root@server01 tmp]# sed -n "s@^[[:space:]]\+@#&@…

    Linux干货 2016-11-14

评论列表(2条)

  • 马哥教育
    马哥教育 2016-07-04 13:49

    写的很好,排版可以多关注一下,要理解你在网上找到的答案哦,加油

    • Net21_仲樂
      Net21_仲樂 2016-07-06 22:43

      @马哥教育好的,争取消化别人的东西变成自己的东西!