• Centos7常用基本命令使用(帮助类、文件目录类)


    1. 帮助类

    1.1 man

    man可以查看可执行的命令、系统调用、函数、文件格式、内核历程

    man查看时按f向下翻页,按b向上翻页

    cd、exit是bash的内置命令,常驻在系统内存中。如下所示:

    [root@bigdata001 ~]# type cd
    cd 是 shell 内嵌
    [root@bigdata001 ~]#
    [root@bigdata001 ~]# type ll
    ll 是 `ls -l --color=auto' 的别名
    [root@bigdata001 ~]# 
    [root@bigdata001 ~]# man -f cd
    cd (1)               - bash built-in commands, see bash(1)
    cd (n)               - Change working directory
    [root@bigdata001 ~]#
    [root@bigdata001 ~]# man n cd
    ......省略部分......
    [root@bigdata001 ~]# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    manual有很多册,查看名称为n的册的解析

    通过alias查看所有有别名的命令

    [root@bigdata001 ~]# alias
    alias cp='cp -i'
    alias egrep='egrep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias grep='grep --color=auto'
    alias l.='ls -d .* --color=auto'
    alias ll='ls -l --color=auto'
    alias ls='ls --color=auto'
    alias mv='mv -i'
    alias rm='rm -i'
    alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
    [root@bigdata001 ~]# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    1.2 help

    查看bash内置命令的说明

    [root@bigdata001 ~]# 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.
        
        Options:
            -L	force symbolic links to be followed
            -P	use the physical directory structure without following symbolic
        	links
            -e	if the -P option is supplied, and the current working directory
        	cannot be determined successfully, exit with a non-zero status
        
        The default is to follow symbolic links, as if `-L' were specified.
        
        Exit Status:
        Returns 0 if the directory is changed, and if $PWD is set successfully when
        -P is used; non-zero otherwise.
    [root@bigdata001 ~]#
    
    • 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

    对于外部命令,可以使用命令提供的help参数查看信息

    [root@bigdata001 ~]# ls --help
    ......省略部分......
    [root@bigdata001 ~]# 
    
    • 1
    • 2
    • 3

    可以使用ctrl + l或clear或reset进行清屏

    2. 文件目录类

    c字符char类型的是鼠标、键盘等。d块block类型的是硬盘等

    2.1 cd命令

    • cd -:回退到上一次的目录
    • cd:回到当前用户的home目录

    2.2 rmdir

    [root@bigdata001 ~]# mkdir dir1 dir2
    [root@bigdata001 ~]# rmdir dir1 dir2
    
    • 1
    • 2

    2.3 cp

    [root@bigdata001 ~]# type cp
    cp 是 `cp -i' 的别名
    [root@bigdata001 ~]#
    [root@bigdata001 ~]# \cp test.txt1 test.txt2
    [root@bigdata001 ~]# 
    
    • 1
    • 2
    • 3
    • 4
    • 5

    执行cp其实就是执行cp -i命令,-i参数的含义是在覆盖前交互式的给出提示

    \cp是cp的原生命令,不带-i参数

    2.4 cat

    cat是catch的意思

    [root@bigdata001 ~]# cat -n anaconda-ks.cfg 
         1	#version=DEVEL
         2	# System authorization information
         3	auth --enableshadow --passalgo=sha512
    ......省略部分......
        47	pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
        48	pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
        49	%end
    [root@bigdata001 ~]# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    -n参数表示显示行号

    2.5 more

    more命令是一个基于vi编辑器的文本过滤器,它以全屏幕的方式按页显示文本文件的内容

    快捷键操作功能说明
    空白键(space)代表向下翻一页
    Ctrl+b返回上一屏
    Ctrl+f向下滚动一屏
    =输出当前行的行号
    :f输出文件名和当前行的行号

    2.6 less

    less指令用来分屏查看文件内容,比more指令更加强大。less指令在显示文件内容时,并不是一次将整个文件加载之后才显示,而是根据显示需要加载内容

    快捷键操作功能说明
    空白键(space)代表向下翻一页
    Ctrl+b返回上一屏
    Ctrl+f向下滚动一屏
    pageUp返回上一屏
    pageDown向下滚动一屏
    :f显示内容例如:text.txt lines 1-28/49 byte 889/1335 67% (press RETURN)。含义是文件名 当前屏幕行号范围 文件总行数 当前字节数和总字节数 当前百分比
    g跳转到文件开头
    G跳转到文件末尾
    /搜索内容向下进行内容的搜索,按n向下查找,按N向上查找
    ?搜索内容向上进行内容的搜索,按n向上查找,按N向下查找

    2.7 echo

    [root@bigdata001 ~]# echo hello   world
    hello world
    [root@bigdata001 ~]# 
    [root@bigdata001 ~]# echo -e "hello\nworld"
    hello
    world
    [root@bigdata001 ~]# 
    [root@bigdata001 ~]# echo -e "hello\n\"world\""
    hello
    "world"
    [root@bigdata001 ~]#
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    2.8 tail

    [root@bigdata001 ~]# tail -f test.txt
    hello world
    
    
    • 1
    • 2
    • 3

    注意:

    • 当按ctrl + s暂停后,用echo hello world >> test.txt进行内容的追加,对test.txt的内容监控不会有新的内容。可以按ctrl + q进行暂停模式的退出,刚刚追加的新内容,会显示出来
    • 使用echo hello world > test.txt,覆盖的内容不会显示,会显示tail: test.txt:文件已截断。再进行echo hello world >> test.txt会显示追加的内容
    • 使用vim对test.txt进行编辑保存,并不会监控改变的内容。再进行echo hello world >> test.txt不会会显示追加的内容。因为用vim进行编辑保存后,文件的index发生了变化。所以对文件的更新,监控是察觉不到的,如下所示:
    [root@bigdata001 ~]# ls -i test.txt
    100988691 test.txt
    [root@bigdata001 ~]# 
    [root@bigdata001 ~]# vi test.txt
    [root@bigdata001 ~]# 
    [root@bigdata001 ~]# ls -i test.txt
    100711030 test.txt
    [root@bigdata001 ~]#
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    2.9 ln链接:

    软链接:相当与一个链接,指向原来的文件或目录
    语法:

    ln -s 文件/目录 软链接名
    
    • 1
    • 在目录的软链接下,执行pwd -P,显示的是原目录的绝对路径
    • 执行`cd -P 目录的软链接,进入的是原目录下
    • 执行rm -rf 目录的软连接/,会删除软链接和原目录下的所有文件

    硬链接:相当与一个指针,指向原来的文件的内部地址。和原文件一摸一样
    语法:

    ln 文件 硬链接名
    
    • 1

    2.10 history

    [root@bigdata001 ~]# history 3
     1022  ls
     1023  cat test.txt
     1024  history 3
    [root@bigdata001 ~]# 
    [root@bigdata001 ~]# !1022
    ls
    anaconda-ks.cfg  
    [root@bigdata001 ~]# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    可以使用history -c对history进行清除

    2.11 tree

    递归查看当前目录的所有层级结构,不包括隐藏文件和目录

    安装tree

    [root@bigdata001 ~]# yum install -y tree
    
    • 1

    使用tree

    [root@bigdata001 ~]# tree
    .
    └── anaconda-ks.cfg
    
    0 directories, 1 file
    [root@bigdata001 ~]# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
  • 相关阅读:
    python——spark入门
    HarmonyOS鸿蒙学习笔记(11)Flex组件alignItems属性说明
    [Servlet 2]Servlet,请求与响应
    RASP技术进阶系列(二):东西向Web流量的智能检测防御
    安装file-saver后导入时报错Could not find a declaration file for module ‘file-saver‘
    颜色代码 颜色卡
    脉冲神经网络原理及应用,脉冲神经网络的优缺点
    【机器学习】训练集/验证集/测试集释疑
    高速串行总线——SATA
    ctf:kali工具: msfvenom
  • 原文地址:https://blog.csdn.net/yy8623977/article/details/125793878