Linux系统的命令一般都是以下所示的格式:javascript
命令名称 [命名参数] [命令对象]
获取登陆信息 - w / who / last。html
[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。html5
Shell也被称为“壳”,它是用户与内核交流的翻译官,简单的说就是人与计算机交互的接口。目前不少Linux系统默认的Shell都是bash(Bourne Again SHell),由于它可使用Tab键进行命令补全、能够保存历史命令、能够方便的配置环境变量以及执行批处理操做等。java
[root@izwz97tbgo9lkabnat2lo8z ~]# ps PID TTY TIME CMD 3531 pts/0 00:00:00 bash 3553 pts/0 00:00:00 ps
查看命令的说明 - whatis。python
[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。mysql
[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。linux
[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。ios
[root@izwz97tbgo9lkabnat2lo8z ~]# su hellokitty [hellokitty@izwz97tbgo9lkabnat2lo8z root]$
以管理员身份执行命令 - sudo。nginx
[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
目录下。git
登入登出相关 - logout / exit / adduser / userdel / passwd / ssh。
[root@izwz97tbgo9lkabnat2lo8z ~]# adduser hellokitty [root@izwz97tbgo9lkabnat2lo8z ~]# passwd hellokitty 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。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# history ... 452 ls 453 cd Python-3.6.5/ 454 clear 455 history [root@iZwz97tbgo9lkabnat2lo8Z ~]# !454
说明:查看到历史命令以后,能够用
!历史命令编号
来从新执行该命令;经过history -c
能够清除历史命令。
建立/删除目录 - mkdir / rmdir。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# mkdir abc [root@iZwz97tbgo9lkabnat2lo8Z ~]# mkdir -p xyz/abc [root@iZwz97tbgo9lkabnat2lo8Z ~]# rmdir abc
建立/删除文件 - touch / rm。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# touch readme.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# touch error.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# rm error.txt rm: remove regular empty file ‘error.txt’? y [root@iZwz97tbgo9lkabnat2lo8Z ~]# rm -rf xyz
touch命令用于建立空白文件或修改文件时间。在Linux系统中一个文件有三种时间:
更改内容的时间 - mtime。
更改权限的时间 - ctime。
最后访问时间 - atime。
rm的几个重要参数:
-i:交互式删除,每一个删除项都会进行询问。
-r:删除目录并递归的删除目录中的文件和目录。
-f:强制删除,忽略不存在的文件,没有任何提示。
切换和查看当前工做目录 - cd / pwd。
说明:
cd
命令后面能够跟相对路径(以当前路径做为参照)或绝对路径(以/
开头)来切换到指定的目录,也能够用cd ..
来返回上一级目录。
查看目录内容 - ls。
-l:以长格式查看文件和目录。
-a:显示以点开头的文件和目录(隐藏文件)。
-R:遇到目录要进行递归展开(继续列出目录下面的文件和目录)。
-d:只列出目录,不列出其余内容。
-S/-t:按大小/时间排序。
查看文件内容 - cat / head / tail / more / less。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# wget http://www.sohu.com/ -O sohu.html --2018-06-20 18:42:34-- http://www.sohu.com/ Resolving www.sohu.com (www.sohu.com)... 14.18.240.6 Connecting to www.sohu.com (www.sohu.com)|14.18.240.6|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 212527 (208K) [text/html] Saving to: ‘sohu.html’ 100%[==================================================>] 212,527 --.-K/s in 0.03s 2018-06-20 18:42:34 (7.48 MB/s) - ‘sohu.html’ saved [212527/212527] [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat sohu.html ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# head -10 sohu.html <!DOCTYPE html> <html> <head> <title>搜狐</title> <meta name="Keywords" content="搜狐,门户网站,新媒体,网络媒体,新闻,财经,体育,娱乐,时尚,汽车,房产,科技,图片,论坛,微博,博客,视频,电影,电视剧"/> <meta name="Description" content="搜狐网为用户提供24小时不间断的最新资讯,及搜索、邮件等网络服务。内容包括全球热点事件、突发新闻、时事评论、热播影视剧、体育赛事、行业动态、生活服务信息,以及论坛、博客、微博、个人搜狐等互动空间。" /> <meta name="shenma-site-verification" content="1237e4d02a3d8d73e96cbd97b699e9c3_1504254750"> <meta charset="utf-8"/> <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/> [root@iZwz97tbgo9lkabnat2lo8Z ~]# tail -2 sohu.html </body> </html> [root@iZwz97tbgo9lkabnat2lo8Z ~]# less sohu.html ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat -n sohu.html | more ...
拷贝/移动文件 - cp / mv。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# mkdir backup [root@iZwz97tbgo9lkabnat2lo8Z ~]# cp sohu.html backup/ [root@iZwz97tbgo9lkabnat2lo8Z ~]# cd backup [root@iZwz97tbgo9lkabnat2lo8Z backup]# ls sohu.html [root@iZwz97tbgo9lkabnat2lo8Z backup]# mv sohu.html sohu_index.html [root@iZwz97tbgo9lkabnat2lo8Z backup]# ls sohu_index.html
查找文件和查找内容 - find / grep。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# find / -name "*.html" /root/sohu.html /root/backup/sohu_index.html [root@izwz97tbgo9lkabnat2lo8z ~]# find . -atime 7 -type f -print [root@izwz97tbgo9lkabnat2lo8z ~]# find . -type f -size +2k [root@izwz97tbgo9lkabnat2lo8z ~]# find . -type f -name "*.swp" -delete [root@iZwz97tbgo9lkabnat2lo8Z ~]# grep "<script>" sohu.html -n 20:<script> [root@iZwz97tbgo9lkabnat2lo8Z ~]# grep -E \<\/?script.*\> sohu.html -n 20:<script> 22:</script> 24:<script src="//statics.itc.cn/web/v3/static/js/es5-shim-08e41cfc3e.min.js"></script> 25:<script src="//statics.itc.cn/web/v3/static/js/es5-sham-1d5fa1124b.min.js"></script> 26:<script src="//statics.itc.cn/web/v3/static/js/html5shiv-21fc8c2ba6.js"></script> 29:<script type="text/javascript"> 52:</script> ...
说明:
grep
在搜索字符串时可使用正则表达式,若是须要使用正则表达式能够用grep -E
或者直接使用egrep
。
连接 - ln。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l sohu.html -rw-r--r-- 1 root root 212131 Jun 20 19:15 sohu.html [root@iZwz97tbgo9lkabnat2lo8Z ~]# ln /root/sohu.html /root/backup/sohu_backup [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l sohu.html -rw-r--r-- 2 root root 212131 Jun 20 19:15 sohu.html [root@iZwz97tbgo9lkabnat2lo8Z ~]# ln /root/sohu.html /root/backup/sohu_backup2 [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l sohu.html -rw-r--r-- 3 root root 212131 Jun 20 19:15 sohu.html [root@iZwz97tbgo9lkabnat2lo8Z ~]# ln -s /etc/centos-release sysinfo [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l sysinfo lrwxrwxrwx 1 root root 19 Jun 20 19:21 sysinfo -> /etc/centos-release [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat sysinfo CentOS Linux release 7.4.1708 (Core) [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat /etc/centos-release CentOS Linux release 7.4.1708 (Core)
说明:连接能够分为硬连接和软连接(符号连接)。硬连接能够认为是一个指向文件数据的指针,就像Python中对象的引用计数,每添加一个硬连接,文件的对应连接数就增长1,只有当文件的连接数为0时,文件所对应的存储空间才有可能被其余文件覆盖。咱们日常删除文件时其实并无删除硬盘上的数据,咱们删除的只是一个指针,或者说是数据的一条使用记录,因此相似于“文件粉碎机”之类的软件在“粉碎”文件时除了删除文件指针,还会在文件对应的存储区域填入数据来保证文件没法再恢复。软连接相似于Windows系统下的快捷方式,当软连接连接的文件被删除时,软连接也就失效了。
压缩/解压缩和归档/解归档 - gzip / gunzip / xz / tar。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# wget http://download.redis.io/releases/redis-4.0.10.tar.gz --2018-06-20 19:29:59-- http://download.redis.io/releases/redis-4.0.10.tar.gz Resolving download.redis.io (download.redis.io)... 109.74.203.151 Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 1738465 (1.7M) [application/x-gzip] Saving to: ‘redis-4.0.10.tar.gz’ 100%[==================================================>] 1,738,465 70.1KB/s in 74s 2018-06-20 19:31:14 (22.9 KB/s) - ‘redis-4.0.10.tar.gz’ saved [1738465/1738465] [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls redis* redis-4.0.10.tar.gz [root@iZwz97tbgo9lkabnat2lo8Z ~]# gunzip redis-4.0.10.tar.gz [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls redis* redis-4.0.10.tar [root@iZwz97tbgo9lkabnat2lo8Z ~]# tar -xvf redis-4.0.10.tar redis-4.0.10/ redis-4.0.10/.gitignore redis-4.0.10/00-RELEASENOTES redis-4.0.10/BUGS redis-4.0.10/CONTRIBUTING redis-4.0.10/COPYING redis-4.0.10/INSTALL redis-4.0.10/MANIFESTO redis-4.0.10/Makefile redis-4.0.10/README.md redis-4.0.10/deps/ redis-4.0.10/deps/Makefile redis-4.0.10/deps/README.md ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls redis* redis-4.0.10.tar redis-4.0.10: 00-RELEASENOTES COPYING Makefile redis.conf runtest-sentinel tests BUGS deps MANIFESTO runtest sentinel.conf utils CONTRIBUTING INSTALL README.md runtest-cluster src
其余工具 - sort / uniq / diff / tr / cut / paste / file / wc。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# cat foo.txt grape apple pitaya [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat bar.txt 100 200 300 400 [root@iZwz97tbgo9lkabnat2lo8Z ~]# paste foo.txt bar.txt grape 100 apple 200 pitaya 300 400 [root@iZwz97tbgo9lkabnat2lo8Z ~]# paste foo.txt bar.txt > hello.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# cut -b 4-8 hello.txt pe 10 le 20 aya 3 0 [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat hello.txt | tr '\t' ',' grape,100 apple,200 pitaya,300 ,400 [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget https://www.baidu.com/img/bd_logo1.png --2018-06-20 18:46:53-- https://www.baidu.com/img/bd_logo1.png Resolving www.baidu.com (www.baidu.com)... 220.181.111.188, 220.181.112.244 Connecting to www.baidu.com (www.baidu.com)|220.181.111.188|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 7877 (7.7K) [image/png] Saving to: ‘bd_logo1.png’ 100%[==================================================>] 7,877 --.-K/s in 0s 2018-06-20 18:46:53 (118 MB/s) - ‘bd_logo1.png’ saved [7877/7877][root@iZwz97tbgo9lkabnat2lo8Z ~]# file bd_logo1.png bd_logo1.png: PNG image data, 540 x 258, 8-bit colormap, non-interlaced [root@iZwz97tbgo9lkabnat2lo8Z ~]# wc sohu.html 2979 6355 212527 sohu.html [root@iZwz97tbgo9lkabnat2lo8Z ~]# wc -l sohu.html 2979 sohu.html
管道的使用 - |。
例子:查找当前目录下文件个数。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# find ./ | wc -l 6152
例子:列出当前路径下的文件和文件夹,给每一项加一个编号。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# ls | cat -n 1 dump.rdb 2 mongodb-3.6.5 3 Python-3.6.5 4 redis-3.2.11 5 redis.conf
例子:查找record.log中包含AAA,但不包含BBB的记录的总数
[root@iZwz97tbgo9lkabnat2lo8Z ~]# cat record.log | grep AAA | grep -v BBB | wc -l
输出重定向和错误重定向 - > / >> / 2>。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# cat readme.txt banana apple grape apple grape watermelon pear pitaya [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat readme.txt | sort | uniq > result.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat result.txt apple banana grape pear pitaya watermelon
输入重定向 - <。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# echo 'hello, world!' > hello.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# wall < hello.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# Broadcast message from root@iZwz97tbgo9lkabnat2lo8Z (Wed Jun 20 19:43:05 2018): hello, world! [root@iZwz97tbgo9lkabnat2lo8Z ~]# echo 'I will show you some code.' >> hello.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# wall < hello.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# Broadcast message from root@iZwz97tbgo9lkabnat2lo8Z (Wed Jun 20 19:43:55 2018): hello, world! I will show you some code.
alias
[root@iZwz97tbgo9lkabnat2lo8Z ~]# alias ll='ls -l' [root@iZwz97tbgo9lkabnat2lo8Z ~]# alias frm='rm -rf' [root@iZwz97tbgo9lkabnat2lo8Z ~]# ll ... drwxr-xr-x 2 root root 4096 Jun 20 12:52 abc ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# frm abc
unalias
[root@iZwz97tbgo9lkabnat2lo8Z ~]# unalias frm [root@iZwz97tbgo9lkabnat2lo8Z ~]# frm sohu.html -bash: frm: command not found
时间和日期 - date / cal。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# date Wed Jun 20 12:53:19 CST 2018 [root@iZwz97tbgo9lkabnat2lo8Z ~]# cal June 2018 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 [root@iZwz97tbgo9lkabnat2lo8Z ~]# cal 5 2017 May 2017 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
录制操做脚本 - script。
给用户发送消息 - mesg / write / wall / mail。
命名规则:文件名的最大长度与文件系统类型有关,通常状况下,文件名不该该超过255个字符,虽然绝大多数的字符均可以用于文件名,可是最好使用英文大小写字母、数字、下划线、点这样的符号。文件名中虽然可使用空格,但应该尽量避免使用空格,不然在输入文件名时须要用将文件名放在双引号中或者经过\
对空格进行转义。
扩展名:在Linux系统下文件的扩展名是可选的,可是使用扩展名有助于对文件内容的理解。有些应用程序要经过扩展名来识别文件,可是更多的应用程序并不依赖文件的扩展名,就像file
命令在识别文件时并非依据扩展名来断定文件的类型。
隐藏文件:以点开头的文件在Linux系统中是隐藏文件(不可见文件)。
/bin - 基本命令的二进制文件。
/boot - 引导加载程序的静态文件。
/dev - 设备文件。
/etc - 配置文件。
/home - 普通用户主目录的父目录。
/lib - 共享库文件。
/lib64 - 共享64位库文件。
/lost+found - 存放未连接文件。
/media - 自动识别设备的挂载目录。
/mnt - 临时挂载文件系统的挂载点。
/opt - 可选插件软件包安装位置。
/proc - 内核和进程信息。
/root - 超级管理员用户主目录。
/run - 存放系统运行时须要的东西。
/sbin - 超级用户的二进制文件。
/sys - 设备的伪文件系统。
/tmp - 临时文件夹。
/usr - 用户应用目录。
/var - 变量数据目录。
chmod - 改变文件模式比特。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l ... -rw-r--r-- 1 root root 211878 Jun 19 16:06 sohu.html ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# chmod g+w,o+w sohu.html [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l ... -rw-rw-rw- 1 root root 211878 Jun 19 16:06 sohu.html ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# chmod 644 sohu.html [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l ... -rw-r--r-- 1 root root 211878 Jun 19 16:06 sohu.html ...
说明:经过上面的例子能够看出,用
chmod
改变文件模式比特有两种方式:一种是字符设定法,另外一种是数字设定法。除了chmod
以外,能够经过umask
来设定哪些权限将在新文件的默认权限中被删除。
长格式查看目录或文件时显示结果及其对应权限的数值以下表所示。
chown - 改变文件全部者。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l ... -rw-r--r-- 1 root root 54 Jun 20 10:06 readme.txt ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# chown hellokitty readme.txt [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l ... -rw-r--r-- 1 hellokitty root 54 Jun 20 10:06 readme.txt ...
列出文件系统的磁盘使用情况 - df。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 40G 5.0G 33G 14% / devtmpfs 486M 0 486M 0% /dev tmpfs 497M 0 497M 0% /dev/shm tmpfs 497M 356K 496M 1% /run tmpfs 497M 0 497M 0% /sys/fs/cgroup tmpfs 100M 0 100M 0% /run/user/0
磁盘分区表操做 - fdisk。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# fdisk -l Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000a42f4 Device Boot Start End Blocks Id System /dev/vda1 * 2048 83884031 41940992 83 Linux Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
格式化文件系统 - mkfs。
文件系统检查 - fsck。
挂载/卸载 - mount / umount。
启动vim。能够经过vi
或vim
命令来启动vim,启动时能够指定文件名来打开一个文件,若是没有指定文件名,也能够在保存的时候指定文件名。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# vim guess.py
命令模式、编辑模式和末行模式:启动vim进入的是命令模式(也称为Normal模式),在命令模式下输入英文字母i
会进入编辑模式(Insert模式),屏幕下方出现-- INSERT --
提示;在编辑模式下按下Esc
会回到命令模式,此时若是输入英文:
会进入末行模式,在末行模式下输入q!
能够在不保存当前工做的状况下强行退出vim;在命令模式下输入v
会进入可视模式(Visual模式),能够用光标选择一个区域再完成对应的操做。
保存和退出vim:在命令模式下输入:
进入末行模式,输入wq
能够实现保存退出;若是想放弃编辑的内容输入q!
强行退出,这一点刚才已经提到过了;在命令模式下也能够直接输入ZZ
实现保存退出。若是只想保存文件不退出,那么能够在末行模式下输入w
;能够在w
后面输入空格再指定要保存的文件名。
光标操做。
在命令模式下能够经过h
、j
、k
、l
来控制光标向左、下、上、右的方向移动,能够在字母前输入数字来表示移动的距离,例如:10h
表示向左移动10个字符。
在命令模式下能够经过Ctrl+y
和Ctrl+e
来实现向上、向下滚动一行文本的操做,能够经过Ctrl+f
和Ctrl+b
来实现向前和向后翻页的操做。
在命令模式下能够经过输入英文字母G
将光标移到文件的末尾,能够经过gg
将光标移到文件的开始,也能够经过在G
前输入数字来将光标移动到指定的行。
文本操做。
删除:在命令模式下能够用dd
来删除整行;能够在dd
前加数字来指定删除的行数;能够用d$
来实现删除从光标处删到行尾的操做,也能够经过d0
来实现从光标处删到行首的操做;若是想删除一个单词,可使用dw
;若是要删除全文,能够在输入:%d
(其中:
用来从命令模式进入末行模式)。
复制和粘贴:在命令模式下能够用yy
来复制整行;能够在yy
前加数字来指定复制的行数;能够经过p
将复制的内容粘贴到光标所在的地方。
撤销和恢复:在命令模式下输入u
能够撤销以前的操做;经过Ctrl+r
能够恢复被撤销的操做。
对内容进行排序:在命令模式下输入%!sort
。
查找和替换。
查找操做须要输入/
进入末行模式并提供正则表达式来匹配与之对应的内容,例如:/doc.*\.
,输入n
来向前搜索,也能够输入N
来向后搜索。
替换操做须要输入:
进入末行模式并指定搜索的范围、正则表达式以及替换后的内容和匹配选项,例如::1,$s/doc.*/hello/gice
,其中:
g
- global:全局匹配。
i
- ignore case:忽略大小写匹配。
c
- confirm:替换时须要确认。
e
- error:忽略错误。
参数设定:在输入:
进入末行模式后能够对vim进行设定。
设置Tab键的空格数:set ts=4
设置显示/不显示行号:set nu
/ set nonu
设置启用/关闭高亮语法:syntax on
/ syntax off
设置显示标尺(光标所在的行和列): set ruler
设置启用/关闭搜索结果高亮:set hls
/ set nohls
说明:若是但愿上面的这些设定在每次启动vim时都能生效,须要将这些设定写到用户主目录下的.vimrc文件中。
高级技巧
比较多个文件。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# vim -d foo.txt bar.txt
打开多个文件。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# vim foo.txt bar.txt hello.txt
启动vim后只有一个窗口显示的是foo.txt,能够在末行模式中输入ls
查看到打开的三个文件,也能够在末行模式中输入b <num>
来显示另外一个文件,例如能够用:b 2
将bar.txt显示出来,能够用:b 3
将hello.txt显示出来。
拆分和切换窗口。
能够在末行模式中输入sp
或vs
来实现对窗口的水平或垂直拆分,这样咱们就能够同时打开多个编辑窗口,经过按两次Ctrl+w
就能够实现编辑窗口的切换,在一个窗口中执行退出操做只会关闭对应的窗口,其余的窗口继续保留。
映射快捷键:在vim下能够将一些经常使用操做映射为快捷键来提高工做效率。
例子1:在命令模式下输入F4
执行从第一行开始删除10000行代码的操做。
:map <F4> gg10000dd。
例子2:在编辑模式下输入__main
直接补全为if __name__ == '__main__':
。
:inoremap __main if __name__ == '__main__':
说明:上面例子2的
inoremap
中的i
表示映射的键在编辑模式使用,nore
表示不要递归,这一点很是重要,不然若是键对应的内容中又出现键自己,就会引起递归(至关于进入了死循环)。若是但愿映射的快捷键每次启动vim时都能生效,须要将映射写到用户主目录下的.vimrc文件中。
录制宏。
在命令模式下输入qa
开始录制宏(其中a
是寄存器的名字,也能够是其余英文字母或0-9的数字)。
执行你的操做(光标操做、编辑操做等),这些操做都会被录制下来。
若是录制的操做已经完成了,按q
结束录制。
经过@a
(a
是刚才使用的寄存器的名字)播放宏,若是要屡次执行宏能够在前面加数字,例如100@a
表示将宏播放100次。
能够试一试下面的例子来体验录制宏的操做,该例子来源于Harttle Land网站,该网站上提供了不少关于vim的使用技巧,有兴趣的能够去了解一下。
yum - Yellowdog Updater Modified。
yum search
:搜索软件包,例如yum search nginx
。
yum list installed
:列出已经安装的软件包,例如yum list installed | grep zlib
。
yum install
:安装软件包,例如yum install nginx
。
yum remove
:删除软件包,例如yum remove nginx
。
yum update
:更新软件包,例如yum update
能够更新全部软件包,而yum update tar
只会更新tar。
yum check-update
:检查有哪些能够更新的软件包。
yum info
:显示软件包的相关信息,例如yum info nginx
。
rpm - Redhat Package Manager。
安装软件包:rpm -ivh <packagename>.rpm
。
移除软件包:rpm -e <packagename>
。
查询软件包:rpm -qa
,例如能够用rpm -qa | grep mysql
来检查是否安装了MySQL相关的软件包。
下面以Nginx为例,演示如何使用yum安装软件。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# yum -y install nginx ... Installed: nginx.x86_64 1:1.12.2-2.el7 Dependency Installed: nginx-all-modules.noarch 1:1.12.2-2.el7 nginx-mod-http-geoip.x86_64 1:1.12.2-2.el7 nginx-mod-http-image-filter.x86_64 1:1.12.2-2.el7 nginx-mod-http-perl.x86_64 1:1.12.2-2.el7 nginx-mod-http-xslt-filter.x86_64 1:1.12.2-2.el7 nginx-mod-mail.x86_64 1:1.12.2-2.el7 nginx-mod-stream.x86_64 1:1.12.2-2.el7 Complete! [root@iZwz97tbgo9lkabnat2lo8Z ~]# yum info nginx Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Installed Packages Name : nginx Arch : x86_64 Epoch : 1 Version : 1.12.2 Release : 2.el7 Size : 1.5 M Repo : installed From repo : epel Summary : A high performance web server and reverse proxy server URL : http://nginx.org/ License : BSD Description : Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and : IMAP protocols, with a strong focus on high concurrency, performance and low : memory usage. [root@iZwz97tbgo9lkabnat2lo8Z ~]# nginx -v nginx version: nginx/1.12.2
移除Nginx。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# nginx -s stop [root@iZwz97tbgo9lkabnat2lo8Z ~]# yum -y remove nginx
下面以MySQL为例,演示如何使用rpm安装软件。要安装MySQL须要先到MySQL官方网站下载对应的RPM文件,固然要选择和你使用的Linux系统对应的版本。MySQL如今是Oracle公司旗下的产品,在MySQL被收购后,MySQL的做者从新制做了一个MySQL的分支MariaDB,能够经过yum进行安装。若是要安装MySQL须要先经过yum删除mariadb-libs
这个可能会跟MySQL底层库冲突的库,而后还须要安装一个名为libaio
的依赖库。
[root@iZwz97tbgo9lkabnat2lo8Z mysql]# ls mysql-community-client-5.7.22-1.el7.x86_64.rpm mysql-community-common-5.7.22-1.el7.x86_64.rpm mysql-community-libs-5.7.22-1.el7.x86_64.rpm mysql-community-server-5.7.22-1.el7.x86_64.rpm [root@iZwz97tbgo9lkabnat2lo8Z mysql]# yum -y remove mariadb-libs [root@iZwz97tbgo9lkabnat2lo8Z mysql]# yum -y install libaio [root@iZwz97tbgo9lkabnat2lo8Z mysql]# ls | xargs rpm -ivh warning: mysql-community-client-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] ...
说明:因为MySQL和MariaDB的底层依赖库是有冲突的,因此上面咱们首先用
yum
移除了名为mariadb-libs的依赖库并安装了名为libaio的依赖库。因为咱们将安装MySQL所需的rpm文件放在一个独立的目录中,因此能够经过ls
命令查看到安装文件并用xargs
将ls
的输出做为参数交给rpm -ivh
来进行安装。关于MySQL和MariaDB之间的关系,能够阅读维基百科上关于MariaDB的介绍。
移除安装的MySQL。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# rpm -qa | grep mysql | xargs rpm -e
下面以安装MongoDB为例,演示这类软件应该如何安装。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.5.tgz --2018-06-21 18:32:53-- https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.5.tgz Resolving fastdl.mongodb.org (fastdl.mongodb.org)... 52.85.83.16, 52.85.83.228, 52.85.83.186, ... Connecting to fastdl.mongodb.org (fastdl.mongodb.org)|52.85.83.16|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 100564462 (96M) [application/x-gzip] Saving to: ‘mongodb-linux-x86_64-rhel70-3.6.5.tgz’ 100%[==================================================>] 100,564,462 630KB/s in 2m 9s 2018-06-21 18:35:04 (760 KB/s) - ‘mongodb-linux-x86_64-rhel70-3.6.5.tgz’ saved [100564462/100564462] [root@iZwz97tbgo9lkabnat2lo8Z ~]# gunzip mongodb-linux-x86_64-rhel70-3.6.5.tgz [root@iZwz97tbgo9lkabnat2lo8Z ~]# tar -xvf mongodb-linux-x86_64-rhel70-3.6.5.tar mongodb-linux-x86_64-rhel70-3.6.5/README mongodb-linux-x86_64-rhel70-3.6.5/THIRD-PARTY-NOTICES mongodb-linux-x86_64-rhel70-3.6.5/MPL-2 mongodb-linux-x86_64-rhel70-3.6.5/GNU-AGPL-3.0 mongodb-linux-x86_64-rhel70-3.6.5/bin/mongodump mongodb-linux-x86_64-rhel70-3.6.5/bin/mongorestore mongodb-linux-x86_64-rhel70-3.6.5/bin/mongoexport mongodb-linux-x86_64-rhel70-3.6.5/bin/mongoimport mongodb-linux-x86_64-rhel70-3.6.5/bin/mongostat mongodb-linux-x86_64-rhel70-3.6.5/bin/mongotop mongodb-linux-x86_64-rhel70-3.6.5/bin/bsondump mongodb-linux-x86_64-rhel70-3.6.5/bin/mongofiles mongodb-linux-x86_64-rhel70-3.6.5/bin/mongoreplay mongodb-linux-x86_64-rhel70-3.6.5/bin/mongoperf mongodb-linux-x86_64-rhel70-3.6.5/bin/mongod mongodb-linux-x86_64-rhel70-3.6.5/bin/mongos mongodb-linux-x86_64-rhel70-3.6.5/bin/mongo mongodb-linux-x86_64-rhel70-3.6.5/bin/install_compass [root@iZwz97tbgo9lkabnat2lo8Z ~]# vim .bash_profile ... PATH=$PATH:$HOME/bin:$HOME/mongodb-linux-x86_64-rhel70-3.6.5/bin export PATH ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# source .bash_profile [root@iZwz97tbgo9lkabnat2lo8Z ~]# mongod --version db version v3.6.5 git version: a20ecd3e3a174162052ff99913bc2ca9a839d618 OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013 allocator: tcmalloc modules: none build environment: distmod: rhel70 distarch: x86_64 target_arch: x86_64 [root@iZwz97tbgo9lkabnat2lo8Z ~]# mongo --version MongoDB shell version v3.6.5 git version: a20ecd3e3a174162052ff99913bc2ca9a839d618 OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013 allocator: tcmalloc modules: none build environment: distmod: rhel70 distarch: x86_64 target_arch: x86_64
说明:固然也能够经过yum来安装MongoDB,具体能够参照官方网站上给出的说明。
安装Python 3.6。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# yum install gcc [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz [root@iZwz97tbgo9lkabnat2lo8Z ~]# gunzip Python-3.6.5.tgz [root@iZwz97tbgo9lkabnat2lo8Z ~]# tar -xvf Python-3.6.5.tar [root@iZwz97tbgo9lkabnat2lo8Z ~]# cd Python-3.6.5 [root@iZwz97tbgo9lkabnat2lo8Z ~]# ./configure --prefix=/usr/local/python36 --enable-optimizations [root@iZwz97tbgo9lkabnat2lo8Z ~]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel [root@iZwz97tbgo9lkabnat2lo8Z ~]# make && make install ... 配置环境变量 ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# ln -s /usr/local/python36/bin/python3.6 /usr/bin/python3 [root@iZwz97tbgo9lkabnat2lo8Z ~]# python3 --version Python 3.6.5 [root@iZwz97tbgo9lkabnat2lo8Z ~]# python3 -m pip install -U pip [root@iZwz97tbgo9lkabnat2lo8Z ~]# pip3 --version
安装Redis-3.2.12。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# wget http://download.redis.io/releases/redis-3.2.12.tar.gz [root@iZwz97tbgo9lkabnat2lo8Z ~]# gunzip redis-3.2.12.tar.gz [root@iZwz97tbgo9lkabnat2lo8Z ~]# tar -xvf redis-3.2.12.tar [root@iZwz97tbgo9lkabnat2lo8Z ~]# cd redis-3.2.12 [root@iZwz97tbgo9lkabnat2lo8Z ~]# make && make install [root@iZwz97tbgo9lkabnat2lo8Z ~]# redis-server --version Redis server v=3.2.12 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=5bc5cd3c03d6ceb6 [root@iZwz97tbgo9lkabnat2lo8Z ~]# redis-cli --version redis-cli 3.2.12
启动服务。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl start firewalld
终止服务。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl stop firewalld
重启服务。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl restart firewalld
查看服务。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl status firewalld
设置是否开机自启。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl enable firewalld Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service. Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service. [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl disable firewalld Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
crontab命令。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# crontab -e * * * * * echo "hello, world!" >> /root/hello.txt 59 23 * * * rm -f /root/*.log
说明:输入
crontab -e
命令会打开vim来编辑Cron表达式并指定触发的任务,上面咱们定制了两个计划任务,一个是每分钟向/root目录下的hello.txt中追加输出hello, world!
;另外一个是天天23时59分执行删除/root目录下以log为后缀名的文件。若是不知道Cron表达式如何书写,能够参照/etc/crontab文件中的提示(下面会讲到)或者用谷歌或百度搜索一下,也可使用Cron表达式在线生成器来生成Cron表达式。
crontab相关文件。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# cd /etc [root@iZwz97tbgo9lkabnat2lo8Z etc]# ls -l | grep cron -rw-------. 1 root root 541 Aug 3 2017 anacrontab drwxr-xr-x. 2 root root 4096 Mar 27 11:56 cron.d drwxr-xr-x. 2 root root 4096 Mar 27 11:51 cron.daily -rw-------. 1 root root 0 Aug 3 2017 cron.deny drwxr-xr-x. 2 root root 4096 Mar 27 11:50 cron.hourly drwxr-xr-x. 2 root root 4096 Jun 10 2014 cron.monthly -rw-r--r-- 1 root root 493 Jun 23 15:09 crontab drwxr-xr-x. 2 root root 4096 Jun 10 2014 cron.weekly [root@iZwz97tbgo9lkabnat2lo8Z etc]# vim crontab 1 SHELL=/bin/bash 2 PATH=/sbin:/bin:/usr/sbin:/usr/bin 3 MAILTO=root 4 5 # For details see man 4 crontabs 6 7 # Example of job definition: 8 # .---------------- minute (0 - 59) 9 # | .------------- hour (0 - 23) 10 # | | .---------- day of month (1 - 31) 11 # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... 12 # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat 13 # | | | | | 14 # * * * * * user-name command to be executed
经过修改/etc
目录下的crontab文件也可以定制计划任务。
安全远程链接 - ssh。
经过网络获取资源 - wget。
-b 后台下载模式
-O 下载到指定的目录
-r 递归下载
显示/操做网络配置(旧) - ifconfig。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# ifconfig eth0 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.18.61.250 netmask 255.255.240.0 broadcast 172.18.63.255 ether 00:16:3e:02:b6:46 txqueuelen 1000 (Ethernet) RX packets 1067841 bytes 1296732947 (1.2 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 409912 bytes 43569163 (41.5 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions
显示/操做网络配置(新) - ip。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# ip address 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:16:3e:02:b6:46 brd ff:ff:ff:ff:ff:ff inet 172.18.61.250/20 brd 172.18.63.255 scope global eth0 valid_lft forever preferred_lft forever
网络可达性检查 - ping。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# ping www.baidu.com -c 3 PING www.a.shifen.com (220.181.111.188) 56(84) bytes of data. 64 bytes from 220.181.111.188 (220.181.111.188): icmp_seq=1 ttl=51 time=36.3 ms 64 bytes from 220.181.111.188 (220.181.111.188): icmp_seq=2 ttl=51 time=36.4 ms 64 bytes from 220.181.111.188 (220.181.111.188): icmp_seq=3 ttl=51 time=36.4 ms --- www.a.shifen.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 36.392/36.406/36.427/0.156 ms
查看网络服务和端口 - netstat。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# netstat -nap | grep nginx
安全文件拷贝 - scp。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# scp root@1.2.3.4:/root/guido.jpg hellokitty@4.3.2.1:/home/hellokitty/pic.jpg
安全文件传输 - sftp。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# sftp root@120.77.222.217 root@120.77.222.217's password: Connected to 120.77.222.217. sftp>
help
:显示帮助信息。
ls
/lls
:显示远端/本地目录列表。
cd
/lcd
:切换远端/本地路径。
mkdir
/lmkdir
:建立远端/本地目录。
pwd
/lpwd
:显示远端/本地当前工做目录。
get
:下载文件。
put
:上传文件。
rm
:删除远端文件。
bye
/exit
/quit
:退出sftp。
ps - 查询进程。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 Jun23 ? 00:00:05 /usr/lib/systemd/systemd --switched-root --system --deserialize 21 root 2 0 0 Jun23 ? 00:00:00 [kthreadd] ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# ps -ef | grep mysqld root 4943 4581 0 22:45 pts/0 00:00:00 grep --color=auto mysqld mysql 25257 1 0 Jun25 ? 00:00:39 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
kill - 终止进程。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# kill 1234 [root@iZwz97tbgo9lkabnat2lo8Z ~]# kill -9 1234
例子:用一条命令强制终止正在运行的Redis进程。
ps -ef | grep redis | grep -v grep | awk '{print $2}' | xargs kill
将进程置于后台运行。
Ctrl+Z
&
[root@iZwz97tbgo9lkabnat2lo8Z ~]# mongod & [root@iZwz97tbgo9lkabnat2lo8Z ~]# redis-server ... ^Z [4]+ Stopped redis-server
jobs - 查询后台进程。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# jobs [2] Running mongod & [3]- Stopped cat [4]+ Stopped redis-server
bg - 让进程在后台继续运行。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# bg %4 [4]+ redis-server & [root@iZwz97tbgo9lkabnat2lo8Z ~]# jobs [2] Running mongod & [3]+ Stopped cat [4]- Running redis-server &
fg - 将后台进程置于前台。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# fg %4 redis-server ^C5554:signal-handler (1530025281) Received SIGINT scheduling shutdown... 5554:M 26 Jun 23:01:21.413 # User requested shutdown... 5554:M 26 Jun 23:01:21.413 * Saving the final RDB snapshot before exiting. 5554:M 26 Jun 23:01:21.415 * DB saved on disk 5554:M 26 Jun 23:01:21.415 # Redis is now ready to exit, bye bye...
说明:置于前台的进程可使用
Ctrl+C
来终止它。
top - 进程监控。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# top top - 23:04:23 up 3 days, 14:10, 1 user, load average: 0.00, 0.01, 0.05 Tasks: 65 total, 1 running, 64 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.3 us, 0.3 sy, 0.0 ni, 99.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 1016168 total, 191060 free, 324700 used, 500408 buff/cache KiB Swap: 0 total, 0 free, 0 used. 530944 avail Mem ...
查看系统活动信息 - sar。
查看内存使用状况 - free。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# free total used free shared buff/cache available Mem: 1016168 323924 190452 356 501792 531800 Swap: 0 0 0
查看进程使用内存情况 - pmap。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# ps PID TTY TIME CMD 4581 pts/0 00:00:00 bash 5664 pts/0 00:00:00 ps [root@iZwz97tbgo9lkabnat2lo8Z ~]# pmap 4581 4581: -bash 0000000000400000 884K r-x-- bash 00000000006dc000 4K r---- bash 00000000006dd000 36K rw--- bash 00000000006e6000 24K rw--- [ anon ] 0000000001de0000 400K rw--- [ anon ] 00007f82fe805000 48K r-x-- libnss_files-2.17.so 00007f82fe811000 2044K ----- libnss_files-2.17.so ...
报告设备CPU和I/O统计信息 - iostat。