zoukankan      html  css  js  c++  java
  • Linux基础命令注释(2)

    Linux基础命令注释(2)

    ln 链接文件

    • ln -s [源文件] [链接名称] 软连接
    [root@localhost ~]# ln -s anaconda-ks.cfg acd
    [root@localhost ~]# ls -l
    总用量 20
    drwxr-xr-x. 3 root root   37 9月   8 11:02 a
    -rw-r--r--. 1 root root   21 9月   8 09:31 abc
    lrwxrwxrwx. 1 root root   15 9月  10 09:46 acd -> anaconda-ks.cfg
    -rw-------. 1 root root 1451 9月   6 22:57 anaconda-ks.cfg
    
    

    • ln [源文件][连接名] 硬链接
    [root@localhost ~]# ln anaconda-ks.cfg vbn
    [root@localhost ~]# ll
    总用量 24
    drwxr-xr-x. 3 root root   37 9月   8 11:02 a
    -rw-r--r--. 1 root root   21 9月   8 09:31 abc
    lrwxrwxrwx. 1 root root   15 9月  10 09:46 acd -> anaconda-ks.cfg
    -rw-------. 2 root root 1451 9月   6 22:57 anaconda-ks.cfg
    -rw-r--r--. 1 root root    0 9月   7 15:56 bbb
    drwxr-xr-x. 3 root root   15 9月   7 16:33 c
    -rw-r--r--. 1 root root  327 9月   7 16:42 cc
    -rw-r--r--. 1 root root  126 9月   7 15:53 qwq
    -rw-------. 2 root root 1451 9月   6 22:57 vbn
    

    copy 复制文件,一个文件到一个文件,多个文件到目录

    • cp
    [root@localhost ~]# ls
    a  abc  acd  anaconda-ks.cfg  bbb  c  cc  qwq  vbn  wqw
    [root@localhost ~]# cp abc cc
    cp:是否覆盖"cc"? y
    

    • -a 归档复制,常用于备份
    [root@localhost ~]# ls
    a  abc   acd  anaconda-ks.cfg  bbb  c  cc  qwq  vbn  wqw
    [root@localhost ~]# cp -a abc acb
    [root@localhost ~]# ls
    a  abc  acb  acd  anaconda-ks.cfg  bbb  c  cc  qwq  vbn  wqw
    

    • -r递归复制,拷贝目录时必须使用此选项
    [root@localhost ~]# ls 
    a  abc  acb  acd  anaconda-ks.cfg  bbb  c  cc  qwq  vbn  wqw
    [root@localhost ~]# ls c
    [root@localhost ~]# 
    [root@localhost ~]# cp -r a c
    
    

    cat 与 tac

    • cat 拼接文件内容并输出至标准输出(屏幕)
    [root@localhost ~]# cat qwq
    rootpw --iscrypted $6$15KaJSMJ1CnXnZP6$i.4EoTpZwTUTcZhK0oYRIjgyP9UTYbXsq//IV4xIiaB.2RfwtJP7SzhiAN4KcrAZP1ABjRIPx9pdl7vXdHoJk.
    
    [root@localhost ~]# cat qwq wqw
    rootpw --iscrypted $6$15KaJSMJ1CnXnZP6$i.4EoTpZwTUTcZhK0oYRIjgyP9UTYbXsq//IV4xIiaB.2RfwtJP7SzhiAN4KcrAZP1ABjRIPx9pdl7vXdHoJk.
    rootpw --iscrypted $6$15KaJSMJ1CnXnZP6$i.4EoTpZwTUTcZhK0oYRIjgyP9UTYbXsq//IV4xIiaB.2RfwtJP7SzhiAN4KcrAZP1ABjRIPx9pdl7vXdHoJk.
    pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
    

    • -n显示行数
    [root@localhost ~]# cat -n anaconda-ks.cfg 
         1	#version=DEVEL
         2	# System authorization information
         3	auth --enableshadow --passalgo=sha512
         4	repo --name="Server-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvailability
         5	repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientStorage
         6	# Use CDROM installation media
         7	cdrom
         8	# Use graphical install
         9	graphical
        10	# Run the Setup Agent on first boot
        11	firstboot --enable
        12	ignoredisk --only-use=sda
        13	# Keyboard layouts
        14	keyboard --vckeymap=cn --xlayouts='cn'
        15	# System language
        16	lang zh_CN.UTF-8
        .....
    
    

    • tac 链接文件并倒序打印内容至标准输出
    [root@localhost ~]# cat /etc/issue
    S
    Kernel 
     on an m
    
    [root@localhost ~]# tac /etc/issue
    
    Kernel 
     on an m
    S
    

    more 全屏查看文本内容从前往后看完后自动退出(空格后翻)

    [root@localhost ~]# more anaconda-ks.cfg 
    #version=DEVEL
    # System authorization information
    auth --enableshadow --passalgo=sha512
    repo --name="Server-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvaila
    bility
    repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientS
    torage
    # Use CDROM installation media
    cdrom
    # Use graphical install
    graphical
    # Run the Setup Agent on first boot
    firstboot --enable
    ignoredisk --only-use=sda
    # Keyboard layouts
    keyboard --vckeymap=cn --xlayouts='cn'
    # System language
    lang zh_CN.UTF-8
    ...
    

    less: 全屏查看文本内容空格后翻页,b 前翻页,看完不会自动退出,q 退出

    [root@localhost ~]# less anaconda-ks.cfg 
    

    head 与tail

    • head 从文件首部打印文件内容,默认10行
    [root@localhost ~]# head anaconda-ks.cfg 
    #version=DEVEL
    # System authorization information
    auth --enableshadow --passalgo=sha512
    repo --name="Server-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvailability
    repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientStorage
    # Use CDROM installation media
    cdrom
    # Use graphical install
    graphical
    # Run the Setup Agent on first boot
    

    -[n]显示n行

    [root@localhost ~]# head -15 anaconda-ks.cfg 
    #version=DEVEL
    # System authorization information
    auth --enableshadow --passalgo=sha512
    repo --name="Server-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvailability
    repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientStorage
    # Use CDROM installation media
    cdrom
    # Use graphical install
    graphical
    # Run the Setup Agent on first boot
    firstboot --enable
    ignoredisk --only-use=sda
    # Keyboard layouts
    keyboard --vckeymap=cn --xlayouts='cn'
    # System language
    

    [root@localhost ~]# cat anaconda-ks.cfg |head -15
    #version=DEVEL
    # System authorization information
    auth --enableshadow --passalgo=sha512
    repo --name="Server-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvailability
    repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientStorage
    # Use CDROM installation media
    cdrom
    # Use graphical install
    graphical
    # Run the Setup Agent on first boot
    firstboot --enable
    ignoredisk --only-use=sda
    # Keyboard layouts
    keyboard --vckeymap=cn --xlayouts='cn'
    # System language
    

    • tail 从文件尾部打印文件内容,默认10行
    [root@localhost ~]# tail anaconda-ks.cfg 
    
    %addon com_redhat_kdump --enable --reserve-mb='auto'
    
    %end
    
    %anaconda
    pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
    pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
    pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
    %end
    
    

    -[n]显示n行

    [root@localhost ~]# tail -15 anaconda-ks.cfg 
    @core
    chrony
    kexec-tools
    
    %end
    
    %addon com_redhat_kdump --enable --reserve-mb='auto'
    
    %end
    
    %anaconda
    pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
    pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
    pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
    %end
    
    

    [root@localhost ~]# cat anaconda-ks.cfg |tail -15
    @core
    chrony
    kexec-tools
    
    %end
    
    %addon com_redhat_kdump --enable --reserve-mb='auto'
    
    %end
    
    %anaconda
    pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
    pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
    pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
    %end
    
    

    • 只显示[n]行
    [root@localhost ~]# cat anaconda-ks.cfg |head -11 | tail -1
    firstboot --enable
    
    

    [root@localhost ~]# head -11 anaconda-ks.cfg | tail -1
    firstboot --enable
    

    du 查看文件或目录占用的磁盘空间大小

    • du 查看文件或目录占用的磁盘空间大小
    [root@localhost ~]# du a
    0	a/c
    4	a
    

    • -s只查看本目录
    [root@localhost ~]# du -s a
    4	a
    

    • -h 显示目录文件大小
    [root@localhost ~]# du -sh a
    4.0K	a
    

    • wc文本统计; -c:统计文本字节数; w:统计文本单词数; -l:统计文本行数l
    [root@localhost ~]# wc abc
     3  3 21 abc
    [root@localhost ~]# wc -c abc
    21 abc
    [root@localhost ~]# wc -w abc
    3 abc
    [root@localhost ~]# wc -l abc
    3 abc
    

    df 报告文件系统磁盘空间使用情

    • df 报告文件系统磁盘空间使用情况
    [root@localhost ~]# df
    文件系统                 1K-块   已用     可用 已用% 挂载点
    /dev/mapper/rhel-root 40137576 971488 39166088    3% /
    devtmpfs                922456      0   922456    0% /dev
    tmpfs                   933524      0   933524    0% /dev/shm
    tmpfs                   933524   8844   924680    1% /run
    tmpfs                   933524      0   933524    0% /sys/fs/cgroup
    /dev/sda1              1038336 145824   892512   15% /boot
    /dev/mapper/rhel-home 19593216  32956 19560260    1% /home
    tmpfs                   186708      0   186708    0% /run/user/0
    

    • -h : 单位转换,以更友好的方式显示大小
    [root@localhost ~]# df -h
    文件系统               容量  已用  可用 已用% 挂载点
    /dev/mapper/rhel-root   39G  949M   38G    3% /
    devtmpfs               901M     0  901M    0% /dev
    tmpfs                  912M     0  912M    0% /dev/shm
    tmpfs                  912M  8.7M  904M    1% /run
    tmpfs                  912M     0  912M    0% /sys/fs/cgroup
    /dev/sda1             1014M  143M  872M   15% /boot
    /dev/mapper/rhel-home   19G   33M   19G    1% /home
    tmpfs                  183M     0  183M    0% /run/user/0
    

    hostname 修改主机名

    • hostname 查看或临时修改主机名,重开终端有效,重启失效
    [root@hostnamectl ~]# hostname
    hostnamectl
    [root@hostnamectl ~]# hostname M
    [root@hostnamectl ~]# hostname
    M
    

    • hostnmectl 修改主机名(会修改配置文件 ),重开终端有效,重启依然有效
    [root@M ~]# hostnamectl set-hostname hostnamectl
    [root@M ~]# hostname
    hostnamectl
    [root@M ~]# shutdown -r now
    Last login: Tue Sep 10 13:00:46 2019 from 192.168.213.1
    [root@hostnamectl ~]# 
    
    

    who

    [root@hostnamectl ~]# who       //显示当前登录用户
    root     pts/0        2019-09-10 13:02 (192.168.213.1)
    [root@hostnamectl ~]# w     //显示当前在线用户并显示其正在运行的命令
     13:06:14 up 3 min,  1 user,  load average: 0.01, 0.01, 0.01
    USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
    root     pts/0    192.168.213.1    13:02    6.00s  0.07s  0.06s w
    [root@hostnamectl ~]# whoami            //显示当前登录用户
    root
    [root@hostnamectl ~]# who am i          //显示当前登录用户
    root     pts/0        2019-09-10 13:02 (192.168.213.1)
    [root@hostnamectl ~]# 
    

    • tty 查看你的终端
    [root@hostnamectl ~]# tty
    /dev/pts/0
    

    which 查看命令的绝对路径

    [root@hostnamectl ~]# which ls
    alias ls='ls --color=auto'
    	/usr/bin/ls
    

    clear 清屏

    • clear 或者 Ctrl+l
    [root@hostnamectl ~]# clear
    [root@hostnamectl ~]# 
    

    cal 打印日历

    [root@hostnamectl ~]# cal
          九月 2019     
    日 一 二 三 四 五 六
     1  2  3  4  5  6  7
     8  9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29 30
    

    • [n]输出n年的日历1~9999
    [root@hostnamectl ~]# cal 2012
                                   2012                               
    
            一月                   二月                   三月        
    日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
     1  2  3  4  5  6  7             1  2  3  4                1  2  3
     8  9 10 11 12 13 14    5  6  7  8  9 10 11    4  5  6  7  8  9 10
    15 16 17 18 19 20 21   12 13 14 15 16 17 18   11 12 13 14 15 16 17
    22 23 24 25 26 27 28   19 20 21 22 23 24 25   18 19 20 21 22 23 24
    29 30 31               26 27 28 29            25 26 27 28 29 30 31
    
            四月                   五月                   六月        
    日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
     1  2  3  4  5  6  7          1  2  3  4  5                   1  2
     8  9 10 11 12 13 14    6  7  8  9 10 11 12    3  4  5  6  7  8  9
    15 16 17 18 19 20 21   13 14 15 16 17 18 19   10 11 12 13 14 15 16
    22 23 24 25 26 27 28   20 21 22 23 24 25 26   17 18 19 20 21 22 23
    29 30                  27 28 29 30 31         24 25 26 27 28 29 30
    
            七月                   八月                   九月        
    日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
     1  2  3  4  5  6  7             1  2  3  4                      1
     8  9 10 11 12 13 14    5  6  7  8  9 10 11    2  3  4  5  6  7  8
    15 16 17 18 19 20 21   12 13 14 15 16 17 18    9 10 11 12 13 14 15
    22 23 24 25 26 27 28   19 20 21 22 23 24 25   16 17 18 19 20 21 22
    29 30 31               26 27 28 29 30 31      23 24 25 26 27 28 29
                                                  30
            十月                  十一月                 十二月       
    日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
        1  2  3  4  5  6                1  2  3                      1
     7  8  9 10 11 12 13    4  5  6  7  8  9 10    2  3  4  5  6  7  8
    14 15 16 17 18 19 20   11 12 13 14 15 16 17    9 10 11 12 13 14 15
    21 22 23 24 25 26 27   18 19 20 21 22 23 24   16 17 18 19 20 21 22
    28 29 30 31            25 26 27 28 29 30      23 24 25 26 27 28 29
                                                  30 31
    
    

    ldd 查看命令依赖那些库

    [root@hostnamectl ~]# ldd /usr/bin/ls
    	linux-vdso.so.1 =>  (0x00007ffe917ec000)
    	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f3a56334000)
    	libcap.so.2 => /lib64/libcap.so.2 (0x00007f3a5612f000)
    	libacl.so.1 => /lib64/libacl.so.1 (0x00007f3a55f25000)
    	libc.so.6 => /lib64/libc.so.6 (0x00007f3a55b62000)
    	libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f3a55900000)
    	libdl.so.2 => /lib64/libdl.so.2 (0x00007f3a556fb000)
    	/lib64/ld-linux-x86-64.so.2 (0x00005561b7879000)
    	libattr.so.1 => /lib64/libattr.so.1 (0x00007f3a554f6000)
    	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f3a552da000)
    
    

    date 时间

    [root@hostnamectl ~]# date
    2019年 09月 10日 星期二 13:21:59 CST
    

    [root@hostnamectl ~]# date -s '2019-09-10 13:21:30'
    2019年 09月 10日 星期二 13:21:30 CST
    

    • 格式化输出时间:
      +%Y:年
      +%m:月
      +%d:日
      +%H:时
      +%M:分
      +%S:秒
    [root@hostnamectl ~]# date +%y
    19
    [root@hostnamectl ~]# date +%m
    09
    [root@hostnamectl ~]# date +%d
    10
    [root@hostnamectl ~]# date +%H
    13
    [root@hostnamectl ~]# date +%M
    56
    [root@hostnamectl ~]# date +%MS
    
    • 创建当前时间文件
    [root@hostnamectl ~]# touch $(date '+%Y%m%d')
    [root@hostnamectl ~]# ls
    20190910  a  abc  acb  acd  anaconda-ks.cfg  bbb 
    

    帮助

    • help command 内置命令
    [root@hostnamectl ~]# help cd
    cd: cd [-L|[-P [-e]]] [dir]
        Change the shell working directory.
        
        Change the current directory to DIR.  The default DIR is the value of the
        HOME shell variable.
        
        The variable CDPATH defines the search path for the directory containing
        DIR.  Alternative directory names in CDPATH are separated by a colon (:).
        A null directory name is the same as the current directory.  If DIR begins
        with a slash (/), then CDPATH is not used.
        
        If the directory is not found, and the shell option `cdable_vars' is set,
        the word is assumed to be  a variable name.  If that variable has a value,
        its value is used for DIR.
    

    • CMMAND --help 外部命令
    [root@hostnamectl ~]# ls --help
    用法:ls [选项]... [文件]...
    List information about the FILEs (the current directory by default).
    Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
    
    Mandatory arguments to long options are mandatory for short options too.
      -a, --all			不隐藏任何以. 开始的项目
      -A, --almost-all		列出除. 及.. 以外的任何项目
          --author			与-l 同时使用时列出每个文件的作者
      -b, --escape			以八进制溢出序列表示不可打印的字符
          --block-size=SIZE      scale sizes by SIZE before printing them; e.g.,
                                   '--block-size=M' prints sizes in units of
                                   1,048,576 bytes; see SIZE format below
      -B, --ignore-backups       do not list implied entries ending with ~
      -c                         with -lt: sort by, and show, ctime (time of last
                                   modification of fil
    
    • man手册
      []:可选

    <>:必选

    …:可出现多次

    |:多选一

    {}:分组

    NAME:命令名称及功能简要说明

    SYNOPSIS:用法说明,包括可用的选项

    DESCRIPTION:命令功能的详尽说明,可能包括每一个选项的意义

    OPTIONS:说明每一个选项的意义

    FILES:此命令相关的配置文件

    BUGS:报告bug

    EXAMPLES:命令示例

    SEE ALSO:另外参照

    翻屏:空格(向后翻一屏),b键(向前翻一屏)

    查找:
    /KEYWORD:从前往后查找KEYWORD
    ?KEYWORD:从后往前查找KEYWORD
    n:下一个匹配的行
    N:前一个匹配的行
    q:退出

    man

    大写N查找上一个

    小写n查找下一个

       Mandatory arguments to long options are mandatory for short options  too.
    
           -a, --all
                  do not ignore entries starting with .
    
           -A, --almost-all
                  do not list implied . and ..
    
           --author
                  with -l, print the author of each file
    
           -b, --escape
                  print C-style escapes for nongraphic characters
    
           --block-size=SIZE
                  scale sizes by SIZE before printing them; e.g.,  '--block-size=M'  prints
                  sizes in units of 1,048,576 bytes; see SIZE format below
    
           -B, --ignore-backups
                  do not list implied entries ending with ~
    
           -c     with  -lt:  sort  by,  and show, ctime (time of last modification of file
                  status information); with -l: show ctime and  sort  by  name;  otherwise:
                  sort by ctime, newest first
    
           -C     list entries by columns
     Manual page ls(1) line 15 (press h for help or q to quit)
    
    
  • 相关阅读:
    SpringBoot国际化和国际化失败的原因
    java之上传文件、下载文件
    java之拦截器Interceptor/自定义视图解析器
    idea配置tomcat,idea和tomcat版本不一致输出json会报500错误,解决localhost:8080 is already in use问题,解决idea控制台日志乱码
    guzzle json 请求
    Testlib-Generator使用笔记
    Harbour.Space Scholarship Contest 2021-2022 (Div. 1 + Div. 2) 题解 (ABCDEF)
    Codeforces Round #731 (Div. 3) 题解 (DEFG)
    面试题
    yaml部署
  • 原文地址:https://www.cnblogs.com/guilai/p/11527475.html
Copyright © 2011-2022 走看看