Linux常用命令-帮助和系统内置类

1.Linux常用命令(一)

1.查询帮助命令

man 命令 查询命令帮助手册

  • -f 关键字精确搜索
    man -f == whatis
  • -k关键字模糊搜索
    man -k == appropos
whatis和apropos命令都需要依靠whatis数据库进行实现,whatis数据库可在主机联网的情况下使用makewhatis创建和更新whatis数据库
[root@aspen ~]# man tree
TREE(1)                General Commands Manual               TREE(1)

NAME #命令简介
       tree - list contents of directories in a tree-like format.

SYNOPSIS #命令格式
       tree   [-acdfghilnpqrstuvxACDFQNSUX]   [-L  level  [-R]]  [-H
       baseHREF] [-T title] [-o filename] [--nolinks]  [-P  pattern]
       [-I pattern] [--inodes] [--device] [--noreport] [--dirsfirst]
       [--version] [--help] [--filelimit #] [--si] [--prune]  [--du]
       [--timefmt format] [directory ...]

DESCRIPTION #命令的详细描述
       Tree is a recursive directory listing program that produces a
       depth indented listing of files, which is colorized ala  dir‐
       colors  if the LS_COLORS environment variable is set and out‐
       put is to tty.  With no arguments, tree lists  the  files  in
       the  current  directory.  When directory arguments are given,
       tree lists all the files  and/or  directories  found  in  the
       given  directories  each in turn.  Upon completion of listing
[root@aspen ~]# man -f tree
tree (1)             - list contents of directories in a tree-like ...

help 系统内置命令 获取bash内置命令帮助手册

[root@aspen ~]# help exit
exit: exit [n]
    Exit the shell.

    Exits the shell with a status of N.  If N is omitted, the exit status
    is that of the last command executed.

命令 --help 使用命令帮助参数获取命令帮助

[root@aspen ~]# vim --help
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Oct 30 2018 19:56:57)

usage: vim [arguments] [file ..]       edit specified file(s)
   or: vim [arguments] -               read text from stdin
   or: vim [arguments] -t tag          edit file where tag is defined
   or: vim [arguments] -q [errorfile]  edit file with first error

Arguments:
   --           Only file names after this
   -v           Vi mode (like "vi")
   -e           Ex mode (like "ex")
   -E           Improved Ex mode
   -s           Silent (batch) mode (only for "ex")
   -d           Diff mode (like "vimdiff")
   -y           Easy mode (like "evim", modeless)
......
   --startuptime <file>   Write startup timing messages to <file>
   -i <viminfo>       Use <viminfo> instead of .viminfo
   -h  or  --help   Print Help (this message) and exit
   --version        Print version information and exit

info 命令 查询命令详细的帮助手册

[root@aspen ~]# info help
File: *manpages*,  Node: help,  Up: (dir)

BASH_BUILTINS(1)            General Commands Manual           BASH_BUILTINS(1)

NAME
       bash,  :,  .,  [, alias, bg, bind, break, builtin, caller, cd, command,
       compgen, complete, 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)

BASH BUILTIN COMMANDS
       Unless otherwise noted, each builtin command documented in this section
       as accepting options preceded by - accepts -- to signify the end of the
       options.   The  :, true, false, and test builtins do not accept options
       and do not treat -- specially.  The exit, logout, break, continue, let,
       and  shift builtins accept and process arguments beginning with - with‐
       out requiring --.  Other builtins that accept  arguments  but  are  not
       specified  as accepting options interpret arguments beginning with - as
       invalid options and require -- to prevent this interpretation.
       : [arguments]
              No effect; the command does nothing beyond  expanding  arguments
              and  performing any specified redirections.  A zero exit code is
              returned.

        .  filename [arguments]
......
-----Info: (*manpages*)help, 1646 lines --Top---------------------------------------------------------------------------
No `Prev' or `Up' for this node within this document.

2.内置命令及其他

yum install 软件名 从网络上安装软件

  • -y 安装过程中遇到的确认选项自动选为yes;
    yum grouplist 查看系统已安装的软件包
    yum groupinstall 软件包名 安装指定的软件包
    yum provides 命令 查看已安装命令所属软件包
    yum repolist 查询系统所使用的YUM源**
[root@aspen ~]# yum repolist 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                                   repo name                                                               status
base/7/x86_64                             CentOS-7 - Base - mirrors.aliyun.com                                    10,019
!epel/x86_64                              Extra Packages for Enterprise Linux 7 - x86_64                          13,174
extras/7/x86_64                           CentOS-7 - Extras - mirrors.aliyun.com                                     413
updates/7/x86_64                          CentOS-7 - Updates - mirrors.aliyun.com                                  1,862
repolist: 25,468
[root@aspen ~]# yum provides ifconfig
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
net-tools-2.0-0.24.20131004git.el7.x86_64 : Basic networking tools
Repo        : @base
Matched from:
Filename    : /usr/sbin/ifconfig
新装系统建议安装的三个常用功能:
tree 以树形模式显示目录结构/内存
vim 文本编辑器(vi编辑器的升级版)
bash-completion Linux下自动补全命令参数工具

rpm 软件包名 RPM包管理命令

  • -i 安装指定软件包
  • -v 显示安装过程
  • -h 以认可读形式显示
  • -q 查询软件包(通常用于查看系统下还未安装的软件包)
  • -a 查询所有已安装的软件包
  • -l 显示软件包文件列表
  • -f 查询拥有指定文件的套件
  • -e 卸载指定软件包
-ivh 通常组合使用,用于安装软件
-qa 组合使用,查看系统所有已安装软件包
-ql 组合使用,查看指定软件包内文件列表
-qf 组合使用,查看指定文件或命令所属软件包
[root@aspen ~]# rpm -ivh /mnt/Packages/telnet-0.17-64.el7.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:telnet-1:0.17-64.el7             ################################# [100%]
Linux系统下安装按软件的三种方式
1.YUM安装:网络自动安装,系统自动解决软件间依赖关系问题
2.rpm安装:使用RPM软件包安装,手动解决软件间依赖关系问题
3.make安装:编译安装

step1:/configure
step2:make
step3:make install

xargs 命令 将标准输入转换成命令行参数

  • -n数字 表示命令在执行的时候一次用的参数的个数(默认是用所有的)
xargs命令后面不支持别名,常与管道配合使用
[root@aspen ~]# cat ./num.txt 
1 2 3 4 5 6 7 8 9 10
[root@aspen ~]# xargs -n1 < ./num.txt
1
2
3
4
5
6
7
8
9
10

echo 内容 显示内容信息到屏幕

  • -e 显示内容时,支持转义字符
  • -n 显示内容时,不显示每行结尾的回车标识符
[root@aspen ~]# echo -e '123456\n123456\n123456'
123456
123456
123456
[root@aspen ~]# echo PS1
PS1
[root@aspen ~]# echo $PS1
[\u@\h \W]\$
[root@aspen ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@aspen ~]# echo -n $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin[root@aspen ~]#

alias 别名='命令 -参数' 查看/设置系统别名

alias 默认查看系统所有别名
[root@aspen ~]# 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@aspen ~]# alias ld='ls -ld --color=auto'
[root@aspen ~]# ld /
dr-xr-xr-x. 19 root root 253 May 10 21:07 /

unalias 取消系统别名

unalias ld 
[root@aspen ~]# ld /
/: file not recognized: Is a directory

blkid 查看系统块设备UUID

[root@aspen ~]# blkid
/dev/sda1: UUID="ed50c0d5-412a-4c9d-9718-fc0c26e29cb1" TYPE="xfs" 
/dev/sda2: UUID="7cf733af-f4be-4eca-be4f-83cde65d7dfa" TYPE="swap" 
/dev/sda3: UUID="b1295302-6765-4999-8f5a-458e2928baeb" TYPE="xfs" 
/dev/sr0: UUID="2018-11-25-23-54-16-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 

history 查看命令执行的历史纪录

  • -c 清空历史命令记录
[root@aspen ~]# history | tail -5
 1160  echo -e '123456\n123456\t123456'
 1161  echo -e '123456\n123456\n123456'
 1162  history 
 1163  history | tail -10
 1164  history | tail -5
[root@aspen ~]# history -c
[root@aspen ~]# history 
  166  history 

sh 脚本文件 执行脚本

  • -x 显示脚本执行过程
[root@aspen scripts]# ./bak-etc-cron.sh
-bash: ./bak-etc-cron.sh: Permission denied
[root@aspen scripts]# sh -x ./bak-etc-cron.sh 
++ hostname -I
++ awk '{print $1}'
+ mkdir -p /backup/10.0.0.200
++ awk '{print $1}'
++ hostname -I
++ date +%F-%w
+ tar zcf /backup/10.0.0.200/bak-2019-05-13-1.tar.gz /etc/ /var/spool/cron/
tar: Removing leading `/' from member names
+ find /backup/ -type f -mtime +7 -iname '*-[^1].tar.gz'
+ xargs rm
rm: missing operand
Try 'rm --help' for more information.
[root@aspen scripts]# cat ./bak-etc-cron.sh 
#!/bin/bash
mkdir -p /backup/`hostname -I |awk '{print $1}'`&& tar zcf /backup/`hostname -I|awk '{print $1}'`/bak-`date +%F-%w`.tar.gz /etc/ /var/spool/cron/ && find /backup/ -type f -mtime +7 -iname '*-[^1].tar.gz' |xargs rm 
[root@aspen scripts]# ls /backup/10.0.0.200
bak-2019-05-13-1.tar.gz

Linux命令要养成操作前备份,操作后检查的好习惯
未完待续...