Linux是一个通用操作系统。一个操作系统要负责任务调度、内存分配、处理外围设备I/O等操作。操作系统通常由内核和系统程序(设备驱动、底层库、shell、服务程序等)两部分组成。
Linux内核是芬兰人Linus Torvalds开发的,于1991年9月发布。而Linux操作系统作为Internet时代的产物,它是由全世界许多开发者共同合作开发的,是一个自由的操作系统(注意是自由不是免费)。
Linux系统的命令通常都是如下所示的格式:
命令名称 [命名参数] [命令对象]
获取登录信息 - 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)
查看自己使用的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
查看命令的说明 - 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
查看命令的位置 - 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
查看帮助文档 - man / info / apropos。
[root@izwz97tbgo9lkabnat2lo8z ~]# ps --help
Usage:
ps [options]
Try 'ps --help <simple|list|output|threads|misc|all>'
or 'ps --help <s|l|o|t|m|a>'
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
...
切换用户 - su。
[root@izwz97tbgo9lkabnat2lo8z ~]# su hellokitty
[hellokitty@izwz97tbgo9lkabnat2lo8z root]$
以管理员身份执行命令 - 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)名单中。
登入登出相关 - 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 hellokitty@1.2.3.4
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 ~]#
查看系统和主机名 - uname / hostname。
[root@izwz97tbgo9lkabnat2lo8z ~]# uname
Linux
[root@izwz97tbgo9lkabnat2lo8z ~]# hostname
izwz97tbgo9lkabnat2lo8z
[root@iZwz97tbgo9lkabnat2lo8Z ~]# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
重启和关机 - reboot / init 6 / shutdown / init 0。
查看历史命令 - history。
创建/删除目录 - mkdir / rmdir。
创建/删除文件 - touch / rm。
切换和查看当前工作目录 - cd / pwd。
查看目录内容 - ls。
查看文件内容 - cat / head / tail / more / less。
拷贝/移动文件 - cp / mv。
查看文件及内容 - find / grep。
[root@izwz97tbgo9lkabnat2lo8z ~]# find -name *.html
./index.html
./code/index.html
[root@izwz97tbgo9lkabnat2lo8z ~]# grep "<script>" . -R -n
./index.html:15: <script>
./code/index.html:2884: <script>
./code/foo.html:2:<!--STATUS OK--><html> <head><meta ...
符号链接 - ln。
压缩和归档 - gzip / gunzip / xz / tar。
其他工具 - sort / uniq / diff / file / wc。
启动和退出
命令模式和编辑模式
光标操作
文本操作
查找和替换
/正则表达式
:1,$s/正则表达式/替换后的内容/gice
g - global
i - ignore case
c - confirm
e - error
.vimrc
set ts=4
set nu
高级技巧