恶补linux 笔记

一、shell 基础

1.用户提示符:#表示root用户  $表示普通用户

2. 一些闲扯淡的命令:

   date  查看当前日期时间

   cal  显示日历

   df   磁盘剩余空间  -h 参数展示人能看的直白的

   free 内存使用数量 -h 参数展示人能看的直白的

   top  查看进程

   lsb_release -a 查看操作系统版本

  

二、文件系统相关

1.  ls 命令的相关常用生僻参数及其他扩展:

    -t 参数 会按文件修改时间的先后来排序

    -r 参数 会按相反的顺序输出

    ls -l 输出结果解析:

    例: -rw-r--r-- 1 root root 3576296 2007-04-03 11:05 Experience ubuntu.ogg
     -rw-r--r-- : 对于文件的访问权限。第一个字符指明文件类型。在不同类 型之间,开头的“-”说明是一个普通文件,“d”表明是一 个目录。其后三个字符是文件所有者的访问权限,再其后的 三个字符是文件所属组中成员的访问权限,最后三个字符是 其他所有人的访问权限。这个字段的完整含义将在第十章讨 论。 
    1:文件硬链接数目
    root :文件属主用户名
    root:  文件所属用户组
    3576296:文件大小(字节数)
     2007-04-03: 上次修改时间
     Experience ubuntu.ogg : 文件名
 

2. 其他常用命令

    a. file : 查看文件描述

    b. less: 浏览文件内容

    c. cp -u参数:当把文件从一个目录复制到另一个目录时,仅复制目标目录中不存在的文件,或者是文件内容新于目标目录中已经存在的文件

   

    

3.关于链接

   链接分为硬链接和符号链接,链接的作用就像我们在编程中定义变量一样,我们操作链接只关心这个链接名是什么、表示什么,而不关心这个链接背后具体的资源是什么版本、什么具体内容。

   硬链接创建方式及特点: ln 文件名  链接名

                                     硬链接不能链接目录

                                     原始资源被删除后硬链接依然有效且可以被访问

                                     硬链接命名虽然可以不写文件类型,但是最好写上,防止原始文件丢失后恢复

                                     只能对已经存在的文件进行硬链接   

                                     不能关联与链接本身 不在同一个磁盘分区上的文件 

             

   符号链接创建方式及特点:ln -s 文件名/目录名  链接名

                                       可以对目录进行链接

                                       原始资源删除后符号链接失效 

                                       可以对不存在的资源进行符号链接

4. 通配符

    *    匹配任意多个字符(包括0个或1个)

        匹配任意一个字符 (不包括0个)

    [字符集]   匹配任意一个属于字符集中的字符

    [!字符集]  匹配任意一个不属于字符集中的字符

    [[:字符类:]] 匹配任意一个属于字符类中的字符 字符类:alnum(字母+数字)、alpha(字母)、digit(数字)、lower(小写字母)、upper(大写字母)

三、操作命令的命令

   1. type : 显示命令的信息

[root@xxxxxxx dir1]# type cp

cp is aliased to `cp -i'

   2.which : 显示命令的来源

[root@xxxxxxx dir1]# which cp

alias cp='cp -i'

/usr/bin/cp

   3.man : 显示命令的手册

 

[root@xxxxxxxx dir1]# man cp

 

 

 

 

 

 

 

              output version information and exit

 

       By  default,  sparse  SOURCE  files  are  detected  by  a  crude  heuristic  and  the  corresponding  DEST file is made sparse as well.  That is the behavior selected by

       --sparse=auto.  Specify --sparse=always to create a sparse DEST file whenever the SOURCE file contains a long enough sequence  of  zero  bytes.   Use  --sparse=never  to

       inhibit creation of sparse files.

 

       When  --reflink[=always]  is  specified,  perform a lightweight copy, where the data blocks are copied only when modified.  If this is not possible the copy fails, or if

       --reflink=auto is specified, fall back to a standard copy.

 

       The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.  The version control method may be selected via the  --backup  option  or  through  the  VER‐

       SION_CONTROL environment variable.  Here are the values:

 

       none, off

              never make backups (even if --backup is given)

 

       numbered, t

              make numbered backups

 

       existing, nil

              numbered if numbered backups exist, simple otherwise

 

       simple, never

              always make simple backups

 

       As a special case, cp makes a backup of SOURCE when the force and backup options are given and SOURCE and DEST are the same name for an existing, regular file.

 

       GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report cp translation bugs to <http://translationproject.org/team/>

 

AUTHOR

       Written by Torbjorn Granlund, David MacKenzie, and Jim Meyering.

 

COPYRIGHT

       Copyright © 2013 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.

       This is free software: you are free to change and redistribute it.  There is NO WARRANTY, to the extent permitted by law.

 

SEE ALSO

       The full documentation for cp is maintained as a Texinfo manual.  If the info and cp programs are properly installed at your site, the command

 

              info coreutils 'cp invocation'

 

       should give you access to the complete manual.

 

GNU coreutils 8.22                                                                November 2016                                                                            CP(1)

   4.info 显示命令信息(info cp 太他妈长了,不粘了)

   5.whatis : 显示命令的简洁信息

[root@xxxxxxxxx dir1]# whatis cp

cp (1)               - copy files and directories

cp (1p)              - copy files

   6.alias 创建连接别名(写在.bashrc 或者zshrc里面,自己可以做命令玩)   

# .bashrc

 

# User specific aliases and functions

 

alias rm='rm -i'

alias cp='cp -i'

alias mv='mv -i'

    
 

四、重定向 

1.重定向标准输入输出 

  ls -l /usr/bin > ls_output.txt   :  将ls结果保存到ls_output.txt中

  ls -l /usr/bin >> ls_output.txt : 同上,但是如果ls_output.txt文件不存在则创建

 注意:shell内部将文件类型标注为0 1 2 三种,分别代表 输入 输出 错误

  ls -l /bin/usr 2 > ls_error.txt 将ls的错误信息保存入ls_error.txt

  ls -l /bin/usr > ls_output.txt 2>&1   将错误信息与正确信息都存入ls_output.txt中

  ls -l /bin/usr 2> /dev/null: 错误信息不输出时将输出定位到 /dev/null 中
 
-----------------未完待续---------------------------------

猜你喜欢

转载自www.cnblogs.com/JhoneLee/p/11114995.html