Linux系统命令01 --- 系统命令精讲

 

Linux系统管理01 –系统命令精讲

 

 

 

 

 

 

 

Linux命令的分类

 

  1. 内部命令:属于shell解释器的一部分
  2. 外部命令:独立于shell解释器之外的程序

 

 

 

 

 

Linux命令格式:

 

Linux命令的通用格式: 命令字  [选项]  [参数]

 

选项:用于调节命令的具体作用

 

“-”引导短格式选项,例如“ls  -a”

 

“--”引导长格式选项,例如“ls  -help”

 

l  注意:多个段格式选项可以合并,例如“ls  -alh” ,但是多个长格式选项不能合并

 

参数:命令的对象,例如文件名,目录等

 

 

 

 

 

Linux命令快捷键

 

Tab键:自动补齐文件名,命令;按两次tab键,系统将输出可用的所有名称列表。

 

反斜杠:强行换行

 

Ctrl + U:快速删除光标之前的所有字符(可视为剪切)

 

Ctrl + K: 快速删除光标及光标之后的所有字符(可视为剪切)

 

Ctrl + Y:粘贴刚才所剪切的字符

 

Ctrl + L:清屏

 

Ctrl + C:结束当前正在执行的命令

 

Ctrl + D:shell提示中注销关闭,类似于输入exit

 

Ctrl + A:把光标移动到行首,类似于Home

 

Ctrl + E:把光标移动到行尾,类似于End

 

Ctrl + Z:转入后台运行

 

Ctrl + R在历史命令中查找

 

 

 

 

 

 

 

 

 

 

 

命令:

 

 

 

Type:查看命令是内部命令还是外部命令

 

例如:

 

[root@localhost ~]# type cd

 

cd shell 内嵌 (由此可见该命令cd为内部命令)

 

 

 

[root@localhost ~]# type cd

 

cd shell 内嵌(由此可见cd 是内部命令)

 

 

 

[root@localhost ~]# type pwd

 

pwd shell 内嵌)(pwd是内部命令)

 

 

 

[root@localhost ~]# type ls

 

ls `ls --color=auto' 的别名(ls没有内嵌,是内部命令

 

 

 

[root@localhost ~]# type ifconfig

 

ifconfig /usr/sbin/ifconfigifconfig没有内嵌,是外部命令

 

 

 

[root@localhost ~]# type du

 

du 已被哈希 (/usr/bin/du)du没有内嵌是外部命令)

 

 

 

 

 

 

 

cd: 用于切换目录

 

例如

 

cd - :返回上级目录

 

[root@localhost ~]# cd abc

 

[root@localhost ~]# cd /liangjian/liyunlong/weiheshang/duanpeng

 

 

 

l  补充:目录路径分为绝对路径和相对路径,以“/”为起始的是绝对路径,不已反斜杠为起始的是相对路径

 

 

 

 

 

 

 

帮助命令:

 

  1. help内部命令帮助,查看bash内部命令的帮助

 

用法1:help  [内部命令]

 

[root@localhost ~]#help  cd

 

用法2:[命令]  --help

 

及命令的“--help”选项,适用于大多数外部命令

 

[root@localhost ~]# ls  --help

 

 

 

 

 

 

 

  1. man用来提供在线帮助,使用权是所有用户。在Linux系统中存储者一部联机使用的手册,以供用户在终端上查找。使用man命令可以调阅其中的帮助信息,非常方便

 

l  用法: man 命令字

 

示例:[root@localhost ~]# man  ls

 

l  参数:

 

-C config-file: 指定设定文件man.conf,缺省值是/ect/man.conf.

 

[root@localhost ~]#man 1 ma

 

[root@localhost ~]#man 7 man

 

l  代号 代表内容

 

1使用者在shell中可以操作的指令或可执行档

 

2系统核心可以呼叫的函数与工具等

 

3一些常用的函数(function)与函数库(library)大部分是C的函数库(libc)

 

4装置档案的说明,通常在/dev下的档案

 

5设定档或是某些档案的格式

 

6游戏(gmans)

 

7惯例与协定等,例如Linux档案系统、网络协定、ASCII code等等的说明

 

8系统管理员可用的管理命令

 

9跟kernel有关的文件

 

l  由于手册页man page是使用less程序来查看的(可以方便地使屏幕上翻下翻)所以在man page里可以使用less的所有选项。

 

 

 

 

 

 

 

Lslist)命令详解

 

 

 

l  作用:

 

列表显示目录内的文件及目录,结合不同的选项实现不同的作用

 

l  格式:

 

ls [选项]  目录或文件名

 

l  常用格式选项:

 

-l:以长格式(long)显示文件和目录的列表

 

-a: 显示所有子目录和文件信息

 

-A: 与“-a”类似,但有两个特殊隐藏目录“.”和“..”不显示

 

-d: 显示目录(directory)本身的属性,长与“–l”同时使用

 

-h:以更人性化(huaman)的方式显示出目录或文件的大小,常与“-l”同时使用

 

-R: 以递归(recursive)的方式显示目录中的所有内容

 

l  示例

 

                       

 

 

 

 

 

 

 

补充:文件名前加“.”“..”的一般为隐藏文件,“.”当前目录的隐藏文件“..”上级目录的隐藏文件

 

 

 

 

 

 

 

pwd: 显示当前工作目录的路径

 

 

 

 

 

 

 

dudisk usarge)命令详解

 

 

 

 

 

 

 

 

 

 

 

1、请用命令查出ifconfig命令程序的绝对路径

[root@localhost ~]# which ifconfig

/usr/sbin/ifconfig

 

[root@localhost ~]# which ipconfig

/usr/bin/which: no ipconfig in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)

 

 

 

 

 

2、请用命令展示以下命令哪些是内部命令,哪些是外部命令?(cd \ pwd \ ls \ ifconfig \ du)

[root@localhost ~]# type cd

cd 是 shell 内嵌 (由此可见该命令cd为内部命令)

 

[root@localhost ~]# type cd

cd 是 shell 内嵌(由此可见cd 是内部命令)

 

[root@localhost ~]# type pwd

pwd 是 shell 内嵌)(pwd是内部命令)

 

[root@localhost ~]# type ls

ls 是 `ls --color=auto' 的别名(ls没有内嵌,是内部命令

 

[root@localhost ~]# type ifconfig

ifconfig 是 /usr/sbin/ifconfig(ifconfig没有内嵌,是外部命令

 

[root@localhost ~]# type du

du 已被哈希 (/usr/bin/du)(du没有内嵌是外部命令)

 

 

 

 

 

3、请在/下创建目录abc

[root@localhost ~]# mkdir /abc

[root@localhost ~]# ls /

abc  boot  etc   lib    media  opt   root  sbin  sys  usr

bin  dev   home  lib64  mnt    proc  run   srv   tmp  var

 

   请在/下创建目录/liangjian/liyunlong/weiheshang/duanpeng

 

[root@localhost ~]# mkdir -pv /liangjian/liyunlong/weiheshang/duanpeng

mkdir: 已创建目录 "/liangjian"

mkdir: 已创建目录 "/liangjian/liyunlong" {}

mkdir: 已创建目录 "/liangjian/liyunlong/weiheshang"

mkdir: 已创建目录 "/liangjian/liyunlong/weiheshang/duanpeng"

[root@localhost ~]# ls /

abc  boot  etc   liangjian  lib64  mnt  proc  run   srv  tmp  var

bin  dev   home  lib        media  opt  root  sbin  sys  usr

[root@localhost ~]#

 

 

   请在/abc下一次创建1000个目录,名字自己拟定。

 

[root@localhost ~]# cd /abc/

[root@localhost abc]# mkdir {1..1000}

[root@localhost abc]# ls

1     146  194  241  29   337  385  432  480  528  576  623  671  719  767  814  862  91   958

10    147  195  242  290  338  386  433  481  529  577  624  672  72   768  815  863  910  959

100   148  196  243  291  339  387  434  482  53   578  625  673  720  769  816  864  911  96

1000  149  197  244  292  34   388  435  483  530  579  626  674  721  77   817  865  912  960

101   15   198  245  293  340  389  436  484  531  58   627  675  722  770  818  866  913  961

102   150  199  246  294  341  39   437  485  532  580  628  676  723  771  819  867  914  962

103   151  2    247  295  342  390  438  486  533  581  629  677  724  772  82   868  915  963

104   152  20   248  296  343  391  439  487  534  582  63   678  725  773  820  869  916  964

105   153  200  249  297  344  392  44   488  535  583  630  679  726  774  821  87   917  965

106   154  201  25   298  345  393  440  489  536  584  631  68   727  775  822  870  918  966

107   155  202  250  299  346  394  441  49   537  585  632  680  728  776  823  871  919  967

108   156  203  251  3    347  395  442  490  538  586  633  681  729  777  824  872  92   968

109   157  204  252  30   348  396  443  491  539  587  634  682  73   778  825  873  920  969

11    158  205  253  300  349  397  444  492  54   588  635  683  730  779  826  874  921  97

110   159  206  254  301  35   398  445  493  540  589  636  684  731  78   827  875  922  970

111   16   207  255  302  350  399  446  494  541  59   637  685  732  780  828  876  923  971

112   160  208  256  303  351  4    447  495  542  590  638  686  733  781  829  877  924  972

113   161  209  257  304  352  40   448  496  543  591  639  687  734  782  83   878  925  973

114   162  21   258  305  353  400  449  497  544  592  64   688  735  783  830  879  926  974

115   163  210  259  306  354  401  45   498  545  593  640  689  736  784  831  88   927  975

116   164  211  26   307  355  402  450  499  546  594  641  69   737  785  832  880  928  976

117   165  212  260  308  356  403  451  5    547  595  642  690  738  786  833  881  929  977

118   166  213  261  309  357  404  452  50   548  596  643  691  739  787  834  882  93   978

119   167  214  262  31   358  405  453  500  549  597  644  692  74   788  835  883  930  979

12    168  215  263  310  359  406  454  501  55   598  645  693  740  789  836  884  931  98

120   169  216  264  311  36   407  455  502  550  599  646  694  741  79   837  885  932  980

121   17   217  265  312  360  408  456  503  551  6    647  695  742  790  838  886  933  981

122   170  218  266  313  361  409  457  504  552  60   648  696  743  791  839  887  934  982

123   171  219  267  314  362  41   458  505  553  600  649  697  744  792  84   888  935  983

124   172  22   268  315  363  410  459  506  554  601  65   698  745  793  840  889  936  984

125   173  220  269  316  364  411  46   507  555  602  650  699  746  794  841  89   937  985

126   174  221  27   317  365  412  460  508  556  603  651  7    747  795  842  890  938  986

127   175  222  270  318  366  413  461  509  557  604  652  70   748  796  843  891  939  987

128   176  223  271  319  367  414  462  51   558  605  653  700  749  797  844  892  94   988

129   177  224  272  32   368  415  463  510  559  606  654  701  75   798  845  893  940  989

13    178  225  273  320  369  416  464  511  56   607  655  702  750  799  846  894  941  99

130   179  226  274  321  37   417  465  512  560  608  656  703  751  8    847  895  942  990

131   18   227  275  322  370  418  466  513  561  609  657  704  752  80   848  896  943  991

132   180  228  276  323  371  419  467  514  562  61   658  705  753  800  849  897  944  992

133   181  229  277  324  372  42   468  515  563  610  659  706  754  801  85   898  945  993

134   182  23   278  325  373  420  469  516  564  611  66   707  755  802  850  899  946  994

135   183  230  279  326  374  421  47   517  565  612  660  708  756  803  851  9    947  995

136   184  231  28   327  375  422  470  518  566  613  661  709  757  804  852  90   948  996

137   185  232  280  328  376  423  471  519  567  614  662  71   758  805  853  900  949  997

138   186  233  281  329  377  424  472  52   568  615  663  710  759  806  854  901  95   998

139   187  234  282  33   378  425  473  520  569  616  664  711  76   807  855  902  950  999

14    188  235  283  330  379  426  474  521  57   617  665  712  760  808  856  903  951

140   189  236  284  331  38   427  475  522  570  618  666  713  761  809  857  904  952

141   19   237  285  332  380  428  476  523  571  619  667  714  762  81   858  905  953

142   190  238  286  333  381  429  477  524  572  62   668  715  763  810  859  906  954

143   191  239  287  334  382  43   478  525  573  620  669  716  764  811  86   907  955

144   192  24   288  335  383  430  479  526  574  621  67   717  765  812  860  908  956

145   193  240  289  336  384  431  48   527  575  622  670  718  766  813  861  909  957

 

 

 

 

 

4、请用绝对路径方式切换到/liangjian/liyunlong/weiheshang/duanpeng 目录下

并用pwd查看当前的路径,请用上级目录名".."方式切换到 /liangjian/liyunlong下

 

[root@localhost ~]# cd /liangjian/liyunlong/weiheshang/duanpeng

[root@localhost duanpeng]# pwd

/liangjian/liyunlong/weiheshang/duanpeng

[root@localhost duanpeng]# cd ..

[root@localhost weiheshang]# cd ..

[root@localhost liyunlong]#

 

 

 

5、请一次删除/abc下一次创建的1000个目录,请在/abc下用touch再创建20个以stu开头的普通可读文档,文档后缀为.txt

[root@localhost abc]# rm -rf *

[root@localhost abc]# ls

[root@localhost abc]# touch stu{1..20}.txt

[root@localhost abc]# ls

stu10.txt  stu13.txt  stu16.txt  stu19.txt  stu2.txt  stu5.txt  stu8.txt

stu11.txt  stu14.txt  stu17.txt  stu1.txt   stu3.txt  stu6.txt  stu9.txt

stu12.txt  stu15.txt  stu18.txt  stu20.txt  stu4.txt  stu7.txt

 

 

6、请用cp命令将/boot/目录下以vmlinuz开头的文件拷贝到/abc下,并以查看他们占磁盘的空间大小。

 

[root@localhost ~]# cp -r /boot/vmlinuz* /abc

[root@localhost abc]# du -sh vmlinuz*

4.8M         vmlinuz-0-rescue-7f8ba12e352e4670a26f091cb7a2014d

4.8M         vmlinuz-3.10.0-229.el7.x86_64

 

 

7、将其中一个vmlinuz开头的文件改名为kgc,另外一个剪切到/tmp目录下。

[root@localhost abc]# mv vmlinuz-3.10.0-229.el7.x86_64 kgc

[root@localhost abc]# ll

总用量 9824

-rwxr-xr-x. 1 root root 5029136 7月  23 20:29 kgc

-rwxr-xr-x. 1 root root 5029136 7月  23 20:29 vmlinuz-0-rescue-7f8ba12e352e4670a26f091cb7a2014d

 

[root@localhost abc]# mv vmlinuz-0-rescue-7f8ba12e352e4670a26f091cb7a2014d /tmp

[root@localhost abc]# cd /tmp

[root@localhost tmp]# ls

ssh-gkUsQy6ctgiQ                                   vmware-root

systemd-private-7pBegE                             yum_save_tx.2019-07-20.16-30.4THohH.yumtx

systemd-private-vB8rF2                             yum_save_tx.2019-07-23.10-14.GP_1hD.yumtx

systemd-private-XG8Fwi                             yum_save_tx.2019-07-23.11-48.XjHgD7.yumtx

vmlinuz-0-rescue-7f8ba12e352e4670a26f091cb7a2014d  yum_save_tx.2019-07-23.15-57.84t_6f.yumtx

 

 

 

8、查看/tmp/目录下以vmlinuz开头文件的详细状态信息。

 

[root@localhost tmp]# stat vmlinuz*

  文件:"vmlinuz-0-rescue-7f8ba12e352e4670a26f091cb7a2014d"

  大小:5029136        块:9824       IO 块:4096   普通文件

设备:fd00h/64768d      Inode:3084001     硬链接:1

权限:(0755/-rwxr-xr-x)  Uid:(    0/    root)   Gid:(    0/    root)

环境:unconfined_u:object_r:default_t:s0

最近访问:2019-07-23 20:29:34.145052906 +0800

最近更改:2019-07-23 20:29:34.175053961 +0800

最近改动:2019-07-23 20:32:16.023831015 +0800

创建时间:-

 

 

 

9、用find命令查找/tmp目录下以vmlinuz开头及大小超过1M的文件

[root@localhost ~]# find /tmp -size +1M -a -name "vmlinuz*"

/tmp/vmlinuz-0-rescue-7f8ba12e352e4670a26f091cb7a2014d

[root@localhost ~]#

 

posted on 2019-07-24 20:49  庆睿  阅读(952)  评论(0编辑  收藏  举报