第三章:Linux系统命令行基础

1、初识命令提示符

WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Thu Apr  2 14:44:31 2020 from 10.0.0.1
[root@localhost ~]# 

1.1、命令提示符结构

[root@localhost ~]#    ======>系统管理员用户
[root@localhost ~]$   ======>系统普通用户
[root@localhost ~]# echo $PS1
[\u@\h \W]\$
参数 含义
\d 代表日期,格式为weekday month date,例如:"Mon Aug 1"
\H 完整主机名
\h 仅取主机名中的第一个名字
\t 显示时间为24小时格式,如:HH:MM:SS
\T 显示时间为12小时格式
\A 显示时间为24小时格式:HH:MM
\u 当前用户的账号名称
\v BASH的版本信息
\w 完整的工作目录名称
\W 利用basename取得工作目录名称,只显示最后一个目录名
\# 下达的第几个命令
\$ 提示字符,如果是root用户,提示符为 # ,普通用户则为 $

1.2、美化命令提示符

[root@localhost sysconfig]# PS1="\[\e[37;40m\][\[\e[31;40m\]\u\[\e[33;40m\]@\[\e[34;40m\]\h \[\e[35;40m\]\w\[\e[0m\]]\\$ "
  • 永久生效

    [root@localhost /etc/sysconfig]# echo 'export PS1="\[\e[37;40m\][\[\e[31;40m\]\u\[\e[33;40m\]@\[\e[34;40m\]\h \[\e[35;40m\]\w\[\e[0m\]]\\$ " '>> /etc/profile
    
    

在PS1中设置字符颜色的格式为:[\e[F;Bm]........[\e[0m]

F B
30 40 黑色
31 41 红色
32 42 绿色
33 43 黄色
34 44 蓝色
35 45 紫红色
36 46 青蓝色
37 47 白色

2、Linux命令行快捷键

ctrl + a 光标移动至开头
ctrl + e 光标移动至结尾
ctrl + f 光标向右移动一个字符
ctrl + b 光标向左移动一个字符
ctrl + u 剪切(删除)光标处到行首的字符
ctrl + k 剪切(删除)光标处到行尾的字符
ctrl + y 粘贴剪切的内容
ctrl + c 中断终端正在执行的任务或者删除整行
ctrl + d 退出当前shell命令行,还可以关闭Xshell
ctrl + r 搜索命令行使用过的历史命令
ctrl + l 清屏
ctrl + z 暂停正在执行的命令 bj后台
ctrl + s 锁屏
ctrl + q 解锁
ctrl + insert 复制
shift + insert 粘贴
esc + . 获取上一条命令最后部分
!sys 最近以sys开头的命令
!!sys 执行上一条命令

3、查看Linux系统命令帮助

3.1、--help

  • 用法
    • 命令 --help
    • 查看中文:LANG="zh_CH.UTF-8"
[root@localhost ~]# cp --help
Usage: cp [OPTION]... [-T] SOURCE DEST
  or:  cp [OPTION]... SOURCE... DIRECTORY
  or:  cp [OPTION]... -t DIRECTORY SOURCE...
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

Mandatory arguments to long options are mandatory for short options too.
  -a, --archive                same as -dR --preserve=all
      --attributes-only        don't copy the file data, just the attributes
      --backup[=CONTROL]       make a backup of each existing destination file
  -b                           like --backup but does not accept an argument
      --copy-contents          copy contents of special files when recursive
  -d                           same as --no-dereference --preserve=links
  -f, --force                  if an existing destination file cannot be
                                 opened, remove it and try again (this option
                                 is ignored when the -n option is also used)
  -i, --interactive            prompt before overwrite (overrides a previous -n
                                  option)
  -H                           follow command-line symbolic links in SOURCE
  -l, --link                   hard link files instead of copying
  -L, --dereference            always follow symbolic links in SOURCE
  -n, --no-clobber             do not overwrite an existing file (overrides
                                 a previous -i option)
  -P, --no-dereference         never follow symbolic links in SOURCE
  -p                           same as --preserve=mode,ownership,timestamps
      --preserve[=ATTR_LIST]   preserve the specified attributes (default:
                                 mode,ownership,timestamps), if possible
                                 additional attributes: context, links, xattr,
                                 all
  -c                           deprecated, same as --preserve=context
      --no-preserve=ATTR_LIST  don't preserve the specified attributes
      --parents                use full source file name under DIRECTORY
  -R, -r, --recursive          copy directories recursively
      --reflink[=WHEN]         control clone/CoW copies. See below
      --remove-destination     remove each existing destination file before
                                 attempting to open it (contrast with --force)
      --sparse=WHEN            control creation of sparse files. See below
      --strip-trailing-slashes  remove any trailing slashes from each SOURCE
                                 argument
  -s, --symbolic-link          make symbolic links instead of copying
  -S, --suffix=SUFFIX          override the usual backup suffix
  -t, --target-directory=DIRECTORY  copy all SOURCE arguments into DIRECTORY
  -T, --no-target-directory    treat DEST as a normal file
  -u, --update                 copy only when the SOURCE file is newer
                                 than the destination file or when the
                                 destination file is missing
  -v, --verbose                explain what is being done
  -x, --one-file-system        stay on this file system
  -Z                           set SELinux security context of destination
                                 file to default type
      --context[=CTX]          like -Z, or if CTX is specified then set the
                                 SELinux or SMACK security context to CTX
      --help     display this help and exit
      --version  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 VERSION_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: 
For complete documentation, run: info coreutils 'cp invocation'

3.2、man

  • 用法:
    • man 命令
    • 按q退出
    • 按空格往下看
    • / 查找内容
[root@localhost ~]# man cp
CP(1)                      User Commands                      CP(1)

NAME
       cp - copy files and directories

SYNOPSIS
       cp [OPTION]... [-T] SOURCE DEST
       cp [OPTION]... SOURCE... DIRECTORY
       cp [OPTION]... -t DIRECTORY SOURCE...

DESCRIPTION
       Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

       Mandatory  arguments to long options are mandatory for short
       options too.

       -a, --archive
              same as -dR --preserve=all

       --attributes-only
              don't copy the file data, just the attributes

       --backup[=CONTROL]

3.3、搜索引擎查找

  • 用法
    • 搜索引擎输入Linux 命令

3.4、内置命令与普通命令的区别

  • 普通命令:

    • 在系统中存在的文件
  • 内置命令:

    • 不在系统中存在文件,存在bash中
  • 特殊性:

    • CentOS7中有些命令也存在文件
  • 内置命令

    bash,  :,  .,  [,  alias,  bg,  bind, break,
           builtin, caller, cd, command, compgen,  com-
           plete,  compopt,  continue,  declare,  dirs,
           disown,  echo,  enable,  eval,  exec,  exit,
           export,  false, fc, fg, getopts, hash, help,
           history, jobs,  kill,  let,  local,  logout,
           mapfile,  popd,  printf,  pushd,  pwd, read,
           readonly, return, set, shift, shopt, source,
           suspend,  test,  times,  trap,  true,  type,
           typeset, ulimit, umask, unalias, unset, wait
           - bash built-in commands, see bash(1)
    

3.5、查看内置命令

[root@localhost ~ 01:58:55]# help cd

4、关机重启一大堆命令

4.1、关机命令

shutdown -h now 立刻关机
systemctl  half  关机后关闭cpu
systemctl  poweroff  关机立即断电
init 0

4.2、重启命令

shutdown -r now 立刻重启
systemctl reboot
init 6

你可能感兴趣的:(第三章:Linux系统命令行基础)