################################

####### 一.linux系统结构 ########

################################


linux是一个倒树结构

linux中所有的东西都是文件  “一切皆文件”

这些文件都在系统顶级目录“/” /就是根目录

/目录以下为二级目录这些目录都是系统装机时系统自动建立的


二级目录的作用

/bin    ##二进制可执行文件也就是系统命令

/sbin   ##系统管理命令存放位置

/boot   ##启动分区,负责系统启动

/dev    ##设备管理文件

/etc    ##大多数系统管理文件

/home   ##普通用户的家目录

/lib    ##32位系统库文件存放位置

/lib64  ##64位系统库文件存放位置

/media  ##系统临时设备挂载点                                                                                 

/mnt    ##系统临时设备挂载点

/run    ##系统临时设备挂载点

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

/proc   ##系统信息

/root   ##超级用户家目录

/srv,/var      ##系统数据

/sys    ##系统管理,主要是关于内核的

/tmp    ##系统临时文件存放位置

/usr    ##系统用户相关信息数据及用户自定义软件存放位置


##end##


########################

#### 二.文件的寻址 ######

########################


绝对路径

文件在系统的真实位置,文件名字以“/”开头

相对路径

文件相对与当前所在位置的一个名字的简写,这个名字不会以/开头,而且名字会自动添加pwd显示的值

[root@localhost Desktop]# pwd

/root/Desktop

以“/”开头的为绝对路径;否则是相对路径

##end##


#######################

#### 三.文件的管理 #####

#######################


##### 1.touch 建立文件或修改文件时间戳 ####


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

       touch [OPTION...] FILE…


stat file:显示文件的时间戳

[root@localhost Desktop]# stat file

  File: `file'

  Size: 0         Blocks: 0          IO Block: 4096   regular empty file

Device: 802h/2050d Inode: 655461      Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2017-09-27 19:20:18.303028677 -0700

Modify: 2017-09-27 19:20:17.279028473 -0700

Change: 2017-09-27 19:20:17.279028473 -0700


三个时间戳:

       accesstime:访问时间,简写为atime,读取文件内容

       modifytime:修改时间,mtime, 改变文件内容(数据)

       changetime:改变时间,ctime, 元数据发生改变


touch file    ##创建文件

    -a:only atime  

    -m:only mtime

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

[root@localhost Desktop]# stat file

  File: `file'

  Size: 0         Blocks: 0          IO Block: 4096   regular empty file

Device: 802h/2050d Inode: 655461      Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2017-09-27 19:20:18.303028677 -0700

Modify: 2017-09-27 19:20:17.279028473 -0700

Change: 2017-09-27 19:20:17.279028473 -0700

[root@localhost Desktop]# touch -a file

[root@localhost Desktop]# stat file

  File: `file'

  Size: 0         Blocks: 0          IO Block: 4096   regular empty file

Device: 802h/2050d Inode: 655461      Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2017-09-27 19:21:00.384028955 -0700

Modify: 2017-09-27 19:20:17.279028473 -0700

Change: 2017-09-27 19:20:59.369028217 -0700

[root@localhost Desktop]# touch -m file

[root@localhost Desktop]# stat file

  File: `file'

  Size: 0         Blocks: 0          IO Block: 4096   regular empty file

Device: 802h/2050d Inode: 655461      Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2017-09-27 19:21:09.274028703 -0700

Modify: 2017-09-27 19:21:08.261028482 -0700

Change: 2017-09-27 19:21:08.261028482 -0700



##### 2.mkdir 建立目录 ####


mkdir【OPTION】 /path/to/somewhere

mkdir directory     ##创建目录

    -p    ##存在不报错,且可自动创建所需的各目录;

    -v:  ##显示详细信息

    -mMOOE:创建目录时直接指定权限;

[root@localhost Desktop]# mkdir -vp westos/hello1/hello2

mkdir: created directory `westos/hello1'

mkdir: created directory `westos/hello1/hello2'


#### 3.rm 删除目录或文件 ####


-f       ##强行删除不提示

-r       ##递归删除目录

[root@localhost Desktop]# rm westos

rm: cannot remove `westos': Is a directory

[root@localhost Desktop]# rm -fr westos

#### 4.cat|head|tail 查看文件内容 ####


cat|head|tail        ##文件内容查看命令


cat   

Usage: cat [OPTION]... [FILE]...

  -A, --show-all           equivalent to -vET   

  -b, --number-nonblank    number nonempty output lines   ##不给空行编号

  -e                       equivalent to -vE

  -E, --show-ends          display $ at end of each line

  -n, --number             number all output lines        ##给空行编号

  -s, --squeeze-blank      suppress repeated empty output lines

  -t                       equivalent to -vT

  -T, --show-tabs          display TAB characters as ^I

  -u                       (ignored)

  -v, --show-nonprinting   use ^ and M- notation, except for LFD and TAB

      --help     display this help and exit

      --version  output version information and exit


[root@localhost Desktop]# cat -A a

sfjsfksdfjls$

dfdsg$

dgdgcx gdffkjk$

hello world$

!!!!! kdsfkjf$

[root@localhost Desktop]# cat a

sfjsfksdfjls

dfdsg

dgdgcx gdffkjk

hello world

!!!!! kdsfkjf

[root@localhost Desktop]# cat -b a

     1sfjsfksdfjls

     2dfdsg

     3dgdgcx gdffkjk

     4hello world

     5!!!!! kdsfkjf


     6sss



head 

Usage: head [OPTION]... [FILE]...

-n, --lines=[-]K         print the first K lines instead of the first 10; #默认前十行

[root@localhost Desktop]# head -n2 a

sfjsfksdfjls

dfdsg

                       

tail

Usage: tail [OPTION]... [FILE]...

-n, --lines=K            output the last K lines, instead of the last 10;#默认后十行

                           or use -n +K to output lines starting with the Kth


[root@localhost Desktop]# tail -n2 a


sss



#### 5.vim 文本方式编辑文件 ####


vim filename 进入到命令模式

命令模式不能编辑文件,如果要编辑文件要进入插入模式

按"i"进入插入模式

如果完成编辑,按'esc'推出插入模式,输入':wq'保存退出


vim filename 如果文件名字不存在,会自动创建


vim 没有操作对象直接打开,编辑文件后要 :wq filename


注意:当文内容被错误更改,不想保存用 " :q! "  这表示强制退出不保存

######## 6.cd 切换工作目录 ############


cd directory    ##切换工作目录到指定目录


cd -            ##切换工作目录到之前所在目录

cd ~            ##切换到自己的家目录

cd ~usernmae    ##切换到指定用户家目录

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

[root@localhost Desktop]# cd /tmp

[root@localhost tmp]# cd -

/root/Desktop

[root@localhost Desktop]# cd ~

[root@localhost ~]# cd ..

[root@localhost /]# 


######## 7.ls 列出目录或文件信息 ######


ls            ##如果后面没有目标那么默认目标为当前目录

[root@localhost Desktop]# ls

file  file~  westos

ls direcory|filename        ##列出文件或目录内容

[root@localhost Desktop]# ls file

file

ls -d direcotry            ##列出目录本身

[root@localhost Desktop]# ls -d

.

ls -l filename|dorectory    ##列出文件或目录里面内容的属性

[root@localhost Desktop]# ls -l

total 4

-rw-r--r--. 1 root root    0 Sep 27 19:21 file

-rw-r--r--. 1 root root    0 Sep 27 19:07 file~

drwxr-xr-x. 3 root root 4096 Sep 27 19:25 westos

ls -ld directory            ##列出目录本身属性

[root@localhost Desktop]# ls -ld

drwxr-xr-x. 3 root root 4096 Sep 27 19:25 .

ls -a                    ##显示目录中的所有内容,包括以"."开头的隐藏文件

[root@localhost Desktop]# ls -a

.  ..  file  file~  westos  .wtt.sh.swp

ls -R                    ##递归显示目录中的内容

[root@localhost Desktop]# ls -R

.:

file  file~  westos


./westos:

hello1


./westos/hello1:

hello2


./westos/hello1/hello2:



#### 8.cp 文件复制 ####

cp [OPTION]... [-T] SOURCE DEST

cp[OPTION]... SOURCE... DIRECTORY

cp[OPTION]... -t DIRECTORY SOURCE...


cp file file1 file2 ...directory    ###把file  file1 file2 复制到 directory中

[root@localhost Desktop]# cp file westos

[root@localhost Desktop]# ls -R

.:

file  file~  westos


./westos:

file  hello1


./westos/hello1:

hello2


./westos/hello1/hello2:

cp file test    ###建立test文件模板为file

cp -r directorydirecotry1    ###复制目录

[root@localhost Desktop]# cp -r westos hello1

[root@localhost Desktop]# ls

hello1  westos

[root@localhost Desktop]# ls -R

.:

hello1  westos


./hello1:

file  hello1


./hello1/hello1:

hello2


./hello1/hello1/hello2:


./westos:

file  hello1


./westos/hello1:

hello2


./westos/hello1/hello2:


    cp SRC DEST

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

         如果目标存在:

             如果DEST是文件:将SRC中的内容覆盖至DEST中;此时建议为cp命令使用-i选项;

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


    cpSRC... DEST

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

 

     cpSRC...DEST

          SRC是目录:此时使用选项:-r

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

                                      

       常用选项

              -i:交互式

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

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

              -v:显示复制过程


#### 9.mv 移动或重命名 ####


      mv[OPTION]... [-T] SOURCE DEST

      mv[OPTION]... SOURCE... DIRECTORY

      mv[OPTION]... -t DIRECTORY SOURCE...

相同磁盘的mv是重命名,不同磁盘的mv是复制删除过程


mv file file1 direcotry   ##移动file file1到directory中

mv 存在文件 不存在文件   ##重命名文件

mv westos/linux .        ##把westos中的linux移动到当前目录 .代表当前目录


##end##



######################

##### 四.正则表达式 ####

######################


*###匹配0到任意字符

?             ###匹配单个字符

[[:alpha:]]    ###匹配单个字母

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

[[:upper:]]    ###匹配单个大写字母

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

[[:alnum:]]    ###匹配单个数字或字母

[[:punct:]]    ###匹配单个符号

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




~             ###当前用户家目录

~username     ###指定的用户家目录

~+            ###当前目录

~-            ###当前目录之前所在目录


.                ###当前目录

..               ###当前目录的上一级


##end##