一、获得帮助的方式

 1.   更新帮助信息  ----  mandb

[kiosk@foundation60 Desktop]$ mandb

 2.   查看命令用途 ----- whatis

[kiosk@foundation60 Desktop]$ whatis  cd

 3.  查看命令的帮助 ------- 命令  --help

[kiosk@foundation60 Desktop]$ ls --help

       命令的帮助中   []    选加

                                  ...   加的个数任意

                                  <>    必须加入

 4.   查看命令的帮助 ------ man  

[kiosk@foundation60 Desktop]$ man cd

   "q"   退出命令的帮助

 

二、文件管理

1.新建

(1)新建文件

  touch

[kiosk@foundation60 Desktop]$ touch file

  注意:touch默认用来建立文件,同时也可以修改文件的时间戳

(2)新建目录

  mkdir            dir(文件夹)

  mkdir    -p       dir1/dir2/dir3(目录)

            "注意:-p的意思是创建路径"

[kiosk@foundation60 Desktop]$ mkdir westos
[kiosk@foundation60 Desktop]$ mkdir -p linux/redhat/student

2、删除

(1)删除文件

  rm    - f     file1 file2 file3

[kiosk@foundation60 Desktop]$ rm -f file

(2)删除目录

  rm -fr dir   

  注意: -f ----- force 强制删除不提示

               -r -------recursive 递归删除

 [kiosk@foundation60 Desktop]$ rm -fr westos

  rm -fr dir*    删除dir中的所有文件

[kiosk@foundation60 Desktop]$  rm -fr *

3、复制  ---------复制是按照模板新建的过程

(1)复制文件

  cp   file   dest             ##复制单个文件

  cp    file1 file2 file3   dir        ##复制多个文件到指定目录中

[kiosk@foundation60 Desktop]$ cp  file  linux
[kiosk@foundation60 Desktop]$ cp file2 file3 westos1

(2)复制目录

  cp    -r    sorcedir1 sourcedir2        destdir      ##复制目录到目录中

[kiosk@foundation60 Desktop]$ cp -r westos1 westos2

4、移动

      "注意": 同磁盘文件移动重命名(比如,都是文件或者都是目录)

                     不同磁盘文件移动复制后删除(比如,文件移动到目录下)

  mv   file   file1      ##相当于文件的重命名

[kiosk@foundation60 Desktop]$ mv  file redhat

  mv    file    dir       ##将文件移动到目录里

[kiosk@foundation60 Desktop]$ mv redhat westos

  mv     dir    dir1    ##目录的重命名

[kiosk@foundation60 Desktop]$ mv westos linux

5、文件查看

  (1)cat               file   ##显示文件全部内容

                        -n      file   ##显示文件内容并在每行前加入行号

                        -b      file   ##显示文件内容并在每行前加入行号,但是不包括空白行

[kiosk@foundation60 Desktop]$ cat file
hello

word!
[kiosk@foundation60 Desktop]$ cat -n file
     1	hello
     2
     3	word!
[kiosk@foundation60 Desktop]$ cat -b file
     1	hello

     2	word!

  (2) less                       file        ##分页浏览

                           上|下                   ##逐行查看

                     Pgup|Pgdn               ##逐页查看

                        /关键字                  ##搜索关键字并高亮显示,“n”向下匹配一个关键字,“N”向上匹配一个关键字

[kiosk@foundation60 Desktop]$ less /etc/passwd

 (3) head           file              ##显示文件前10行

            head   -n  3   file             ##显示文件前3行

(4)  tail           file                  ##显示文件后10行

            tail   -n  3   file                ##显示文件后3行

6、文件修改

(1)图形工具

          gedit file

(2)vim

          vim  file

7、文件统计

 (1) wc        file             ##统计文件(显示行数,词数以及字节数)

[kiosk@foundation60 Desktop]$ wc /etc/passwd
  39   70 2005 /etc/passwd

  (2)wc    -c        file     ##统计文件的字节数

[kiosk@foundation60 Desktop]$ wc -c  /etc/passwd
2005 /etc/passwd

  (3)wc    -m       file     ##统计文件的字符数

[kiosk@foundation60 Desktop]$ wc -m  /etc/passwd
2005 /etc/passwd

                       "注意:一个汉字两个字节,是一个字符;一个字母占一个字节,是一个字符"

  (4)wc    -w      file     ##统计文件的词数

             wc     -l       file     ##统计文件的行数

[kiosk@foundation60 Desktop]$ wc -w  /etc/passwd
70 /etc/passwd
[kiosk@foundation60 Desktop]$ wc -l  /etc/passwd
39 /etc/passwd

     注意:

                  以上统计均统计最后的转义符

    (5) wc  -L file     ##统计文件的最长行的长度(即字节数)

[kiosk@foundation60 Desktop]$ wc -L  /etc/passwd
85 /etc/passwd

                      "注意:统计长度时不统计最后的转义符"

8、文件路径

(1)相对路径

          相对与当前系统位置,文件名称的简写,此名称前会自动添加“pwd”命令的输出

          相对路径文件名称前不会出现“/”

(2)绝对路径

           文件在系统中的真实位置,在任何情况下都可以使用

           绝对路径一定以“/”开头

(3)linux 的系统结构及目录分类

          linux是一个倒数型结构,顶级目录“/”是根目录

         “/”下的二级命令:

                /bin      ##系统常规命令

                /boot     ##系统启动目录

                /dev      ##设备影射文件

                /etc      ##系统配置文件

                /home     ##普通用户家目录

                /lib      ##32位函数库

                /lib64    ##64位函数库

                /media    ##光盘临时挂载

                /mnt      ##手动临时挂载(挂载u盘)

                /run      ##自动临时挂载

               /opt      ##第三方软件安装位置

               /proc     ##系统进程信息和运行信息

               /root     ##超级用户家目录

              /sbin     ##系统管理命令

              /srv      ##系统数据

              /sys      ##内核相关调式

              /tmp      ##临时文件

              /usr      ##用户相关设定

              /var      ##系统数据

(4)关于系统路径的命令

         pwd               ##显示当前路径

[kiosk@foundation60 Desktop]$ pwd

9、显示

(1)ls        dir            ##显示路径信息

(2)ls    -l       file       ##显示目标属性(文件或者目录)

[kiosk@foundation60 Desktop]$ ls -l file
-rw-r--r-- 1 kiosk kiosk 7 Oct  4 05:56 file
[kiosk@foundation60 Desktop]$ ls -l linux
total 0
-rw-r--r-- 1 kiosk kiosk 0 Oct  4 04:21 redhat

(3)ls    -d                  ##显示当前这个目录本身

[kiosk@foundation60 Desktop]$ ls -d
.

(4)ls   -R    dir              ##递归显示目录中的所有内容

[kiosk@foundation60 Desktop]$ ls -R
.:
file  linux  文件管理代码

./linux:
redhat

(5)ls    -a                    ##显示所有文件包括以"."开头的隐藏文件

[kiosk@foundation60 Desktop]$ ls -a
.  ..  file  linux  文件管理代码

(6)ls     -ad                          ##同上

[kiosk@foundation60 Desktop]$ ls  -ad
.

(7)ls    -ad     .*              ##显示所有隐藏文件

[kiosk@foundation60 Desktop]$ ls -ad  .*
.  ..

(8)ls     .*                   ##显示以"."开头的目录(路径)的路径信息

[kiosk@foundation60 Desktop]$ ls .*
.:
file  linux  文件管理代码

..:
anaconda-ks.cfg  Documents  Music     Public     Videos
Desktop          Downloads  Pictures  Templates

10、路径切换

(1)cd     ~                ##进入当前用户家目录

          cd   /mnt             ##进入mnt目录

          cd    ..                 ##进入到当前目录的上一级目录

           cd    -                 ##当前目录和进入当前目录之前所在目录之间的切换

(2) ~                        ##当前用户家目录

          ~username      ##指定用户家目录

          ~+                    ##当前目录

          ~-                     ##当前目录之前的目录

 

11、文件批处理

(1)*                    ##匹配0~任意字符

(2)?                  ##匹配单个字符

(3)[[:alpha:]]       ##匹配单个字母

          [[:lower:]]   ##匹配单个小写字符

          [[:uper:]]           ##匹配单个大写字符

          [[:digit:]]           ##匹配单个数字

          [[:punct:]]          ##匹配的那个符号

          [[:space:]]        ##匹配单个空格

          [[1][2]]              ##匹配1或者2

  注意:特殊意义的符号要加上"",进行全部转译( 例如: &,*,$及空格等)

(4){}                  ##精确匹配

[kiosk@foundation60 Desktop]$ touch file{1..3}
[kiosk@foundation60 Desktop]$ touch file{a..c}

 (5) []                ##模糊匹配

         [a-c]           ##a或者b或者c

         [1-3]

         [!a-c]            ##不是a也不是b也不是c

         [^a-c]          ##不是a也不是b也不是c

 

   

 

10-04 20:25