Linux系统基础命令

基础命令

Linux系统的命令通常都是如下所示的格式:

命令名称 [命名参数] [命令对象]
  1. 获取登录信息 - w / who / last

    [root@izwz97tbgo9lkabnat2lo8z ~]# w
    23:31:16 up 12:16,  2 users,  load average: 0.00, 0.01, 0.05
    USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
    root     pts/0    182.139.66.250   23:03    4.00s  0.02s  0.00s w
    jackfrue pts/1    182.139.66.250   23:26    3:56   0.00s  0.00s -bash
    [root@izwz97tbgo9lkabnat2lo8z ~]# who
    root     pts/0        2018-04-12 23:03 (182.139.66.250)
    jackfrued pts/1        2018-04-12 23:26 (182.139.66.250)
    [root@izwz97tbgo9lkabnat2lo8z ~]# who am i
    root     pts/0        2018-04-12 23:03 (182.139.66.250)
  2. 查看自己使用的Shell - ps

    Shell也被称为“壳”,它是用户与内核交流的翻译官,简单的说就是人与计算机交互的接口。目前很多Linux系统默认的Shell都是bash(Bourne Again SHell),因为它可以使用Tab键进行命令补全、可以保存历史命令、可以方便的配置环境变量以及执行批处理操作等。

    [root@izwz97tbgo9lkabnat2lo8z ~]# ps
     PID TTY          TIME CMD
    3531 pts/0    00:00:00 bash
    3553 pts/0    00:00:00 ps
  3. 查看命令的说明 - whatis

    [root@izwz97tbgo9lkabnat2lo8z ~]# whatis ps
    ps (1)        - report a snapshot of the current processes.
    [root@izwz97tbgo9lkabnat2lo8z ~]# whatis python
    python (1)    - an interpreted, interactive, object-oriented programming language
  4. 查看命令的位置 - which / whereis

    [root@izwz97tbgo9lkabnat2lo8z ~]# whereis ps
    ps: /usr/bin/ps /usr/share/man/man1/ps.1.gz
    [root@izwz97tbgo9lkabnat2lo8z ~]# whereis python
    python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz
    [root@izwz97tbgo9lkabnat2lo8z ~]# which ps
    /usr/bin/ps
    [root@izwz97tbgo9lkabnat2lo8z ~]# which python
    /usr/bin/python
  5. 查看帮助文档 - man / info / apropos

    [root@izwz97tbgo9lkabnat2lo8z ~]# ps --help
    Usage:
    ps [options]
    Try 'ps --help '
     or 'ps --help '
    for additional help text.
    For more details see ps(1).
    [root@izwz97tbgo9lkabnat2lo8z ~]# man ps
    PS(1)                                User Commands                                PS(1)
    NAME
          ps - report a snapshot of the current processes.
    SYNOPSIS
          ps [options]
    DESCRIPTION
    ...
    [root@izwz97tbgo9lkabnat2lo8z ~]# info ps
    ...
  6. 切换用户 - su

    [root@izwz97tbgo9lkabnat2lo8z ~]# su hellokitty
    [hellokitty@izwz97tbgo9lkabnat2lo8z root]$
  7. 以管理员身份执行命令 - sudo

    [jackfrued@izwz97tbgo9lkabnat2lo8z ~]$ ls /root
    ls: cannot open directory /root: Permission denied
    [jackfrued@izwz97tbgo9lkabnat2lo8z ~]$ sudo ls /root
    [sudo] password for jackfrued:
    calendar.py  code  error.txt  hehe  hello.c  index.html  myconf  result.txt

    说明:如果希望用户能够以管理员身份执行命令,用户必须在sudoers(/etc/sudoers)名单中。

  8. 登入登出相关 - logout / exit / adduser / userdel / passwd / ssh

    [root@izwz97tbgo9lkabnat2lo8z ~]# adduser jackfrued
    [root@izwz97tbgo9lkabnat2lo8z ~]# passwd jackfrued
    Changing password for user jackfrued.
    New password:
    Retype new password:
    passwd: all authentication tokens updated successfully.
    [root@izwz97tbgo9lkabnat2lo8z ~]# ssh [email protected]
    hellokitty@1.2.3.4's password:
    Last login: Thu Apr 12 23:05:32 2018 from 10.12.14.16
    [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ logout
    Connection to 1.2.3.4 closed.
    [root@izwz97tbgo9lkabnat2lo8z ~]#
  9. 查看系统和主机名 - uname / hostname

    [root@izwz97tbgo9lkabnat2lo8z ~]# uname
    Linux
    [root@izwz97tbgo9lkabnat2lo8z ~]# hostname
    izwz97tbgo9lkabnat2lo8z
    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat /etc/centos-release
    CentOS Linux release 7.4.1708 (Core) 
  10. 重启和关机 - reboot / init 6 / shutdown / init 0

  11. 查看历史命令 - history

实用程序

文件和文件夹操作

  1. 创建/删除目录 - mkdir / rmdir

  2. 创建/删除文件 - touch / rm

    • touch命令用于创建空白文件或修改文件时间。在Linux系统中一个文件有三种时间:
      • 更改内容的时间(mtime)
      • 更改权限的时间(ctime)
      • 最后访问时间(atime)
  3. 切换和查看当前工作目录 - cd / pwd

  4. 查看目录内容 - ls

  5. 查看文件内容 - cat / head / tail / more / less

  6. 拷贝/移动文件 - cp / mv

  7. 查看文件及内容 - find / grep

    [root@izwz97tbgo9lkabnat2lo8z ~]# find -name *.html
    ./index.html
    ./code/index.html
    [root@izwz97tbgo9lkabnat2lo8z ~]# grep "
                        
                        

你可能感兴趣的:(linux)