• 1.1 Linux命令行概述

  • 1.2 在Linux命令行下查看命令帮助

  • 1.3 Linux关机、重启、注销命令

  • 1.4 老男孩的运维思想

  • 1.1 Linux命令行概述

    1.1.1 Linux命令行的作用与意义

      Linux是一个主要通过命令来进行管理的操作系统。

    1.1.2 Linux命令行介绍

    1)通过SSH工具远程连接阿里云ECS服务器,如Xshell;

    2)使用阿里云Web控制台-远程连接ECS服务器

    3)CentOS Linux命令行退出命令操作的界面

    1.1.3 Linux命令行常用快捷键

    常见的Linux远程连接工具:SecureCRT、Xshell客户端软件;

    1)最有用的快捷键;

    • tab 命令自动补全快捷键;

    2)移动光标快捷键;

    • Ctrl +a
    • Ctrl + e
    • Ctrl + f
    • Ctrl + b

    3)剪切、粘贴、清除快捷键;

    • Ctrl + Insert
    • Shift + Insert
    • Ctrl + k
    • Ctrl + u
    • Ctrl + w
    • Ctrl + y
    • Ctrl + e
    • Ctrl + h

    4)重复执行命令快捷键

    • Ctrl + d
    • Ctrl + r
    • Ctrl + g

    5)控制快捷键

    • Ctrl + l
    • Ctrl + s
    • Ctrl + q
    • Ctrl + z

    6)!开头的快捷键

    • !!
    • !pw
    • !pw:p
    • !num(指数字)
    • !$

    7)Esc相关

    • Esc + .
    • Esc + b
    • Esc + f

    1.2 在Linux命令行下查看命令帮助

    1.2.1 使用man获取命令帮助信息

    1)man命令的基本用法

      man命令是LInux系统中最核心的命令之一,可通过其查看其它Linux命令的使用、用法信息。还可查看软件服务配置文件、系统调用、库函数等帮助信息;

    2) 语法格式

    man 参数选项 命令/文件

    3)选项说明

    • User Commands 用户命令相关
    • System calls 系统函数调用
    • C Library Function C的库函数相关
    • Device and Special Files 设备和特殊文件相关
    • File Formats and Conventions 文件格式和规划
    • Games et.AI 游戏及其他
    • Miscellanea 宏、包及其他杂项
    • System Administration tools and Deamons 系统管理员命令和进程

    4)实战举例

    man man

    man cp

    man ls

    5) man帮助页的快捷键

    • Page Down
    • Page Up
    • Home
    • End
    • /cuixiaozhao
    • ?cuixiaozhao
    • n,N
    • q

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

    [root@iZ2ze2m3z176dpbiaolifiZ ~]# cat --help
    Usage: cat [OPTION]... [FILE]...
    Concatenate FILE(s), or standard input, to standard output. -A, --show-all equivalent to -vET

    -b, --number-nonblank number nonempty output lines, overrides -n

    -e equivalent to -vE

    -E, --show-ends display $ at end of each line

    -n, --number number all output lines

    -s, --squeeze-blank suppress repeated empty output lines

    -t equivalent to -vT

    -T, --show-tabs display TAB characters as ^I

    -u (ignored)

    -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB

    --help display this help and exit

    --version output version information and exit With no FILE, or when FILE is -, read standard input. Examples:

    cat f - g Output f's contents, then standard input, then g's contents.

    cat Copy standard input to standard output. GNU coreutils online help: <http://www.gnu.org/software/coreutils/>

    For complete documentation, run: info coreutils 'cat invocation'

    [root@iZ2ze2m3z176dpbiaolifiZ ~]# more --help

    more: unknown option -help

    Usage: more [options] file... Options:

    -d display help instead of ring bell

    -f count logical, rather than screen lines

    -l suppress pause after form feed

    -p do not scroll, clean screen and display text

    -c do not scroll, display text and clean line ends

    -u suppress underlining

    -s squeeze multiple blank lines into one

    -NUM specify the number of lines per screenful

    +NUM display file beginning from line number NUM

    +/STRING display file beginning from search string match

    -V output version information and exit

    [root@iZ2ze2m3z176dpbiaolifiZ ~]#

    小结:

    • 命令 --help 获取的是常用帮助信息;
    • man 命令 获取的更多更复杂的帮助信息;

    1.2.3 使用help命令获取bash内置命令帮助

    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 - without 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.

    举例如下:

    [root@iZ2ze2m3z176dpbiaolifiZ ~]# help cd
    cd: cd [-L|[-P [-e]]] [dir]
    Change the shell working directory.
    Change the current directory to DIR.  The default DIR </span><span style="color: #0000ff;">is</span><span style="color: #000000;"> the value of the
    HOME shell variable. The variable CDPATH defines the search path </span><span style="color: #0000ff;">for</span><span style="color: #000000;"> the directory containing
    DIR. Alternative directory names </span><span style="color: #0000ff;">in</span><span style="color: #000000;"> CDPATH are separated by a colon (:).
    A null directory name </span><span style="color: #0000ff;">is</span><span style="color: #000000;"> the same as the current directory. If DIR begins
    with a slash (</span>/), then CDPATH <span style="color: #0000ff;">is</span> <span style="color: #0000ff;">not</span><span style="color: #000000;"> used. If the directory </span><span style="color: #0000ff;">is</span> <span style="color: #0000ff;">not</span> found, <span style="color: #0000ff;">and</span> the shell option `cdable_vars<span style="color: #800000;">'</span><span style="color: #800000;"> is set,</span>
    the word <span style="color: #0000ff;">is</span><span style="color: #000000;"> assumed to be a variable name. If that variable has a value,
    its value </span><span style="color: #0000ff;">is</span> used <span style="color: #0000ff;">for</span><span style="color: #000000;"> DIR. Options:
    </span>-<span style="color: #000000;">L force symbolic links to be followed
    </span>-<span style="color: #000000;">P use the physical directory structure without following symbolic
    links
    </span>-e <span style="color: #0000ff;">if</span> the -P option <span style="color: #0000ff;">is</span> supplied, <span style="color: #0000ff;">and</span><span style="color: #000000;"> the current working directory
    cannot be determined successfully, exit with a non</span>-<span style="color: #000000;">zero status The default </span><span style="color: #0000ff;">is</span> to follow symbolic links, as <span style="color: #0000ff;">if</span> `-L<span style="color: #800000;">'</span><span style="color: #800000;"> were specified.</span>

    Exit Status:
    Returns 0 if the directory is changed, and if $PWD is set successfully when
    -P is used; non-zero otherwise.
    [root@iZ2ze2m3z176dpbiaolifiZ ~]# help history
    history: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
    Display or manipulate the history list.

    Display the history list with line numbers, prefixing each modified
    entry with a `</span>*<span style="color: #800000;">'</span><span style="color: #800000;">. An argument of N lists only the last N entries.</span>

    Options:
    -c clear the history list by deleting all of the entries
    -d offset delete the history entry at offset OFFSET.

      </span>-a    append history lines <span style="color: #0000ff;">from</span><span style="color: #000000;"> this session to the history file
    </span>-n read all history lines <span style="color: #0000ff;">not</span> already read <span style="color: #0000ff;">from</span><span style="color: #000000;"> the history file
    </span>-r read the history file <span style="color: #0000ff;">and</span><span style="color: #000000;"> append the contents to the history
    list
    </span>-<span style="color: #000000;">w write the current history to the history file
    </span><span style="color: #0000ff;">and</span><span style="color: #000000;"> append them to the history list </span>-p perform history expansion on each ARG <span style="color: #0000ff;">and</span><span style="color: #000000;"> display the result
    without storing it </span><span style="color: #0000ff;">in</span><span style="color: #000000;"> the history list
    </span>-<span style="color: #000000;">s append the ARGs to the history list as a single entry If FILENAME </span><span style="color: #0000ff;">is</span> given, it <span style="color: #0000ff;">is</span><span style="color: #000000;"> used as the history file. Otherwise,
    </span><span style="color: #0000ff;">if</span> $HISTFILE has a value, that <span style="color: #0000ff;">is</span> used, <span style="color: #0000ff;">else</span> ~/<span style="color: #000000;">.bash_history. If the $HISTTIMEFORMAT variable </span><span style="color: #0000ff;">is</span> set <span style="color: #0000ff;">and</span> <span style="color: #0000ff;">not</span> null, its value <span style="color: #0000ff;">is</span><span style="color: #000000;"> used
    as a format string </span><span style="color: #0000ff;">for</span> strftime(3) to <span style="color: #0000ff;">print</span><span style="color: #000000;"> the time stamp associated
    with each displayed history entry. No time stamps are printed otherwise. Exit Status:
    Returns success unless an invalid option </span><span style="color: #0000ff;">is</span> given <span style="color: #0000ff;">or</span><span style="color: #000000;"> an error occurs.

    [root@iZ2ze2m3z176dpbiaolifiZ ~]#

    1.2.4 使用info获取帮助信息

    • info ls
    • info cd
    • info man

    1.2.5 通过互联网寻求帮助信息

    搜索引擎的使用优先顺序(建议)

    www.google.com ->www.bing.com ->www.baidu.com

    1.3 Linux关机、重启、注销命令

    1.3.1 重启或关机命令:shutdown

      shutdown总体来讲,是一个用来安全关闭或重启Linux系统的命令。

      与shutdown功能类似的有init halt poweroff reboot

    SHUTDOWN(8)                                                                                                                     shutdown                                                                                                                    SHUTDOWN(8)
    
    NAME

    shutdown - Halt, power-off or reboot the machine SYNOPSIS

    shutdown [OPTIONS...] [TIME] [WALL...] DESCRIPTION

    shutdown may be used to halt, power-off or reboot the machine.
       The first argument may be a time string (which </span><span style="color: #0000ff;">is</span> usually <span style="color: #800000;">"</span><span style="color: #800000;">now</span><span style="color: #800000;">"</span>). Optionally, this may be followed by a wall message to be sent to all logged-<span style="color: #0000ff;">in</span><span style="color: #000000;"> users before going down.
    
       The time string may either be </span><span style="color: #0000ff;">in</span> the format <span style="color: #800000;">"</span><span style="color: #800000;">hh:mm</span><span style="color: #800000;">"</span> <span style="color: #0000ff;">for</span> hour/minutes specifying the time to execute the shutdown at, specified <span style="color: #0000ff;">in</span> 24h clock format. Alternatively it may be <span style="color: #0000ff;">in</span> the syntax <span style="color: #800000;">"</span><span style="color: #800000;">+m</span><span style="color: #800000;">"</span> referring to the specified number of minutes m <span style="color: #0000ff;">from</span> now.  <span style="color: #800000;">"</span><span style="color: #800000;">now</span><span style="color: #800000;">"</span>
    <span style="color: #0000ff;">is</span> an alias <span style="color: #0000ff;">for</span> <span style="color: #800000;">"</span><span style="color: #800000;">+0</span><span style="color: #800000;">"</span>, i.e. <span style="color: #0000ff;">for</span> triggering an immediate shutdown. If no time argument <span style="color: #0000ff;">is</span> specified, <span style="color: #800000;">"</span><span style="color: #800000;">+1</span><span style="color: #800000;">"</span> <span style="color: #0000ff;">is</span><span style="color: #000000;"> implied. Note that to specify a wall message you must specify a time argument, too. If the time argument </span><span style="color: #0000ff;">is</span> used, 5 minutes before the system goes down the /run/nologin file <span style="color: #0000ff;">is</span> created to ensure that further logins shall <span style="color: #0000ff;">not</span><span style="color: #000000;"> be allowed.

    OPTIONS

    The following options are understood:

       </span>--<span style="color: #000000;">help
    Print a short help text </span><span style="color: #0000ff;">and</span><span style="color: #000000;"> exit. </span>-H, --<span style="color: #000000;">halt
    Halt the machine. </span>-P, --<span style="color: #000000;">poweroff
    Power</span>-<span style="color: #000000;">off the machine (the default). </span>-r, --<span style="color: #000000;">reboot
    Reboot the machine. </span>-<span style="color: #000000;">h
    Equivalent to </span>--poweroff, unless --halt <span style="color: #0000ff;">is</span><span style="color: #000000;"> specified. </span>-<span style="color: #000000;">k
    Do </span><span style="color: #0000ff;">not</span> halt, power-<span style="color: #000000;">off, reboot, just write wall message. </span>--no-<span style="color: #000000;">wall
    Do </span><span style="color: #0000ff;">not</span> send wall message before halt, power-<span style="color: #000000;">off, reboot. </span>-<span style="color: #000000;">c
    Cancel a pending shutdown. This may be used cancel the effect of an invocation of shutdown with a time argument that </span><span style="color: #0000ff;">is</span> <span style="color: #0000ff;">not</span> <span style="color: #800000;">"</span><span style="color: #800000;">+0</span><span style="color: #800000;">"</span> <span style="color: #0000ff;">or</span> <span style="color: #800000;">"</span><span style="color: #800000;">now</span><span style="color: #800000;">"</span><span style="color: #000000;">.

    EXIT STATUS

    On success, 0 is returned, a non-zero failure code otherwise.

    SEE ALSO

    systemd(1), systemctl(1), halt(8), wall(1)

    Manual page shutdown(8) line 1 (press h for help or q to quit)

    shutdown实战举例

    • shutdown -h +1 #一分钟后关闭Linux操作系统
    • shutdown -c #取消shutdown操作
    • shutdown -r 11:11 #11:11重启Linux系统
    • shutdown -h now#now即现在,立刻关闭操作系统

    1.3.2 关机与重启命令:halt/poweroff/reboot

      从Redhat或CentOS6开始,这三者对应的man帮助信息都是同一个,而halt和poweroff命令是reboot命令的链接文件;

    • reboot 选项
    • halt 选项
    • poweroff 选项

    通常情况下,该3命令都不带任何参数

    [root@iZ2ze2m3z176dpbiaolifiZ ~]# ls /sbin/poweroff
    /sbin/poweroff
    [root@iZ2ze2m3z176dpbiaolifiZ ~]# ls /sbin/halt
    /sbin/halt
    [root@iZ2ze2m3z176dpbiaolifiZ ~]# ls /sbin/reboot
    /sbin/reboot
    [root@iZ2ze2m3z176dpbiaolifiZ ~]# ls -l /sbin/poweroff
    lrwxrwxrwx 1 root root 16 Oct 15 2017 /sbin/poweroff -> ../bin/systemctl
    [root@iZ2ze2m3z176dpbiaolifiZ ~]# ls -l /sbin/halt
    lrwxrwxrwx 1 root root 16 Oct 15 2017 /sbin/halt -> ../bin/systemctl
    [root@iZ2ze2m3z176dpbiaolifiZ ~]# ls -l /sbin/reboot
    lrwxrwxrwx 1 root root 16 Oct 15 2017 /sbin/reboot -> ../bin/systemctl
    [root@iZ2ze2m3z176dpbiaolifiZ ~]#

    1.3.3 关机、重启和注销的命令列表

    1)关机命令

    • shutdown -h now
    • shutdown -h +1
    • halt
    • init 0
    • poweroff

    2)重启命令

    • reboot
    • shutdown -r now
    • shutdown -r +1
    • init 6

    3)注销命令

    • logout
    • exit
    • Ctrl + d(本质就是logout)

    1.4 老男孩的运维思想

      基础不牢,地动山摇!很多高大上的技术都是由细小的基础知识累积而成的!

      Linux命令正是组成Linux系统最核心的、重要的基础之一。牢牢掌握基础命令,方能在日后使用Linux时随心所欲。

    第1章 Linux命令行简介的更多相关文章

    1. 核心系统命令实战 第一章Linux命令行简介

      第一章Linux命令行简介 1.1 Linux命令行概述 1.1.1 Linux 命令行的开启和退出 开启:登陆账号密码进入系统 退出:exit/logout  快捷键:Ctrl+d 1.1.2 Li ...

    2. 第一章 Linux命令行简介

      1 Linux系统命令操作语法的格式 命令_[参数选项]_[文件或路径]    其中 _ 至少一个空格    如:rm -f /etc/hosts    其中/etc/hosts完整路径不带空格   ...

    3. SLAM+语音机器人DIY系列:(一)Linux基础——3.Linux命令行基础操作

      摘要 由于机器人SLAM.自动导航.语音交互这一系列算法都在机器人操作系统ROS中有很好的支持,所以后续的章节中都会使用ROS来组织构建代码:而ROS又是安装在Linux发行版ubuntu系统之上的, ...

    4. 40个超有趣的Linux命令行彩蛋和游戏

      40个有趣的Linux命令行彩蛋和游戏,让你假装成日理万机的黑客高手.附一键安装脚本,在树莓派和ubuntu云主机上亲测成功,有些还可以在Windows的DOS命令行中运行. 本文配套B站视频:40个 ...

    5. Linux命令行–初识Linux shell

      shell及脚本简介  GNU/Linux shell 是个交互工具,它为用户提供了启动程序.管理文件系统上的文件以及管理运行在Linux系统上的进程的途径 . shell的核心是命令行提示符 它是s ...

    6. 20个linux命令行工具监视性能(下)

      昨天晚上第一次翻译了<20 Command Line Tools to Monitor Linux Performance>中的前十个命令,翻译得不是很好,今天晚上继续把后面的十个也翻译给 ...

    7. 在 Linux 命令行中使用和执行 PHP 代码

      PHP是一个开源服务器端脚本语言,最初这三个字母代表的是“Personal Home Page”,而现在则代表的是“PHP:Hypertext Preprocessor”,它是个递归首字母缩写.它是一 ...

    8. 《Linux命令行大全》系列(三、Linux 系统)

      在<Linux命令行大全>一书中,第3章名称是 Linux 系统. 概念太大,不过该节内容却是 Linux 系统最为核心的基础——查看 Linux 系统. ls 命令 显示目录自身信息或目 ...

    9. [Android] 基于 Linux 命令行构建 Android 应用(七):自动化构建

      本章将演示如何基于 Linux 命令行构建 Android 应用,在开始本章之前,希望你已经阅读之前几章内容. 本文环境为 RHEL Sandiego 32-bits,要基于 Linux CLI 构建 ...

    随机推荐

    1. [2018HN省队集训D6T2] girls

      [2018HN省队集训D6T2] girls 题意 给定一张 \(n\) 个点 \(m\) 条边的无向图, 求选三个不同结点并使它们两两不邻接的所有方案的权值和 \(\bmod 2^{64}\) 的值 ...

    2. 第2次作业——APP案例分析

      第一部分 调研, 评测 1.下载软件并使用起来,描述最简单直观的个人第一次上手体验. 知乎,中文互联网最大的知识平台.使用知乎这个APP3年了,目睹了它的兴盛(当然没有衰亡@_@).打开这款APP,主 ...

    3. 026.3 网络编程 TCP聊天

      分为客户端和服务端,分别进行收发操作##########################################################################客户端:###思 ...

    4. log4jnet不记录日志的问题解决

      背景:dll文件从别人项目里复制过来的,配置文件是从别的项目里配置过来的.然后就是不写日志. 最后经过搜索原项目,发现需要在AssemblyInfo.cs文件里加一段话, [assembly: log ...

    5. js面向对象理解

      js面向对象理解 ECMAScript 有两种开发模式:1.函数式(过程化),2.面向对象(OOP).面向对象的语言有一个标志,那就是类的概念,而通过类可以创建任意多个具有相同属性和方法的对象.但是, ...

    6. virtualbox+vagrant学习-3-Vagrant Share-4-Vagrant Connect

      Vagrant Connect vagrant可以共享到vagrant环境的任何或每个端口,而不仅仅是SSH和HTTP.“vagrant connect”命令为连接人员提供一个静态IP,他们可以使用该 ...

    7. 为什么会有object这么一个根基类

      先问一个问题,为什么需要有一个统一的基类:Object?甚至,我们在编程语言中也常常见到这种模式,比如Java中的object.C#的object,甚至一些纯对象的脚本语言(Ruby里连数字123都是 ...

    8. 关于Koala 中文编译出错

      关于koala: 我们知道koala是一个前端预处理器语言图形编译工具,支持Less.Sass.Compass.CoffeeScript,帮助web开发者更高效地使用它们进行开发.跨平台运行,完美兼容 ...

    9. Kubernetes介绍

      Kubernetes介绍 一.Kubernetes起源 Kubernetes (K8s) 是 Google 在 2014 年发布的一个开源项目.   据说 Google 的数据中心里运行着超过 20 ...

    10. PAT乙级1014

      1014 福尔摩斯的约会 (20 分)   大侦探福尔摩斯接到一张奇怪的字条:我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d& ...