最全的linux基础命令
第1章 linux命令
1.1 线上查询及帮助命令
-
help命令***
help前面接你要查询的命令:例如ls
[root@server02 ~]# ls --help
用法:ls [选项]... [文件]...
列出 FILE 的信息(默认为当前目录)。
如果不指定-cftuvSUX 或--sort 选项,则根据字母大小排序。
长选项必须使用的参数对于短选项时也是必需使用的。
-a, --all 不隐藏任何以. 开始的项目
-A, --almost-all 列出除. 及.. 以外的任何项目
--author 与-l 同时使用时列出每个文件的作者
-b, --escape 以八进制溢出序列表示不可打印的字符
--block-size=大小 块以指定大小的字节为单位
-B, --ignore-backups 不列出任何以"~"字符结束的项目
-c 配合-lt:根据ctime 排序并显示ctime(文件
状态最后更改的时间)
配合-l:显示ctime 但根据名称排序 其他情况:按ctime 排序
-C 每栏由上至下列出项目
--color[=WHEN] 控制是否使用色彩分辨文件。WHEN 可以是
"never"(默认)、"always"或"auto"其中之一
-d, --directory 当遇到目录时列出目录本身而非目录内的文件
-D, --dired 产生适合Emacs 的dired 模式使用的结果
-f 不进行排序,-aU 选项生效,-lst 选项失效
-F, --classify 加上文件类型的指示符号(*/=@| 其中一个)
--format=关键字 交错-x,逗号分隔-m,水平-x,长-l,
单栏-1,详细-l,垂直-C
--full-time 即-l --time-style=full-iso
-g 类似-l,但不列出所有者
--group-directories-first
在文件前分组目录。此选项可与--sort 一起使用,
但是一旦使用--sort=none (-U)将禁用分组
-G, --no-group 以一个长列表的形式,不输出组名
-h, --human-readable 与-l 一起,以易于阅读的格式输出文件大小
(例如 1K 234M 2G)
--si 同上面类似,但是使用1000 为基底而非1024
-H, --dereference-command-line
跟随命令行列出的符号链接
--dereference-command-line-symlink-to-dir
跟随命令行列出的目录的符号链接
--hide=PATTERN 隐藏符合PATTERN 模式的项目
(-a 或 -A 将覆盖此选项)
--indicator-style=方式 指定在每个项目名称后加上指示符号方式:
none (默认),classify (-F),file-type (-p)
-i, --inode 显示每个文件的inode 号
-I, --ignore=PATTERN 不显示任何符合指定shell PATTERN 的项目
-k 即--block-size=1K
-l 使用较长格式列出信息
-L, --dereference 当显示符号链接的文件信息时,显示符号链接所指示
的对象而并非符号链接本身的信息
-m 所有项目以逗号分隔,并填满整行行宽
-n, --numeric-uid-gid 类似 -l,但列出UID 及GID 号
-N, --literal 输出未经处理的项目名称 (如不特别处理控制字符)
-o 类似 -l,但不列出有关组的信息
-p, --indicator-style=slash 对目录加上表示符号"/"
-q, --hide-control-chars 以"?"字符代替无法打印的字符
--show-control-chars 直接显示无法打印的字符 (这是默认方式,除非调用
的程序名称是"ls"而且是在终端输出结果)
-Q, --quote-name 将条目名称括上双引号
--quoting-style=方式 使用指定的quoting 方式显示条目的名称:
literal、locale、shell、shell-always、c、escape
-r, --reverse 排序时保留顺序
-R, --recursive 递归显示子目录
-s, --size 以块数形式显示每个文件分配的尺寸
-S 根据文件大小排序
--sort=WORD 以下是可选用的WORD 和它们代表的相应选项:
extension -X status -c
none -U time -t
size -S atime -u
time -t access -u
version -v use -u
--time=WORD 和-l 同时使用时显示WORD 所代表的时间而非修改时
间:atime、access、use、ctime 或status;加上
--sort=time 选项时会以指定时间作为排序关键字
--time-style=STYLE 和-l 同时使用时根据STYLE 代表的格式显示时间:
full-iso、iso、locale、posix-iso、+FORMAT。
FORMAT 即是"date"所用的时间格式;如果FORMAT
是FORMAT1<换行>FORMAT2,FORMAT1 适用于较旧
的文件而FORMAT2 适用于较新的文件;如果STYLE
以"posix-"开头,则STYLE 仅在POSIX 语系之外
生效。
-t 根据修改时间排序
-T, --tabsize=宽度 指定制表符(Tab)的宽度,而非8 个字符
-t 按修改时间排序
-T, --tabsize=COLS 指定制表符(Tab)的宽度,而非8个字符
-u 同-lt 一起使用:按照访问时间排序并显示
同-l一起使用:显示访问时间并按文件名排序
其他:按照访问时间排序
-U 不进行排序;按照目录顺序列出项目
-v 在文本中进行数字(版本)的自然排序
-w, --width=COLS assume screen width instead of current value
-x list entries by lines instead of by columns
-X sort alphabetically by entry extension
-1 list one file per line
SELinux options:
--lcontext Display security context. Enable -l. Lines
will probably be too wide for most displays.
-Z, --context Display security context so it fits on most
displays. Displays only mode, user, group,
security context and file name.
--scontext Display only security context and file name.
--help 显示此帮助信息并退出
--version 显示版本信息并退出
SIZE 可以是一个可选的整数,后面跟着以下单位中的一个:
KB 1000,K 1024,MB 1000*1000,M 1024*1024,还有 G、T、P、E、Z、Y。
使用色彩来区分文件类型的功能已被禁用,默认设置和 --color=never 同时禁用了它。
使用 --color=auto 选项,ls 只在标准输出被连至终端时才生成颜色代码。
LS_COLORS 环境变量可改变此设置,可使用 dircolors 命令来设置。
退出状态:
0 正常
1 一般问题 (例如:无法访问子文件夹)
2 严重问题 (例如:无法使用命令行参数)
请向bug-coreutils@gnu.org 报告ls 的错误
GNU coreutils 项目主页:<http://www.gnu.org/software/coreutils/>
GNU 软件一般性帮助:<http://www.gnu.org/gethelp/>
请向<http://translationproject.org/team/zh_CN.html> 报告ls 的翻译错误
要获取完整文档,请运行:info coreutils 'ls invocation'
-
man命令****
man后面加你要查询的命令:例如ls
[root@server02 ~]# man ls
LS(1) LS(1)
NAME
ls, dir, vdir - 列目录内容
提要
ls [选项] [文件名...]
POSIX 标准选项: [-CFRacdilqrtu1]
GNU 选项 (短格式):
[-1abcdfgiklmnopqrstuxABCDFGLNQRSUX] [-w cols] [-T cols] [-I pattern] [--full-time] [--format={long,verbose,commas,across,vertical,single-col-
umn}] [--sort={none,time,size,extension}] [--time={atime,access,use,ctime,status}] [--color[={none,auto,always}]] [--help] [--version] [--]
描述( DESCRIPTION )
程序ls先列出非目录的文件项,然后是每一个目录中的"可显示"文件。如果没有选项之外的参数【译注:即文件名部分为空】出现,缺省为 "." (当前目录)。 选
项" -d "使得目录与非目录项同样对待。除非" -a " 选项出现,文件名以"."开始的文件不属"可显示"文件。
以当前目录为准,每一组文件(包括非目录文件项,以及每一内含文件的目录)分别按文件名比较顺序排序。如果" -l "选项存在,每组文件前显示一摘要行: 给出
该组文件长度之和(以 512 字节为单位)。
输出是到标准输出( stdout )。除非以" -C "选项要求按多列输出,输出将是一行一个。然而,输出到终端时,单列输出或多列输出是不确定的。可以分别 用 选
项" -1 " 或" -C "来强制按单列或多列输出。
-C 多列输出,纵向排序。
-F 每个目录名加" / "后缀,每个 FIFO 名加" | "后缀,每个可运行名加" * "后缀。
-R 递归列出遇到的子目录。
-a 列出所有文件,包括以 "." 开头的隐含文件。
-c 使用"状态改变时间"代替"文件修改时间"为依据来排序(使用" -t "选项时)或列出(使用" -l "选项时)。
-d 将目录名象其它文件一样列出,而不是列出它们的内容。
-i 输出文件前先输出文件系列号(即 i 节点号: i-node number)。 -l 列出(以单列格式)文件模式( file mode ),文件的链接数,所有者名,组名,文
件大小(以字节为单位),时间信息,及文件名。缺省时,时间信息显示最近修改时间;可以以选项" -c "和" -u "选择显示其它两种时间信息。对于设 备
文件,原先显示文件大小的区域通常显示的是主要和次要的号(majorand minor device numbers)。
-q 将文件名中的非打印字符输出为问号。(对于到终端的输出这是缺省的。)
-
文件和目录操作命令
1.2.1 ls****
ls:查看列表信息
[root@server02 ~]# ls
10MinuteAtHomeHIITABChallenge.MP4 config.db.p install.log.syslog sdsdsdsd.ts
10MinuteAtHomeHIITABChallenge.ts config.db.t jar.tar t.txt
123.sh dd libevent-2.0.21-stable.tar.gz video.ts
1.sh get_dir.c live.mpg work
aa h5_record.mp4 manpages-zh-1.5.1 wtxt.txt
a_en h5_record.ts manpages-zh-1.5.1.tar.gz 公共的
anaconda-ks.cfg index.html Net.class 模板
bb index.html.1 orderId-generater-0.0.1-SNAPSHOT 视频
btv.ts index.html.2 orderId-generater-0.0.1-SNAPSHOT-bin.zip 图片
catalina.out index.html.3 rev.txt 文档
cctv5_6m.ts index.html.4 rpmbuild 下载
common_zh index.html.5 sad.ts 音乐
config.db install.log sdsd.cap 桌面
ls -l:相当于ll,用来显示目标详细信息
[root@server02 ~]# ls -l
-rw-r--r-- 1 root root 203642732 6月 15 2018 10MinuteAtHomeHIITABChallenge.MP4
-rw-r--r-- 1 root root 223125544 6月 15 2018 10MinuteAtHomeHIITABChallenge.ts
-rw-r--r-- 1 root root 410 7月 2 2018 123.sh
-rw-r--r-- 1 root root 388 7月 2 2018 1.sh
drwxr-xr-x 2 root root 4096 6月 30 2018 aa
-rw-r--r-- 1 root root 0 10月 27 2017 a_en
-rw-------. 1 root root 2625 6月 26 2017 anaconda-ks.cfg
drwxr-xr-x 2 root root 4096 7月 12 2018 bb
-rw-r--r-- 1 root root 40628868 12月 18 16:17 btv.ts
-rw-r--r-- 1 root root 0 10月 27 2017 catalina.out
-rw-r--r-- 1 root root 92783264 5月 8 2018 cctv5_6m.ts
-rw-r--r-- 1 root root 0 10月 27 2017 common_zh
-rw-r--r-- 1 root root 33432 8月 13 2018 config.db
-rw-r--r-- 1 root root 13776 8月 13 2018 config.db.p
-rw-r--r-- 1 root root 16 10月 22 09:06 config.db.t
ls -al:显示隐藏文件(.为隐藏文件)
[root@server02 ~]# ls -al
总用量 726320
dr-xr-x---. 40 root root 4096 2月 19 09:52 .
dr-xr-xr-x. 34 root root 4096 2月 18 09:08 ..
-rw-r--r-- 1 root root 203642732 6月 15 2018 10MinuteAtHomeHIITABChallenge.MP4
-rw-r--r-- 1 root root 223125544 6月 15 2018 10MinuteAtHomeHIITABChallenge.ts
-rw-r--r-- 1 root root 410 7月 2 2018 123.sh
-rw-r--r-- 1 root root 388 7月 2 2018 1.sh
drwxr-xr-x 2 root root 4096 6月 30 2018 aa
drwxr-xr-x 3 root root 4096 10月 28 2017 .abrt
-rw-r--r-- 1 root root 0 10月 27 2017 a_en
-rw-------. 1 root root 2625 6月 26 2017 anaconda-ks.cfg
-rw------- 1 root root 24834 2月 19 20:26 .bash_history
-rw-r--r--. 1 root root 18 5月 20 2009 .bash_logout
-rw-r--r-- 1 root root 318 2月 7 2018 .bash_profile
-rw-r--r-- 1 root root 255 7月 17 2018 .bashrc
drwxr-xr-x 2 root root 4096 7月 12 2018 bb
-rw-r--r-- 1 root root 40628868 12月 18 16:17 btv.ts
drwxr-xr-x 3 root root 4096 9月 21 2017 .cache
-rw-r--r-- 1 root root 0 10月 27 2017 catalina.out
-rw-r--r-- 1 root root 92783264 5月 8 2018 cctv5_6m.ts
-rw-r--r-- 1 root root 0 10月 27 2017 common_zh
drwxr-xr-x 5 root root 4096 9月 21 2017 .config
-rw-r--r-- 1 root root 33432 8月 13 2018 config.db
ls -ltr:按修改时间逆向排序文件和文件夹详细信息(-t:时间 -r:逆向)
[root@server02 ~]# ls -ltr
总用量 725540
-rw-r--r-- 1 root root 850772 12月 22 2015 libevent-2.0.21-stable.tar.gz
-rw-r--r--. 1 root root 12619 6月 26 2017 install.log.syslog
-rw-r--r--. 1 root root 67834 6月 26 2017 install.log
-rw-------. 1 root root 2625 6月 26 2017 anaconda-ks.cfg
drwxr-xr-x 2 root root 4096 9月 21 2017 桌面
drwxr-xr-x 2 root root 4096 9月 21 2017 下载
drwxr-xr-x 2 root root 4096 9月 21 2017 模板
drwxr-xr-x 2 root root 4096 9月 21 2017 音乐
drwxr-xr-x 2 root root 4096 9月 21 2017 文档
drwxr-xr-x 2 root root 4096 9月 21 2017 图片
drwxr-xr-x 2 root root 4096 9月 21 2017 视频
drwxr-xr-x 2 root root 4096 9月 21 2017 公共的
-rw-r--r-- 1 root root 0 10月 27 2017 a_en
-rw-r--r-- 1 root root 0 10月 27 2017 wtxt.txt
-rw-r--r-- 1 root root 0 10月 27 2017 rev.txt
-rw-r--r-- 1 root root 0 10月 27 2017 common_zh
-rw-r--r-- 1 root root 0 10月 27 2017 t.txt
-rw-r--r-- 1 root root 0 10月 27 2017 catalina.out
-rw-r--r-- 1 root root 5019412 12月 9 2017 video.ts
-rw-r--r-- 1 root root 9562886 2月 26 2018 orderId-generater-0.0.1-SNAPSHOT-bin.zip
drwxr-xr-x 3 root root 4096 2月 26 2018 orderId-generater-0.0.1-SNAPSHOT
-rw-r--r-- 1 root root 54794240 3月 16 2018 jar.tar
-rw-r--r-- 1 root root 1808 4月 25 2018 Net.class
-rw-r--r-- 1 tcpdump tcpdump 7646334 4月 26 2018 sdsd.cap
-rw-r--r-- 1 root root 13803460 5月 3 2018 h5_record.mp4
-rw-r--r-- 1 root root 15654384 5月 4 2018 h5_record.ts
-rw-r--r-- 1 root root 92783264 5月 8 2018 cctv5_6m.ts
-rw-r--r-- 1 root root 1494036 5月 10 2018 sdsdsdsd.ts
ls -d:列出指定目录是否存在
[root@oldboyedu ~]# ls -d /oldboy/oldboy01/ --- 列出指定目录是否存在
/oldboy/oldboy01/
ls -1h:以人类可读的方式写出来
[root@oldboy6666 ~]# ls -lh
total 12K
-rw-r--r--. 1 root root 7 Sep 10 16:45 1.txt
-rw-------. 1 root root 1.5K Aug 30 12:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Sep 9 11:23 oldboy01
-rw-r--r--. 1 root root 986 Sep 2 14:36 passwd
[root@oldboy6666 ~]#
ls -hlSr:根据文件的大小逆向排序(-S:文件大小)
[root@oldboy6666 ~] # ls -hlSr /etc
-rw-r--r--. 1 root root 2.0K Apr 11 2018 mail.rc
-rw-r--r--. 1 root root 2.0K Oct 31 2018 virc
-rw-r--r--. 1 root root 2.0K Jun 28 21:59 vimrc
-rw-r--r--. 1 root root 2.0K Oct 30 2018 login.defs
-rw-r--r--. 1 root root 2.0K Sep 12 15:03 profile
-rw-r--r--. 1 root root 2.4K Oct 13 2013 libuser.conf
-rw-r--r--. 1 root root 2.8K Oct 31 2018 bashrc
-rw-r-----. 1 root root 3.2K Oct 30 2018 sudo-ldap.conf
-rw-r--r--. 1 root root 3.2K Oct 30 2018 rsyslog.conf
drwxr-xr-x. 6 root root 4.0K Sep 12 11:51 sysconfig
drwxr-xr-x. 6 root root 4.0K Sep 18 10:58 security
drwxr-xr-x. 2 root root 4.0K Sep 11 17:11 profile.d
drwxr-xr-x. 2 root root 4.0K Aug 30 12:15 pam.d
-r--r-----. 1 root root 4.3K Oct 30 2018 sudoers
-rw-r--r--. 1 root root 4.4K May 16 05:01 wgetrc
-rw-r--r--. 1 root root 4.6K Oct 30 2018 DIR_COLORS.lightbgcolor
-rw-r--r--. 1 root root 5.0K Oct 30 2018 DIR_COLORS
-rw-r--r--. 1 root root 5.1K Nov 5 2018 makedumpfile.conf.sample
-rw-r--r--. 1 root root 5.1K Oct 31 2018 man_db.conf
-rw-r--r--. 1 root root 5.6K Oct 30 2018 DIR_COLORS.256color
-rw-r--r--. 1 root root 6.4K Oct 31 2018 protocols
-rw-------. 1 tss tss 6.9K Aug 4 2017 tcsd.conf
-rw-r--r--. 1 root root 7.1K Aug 30 12:12 kdump.conf
-rw-r--r--. 1 root root 12K Aug 30 12:29 aliases.db
-rw-r--r--. 1 root root 29K Sep 6 11:26 ld.so.cache
-rw-r--r--. 1 root root 51K May 15 2013 mime.types
-rw-r--r--. 1 root root 655K Jun 7 2013 services
ls -lF:查找出来的目录后面会加/
[root@oldboy6666 ~] # ls -lF /etc
total 1164
drwxr-xr-x. 3 root root 101 Aug 30 12:12 abrt/
-rw-r--r--. 1 root root 18 Sep 12 17:04 adjtime
-rw-r--r--. 1 root root 1518 Jun 7 2013 aliases
-rw-r--r--. 1 root root 12288 Aug 30 12:29 aliases.db
drwxr-xr-x. 2 root root 236 Aug 30 12:13 alternatives/
-rw-------. 1 root root 541 Apr 11 2018 anacrontab
-rw-r--r--. 1 root root 55 Oct 30 2018 asound.conf
drwxr-x---. 3 root root 43 Aug 30 12:13 audisp/
drwxr-x---. 3 root root 83 Aug 30 12:29 audit/
drwxr-xr-x. 2 root root 79 Sep 11 12:29 bash_completion.d/
-rw-r--r--. 1 root root 2853 Oct 31 2018 bashrc
drwxr-xr-x. 2 root root 6 Oct 31 2018 binfmt.d/
-rw-r--r--. 1 root root 38 Nov 23 2018 centos-release
-rw-r--r--. 1 root root 51 Nov 23 2018 centos-release-upstream
drwxr-xr-x. 2 root root 6 Aug 4 2017 chkconfig.d/
1.2.2 cd****
cd/cd ~:切换到家目录
[root@server02 ~]# cd /opt
[root@server02 opt]# ls
121.cap download.cap lost+found starts tomcat_gz tomcat_nw
30.cap hdtest.txt ntfs-3g_ntfsprogs-2011.4.12 testdisk tomcat_hn tomcat.tar.gz
apache-jmeter-2.13 hs platform-tools-latest-linux testdisk.c tomcat_hrjq tomcat_th
apache-jmeter-2.13.zip ifcfg-em1.bak res test.sh tomcat_ht tomcat_vod
catalina.out ifcfg-em2.bak restart_app.sh tomcat tomcat_jd tomcat_whjj
cfg kkstatr.sh rh tomcat_93792 tomcat_jinding viewstatus.sh
download01.cap lo_config.sh shutdown_app.sh tomcat.bak tomcat_jy work
download02.cap log smart tomcat_gpzx tomcat_kk
download03.cap log0001.out start_app.sh tomcat_gx tomcat_license
[root@server02 opt]# cd tomcat
[root@server02 tomcat]# ls
bin conf lib log NOTICE RUNNING.txt temp work
cfg hs_err_pid32351.log LICENSE logs RELEASE-NOTES shared webapps
cd ..:切换到上级目录
[root@server02 ~]#(1) cd /opt
[root@server02 opt]# ls
121.cap download.cap lost+found starts tomcat_gz tomcat_nw
30.cap hdtest.txt ntfs-3g_ntfsprogs-2011.4.12 testdisk tomcat_hn tomcat.tar.gz
apache-jmeter-2.13 hs platform-tools-latest-linux testdisk.c tomcat_hrjq tomcat_th
apache-jmeter-2.13.zip ifcfg-em1.bak res test.sh tomcat_ht tomcat_vod
catalina.out ifcfg-em2.bak restart_app.sh tomcat tomcat_jd tomcat_whjj
cfg kkstatr.sh rh tomcat_93792 tomcat_jinding viewstatus.sh
download01.cap lo_config.sh shutdown_app.sh tomcat.bak tomcat_jy work
download02.cap log smart tomcat_gpzx tomcat_kk
download03.cap log0001.out start_app.sh tomcat_gx tomcat_license
[root@server02 opt]# (2)cd tomcat
[root@server02 tomcat]# ls
bin conf lib log NOTICE RUNNING.txt temp work
cfg hs_err_pid32351.log LICENSE logs RELEASE-NOTES shared webapps
[root@server02 tomcat]# (3)cd ..
[root@server02 opt]# ls
121.cap download.cap lost+found starts tomcat_gz tomcat_nw
30.cap hdtest.txt ntfs-3g_ntfsprogs-2011.4.12 testdisk tomcat_hn tomcat.tar.gz
apache-jmeter-2.13 hs platform-tools-latest-linux testdisk.c tomcat_hrjq tomcat_th
apache-jmeter-2.13.zip ifcfg-em1.bak res test.sh tomcat_ht tomcat_vod
catalina.out ifcfg-em2.bak restart_app.sh tomcat tomcat_jd tomcat_whjj
cfg kkstatr.sh rh tomcat_93792 tomcat_jinding viewstatus.sh
download01.cap lo_config.sh shutdown_app.sh tomcat.bak tomcat_jy work
download02.cap log smart tomcat_gpzx tomcat_kk
download03.cap log0001.out start_app.sh tomcat_gx tomcat_license
[root@server02 opt]#
cd - 切换到上一次所在的目录
[root@server02 tomcat]# (1)cd /opt/tomcat
[root@server02 tomcat]# ls
bin conf lib log NOTICE RUNNING.txt temp work
cfg hs_err_pid32351.log LICENSE logs RELEASE-NOTES shared webapps
[root@server02 tomcat]# (2)cd lib/
[root@server02 lib]# ls
annotations-api.jar catalina-tribes.jar jasper.jar tomcat-api.jar tomcat-i18n-fr.jar websocket-api.jar
catalina-ant.jar ecj-4.3.1.jar jsp-api.jar tomcat-coyote.jar tomcat-i18n-ja.jar
catalina-ha.jar el-api.jar servlet-api.jar tomcat-dbcp.jar tomcat-jdbc.jar
catalina.jar jasper-el.jar tomcat7-websocket.jar tomcat-i18n-es.jar tomcat-util.jar
[root@server02 lib]# cd /res/
[root@server02 res]# ls
93792 gpzx hrjq jd jy kk nw nw_mdml readme testso upload whjj
backup gz ht jg jynew lost+found nw.bak nws smart th vod
[root@server02 res]# (3)cd -
/opt/tomcat/lib
1.2.3 cp****
cp:拷贝命令 cp 源目标 目的目标
[root@server02 ll]# mkdir bb
[root@server02 ll]# mkdir aa
mkdir: 无法创建目录"aa": 文件已存在
[root@server02 ll]# mkdir aa
mkdir: 无法创建目录"aa": 文件已存在
[root@server02 ll]# ls
aa bb
[root@server02 ll]# cp aa bb/
cp: 略过目录"aa"
[root@server02 ll]# touch txt.txt
[root@server02 ll]# cp txt.txt bb/
[root@server02 ll]# cd bb
[root@server02 bb]# ls
txt.txt
[root@server02 bb]#
cp -r:递归处理
[root@server02 ll]# mkdir bb
[root@server02 ll]# mkdir aa
mkdir: 无法创建目录"aa": 文件已存在
[root@server02 ll]# mkdir aa
mkdir: 无法创建目录"aa": 文件已存在
[root@server02 ll]# ls
aa bb
[root@server02 ll]# cp aa bb/
cp: 略过目录"aa"
[root@server02 ll]# touch txt.txt
[root@server02 ll]# cp txt.txt bb/
[root@server02 ll]# cd bb
[root@server02 bb]# ls
txt.txt
[root@server02 bb]#
cp -rf:强制覆盖(\cp -r)|(/usr/bin/cp )
[root@server02 ll]# ls
'1.ttx 2.txt aa bb txt.txt
[root@server02 ll]# 'cd bb
> ls
> ^C
[root@server02 ll]# ls
1.ttx 2.txt aa bb txt.txt
[root@server02 ll]# cp -rf txt.txt ../
[root@server02 ll]#
1.2.5 mkdir****
mkdir:创建目录,但是只能创建一级目录
[root@server02 cdn]#
[root@server02 cdn]# cd /opt/ll/
[root@server02 ll]# ls
1.ttx 2.txt aa bb ll.TXT txt.txt
[root@server02 ll]# mkdir xx
[root@server02 ll]#(1) ls
1.ttx 2.txt aa bb ll.TXT txt.txt xx
[root@server02 ll]# mkdir xx/aa/bb
mkdir: 无法创建目录"xx/aa/bb": 没有那个文件或目录
mkdir -p:创建多级目录和创建存在目录的时候会忽略错误信息
[root@server02 ll]# mkdir -p xx/AA/BB
[root@server02 ll]# ls
1.ttx 2.txt aa bb ll.TXT txt.txt xx
[root@server02 ll]# cd xx
[root@server02 xx]# ls
AA
[root@server02 xx]# cd AA
[root@server02 AA]# ls
BB
[root@server02 AA]# cd BB
[root@server02 BB]# ls
[root@server02 BB]#
mkdir -m:创建目录的时候可以修改目录权限
[root@oldboy6666 ~] # mkdir aa
[root@oldboy6666 ~] # ll -d aa
drwxr-xr-x 2 root root 6 Sep 18 16:33 aa
[root@oldboy6666 ~] # mkdir bb -m 777
[root@oldboy6666 ~] # ll -d bb
drwxrwxrwx 2 root root 6 Sep 18 16:34 bb
[root@oldboy6666 ~] #
mkdir -v:创建目录的时候会显示详细信息
[root@oldboy6666 ~] # mkdir cc -v
mkdir: created directory 'cc'
[root@oldboy6666 ~] #
1.2.6 mv****
mv 源文件目录 目标文件目录
[root@server02 xx]# cd AA
[root@server02 AA]# ls
BB
[root@server02 AA]# cd BB
[root@server02 BB]# ls
[root@server02 BB]# cd ..
[root@server02 AA]# ls
BB
[root@server02 AA]# mv BB ../../
[root@server02 AA]# ls
[root@server02 AA]# cd ../..
[root@server02 ll]# ls
ttx 2.txt aa bb BB ll.TXT txt.txt xx
mv 源文件 重命名后的文件
[root@server02 ll]# ls
1.ttx 2.txt aa bb BB ll.TXT txt.txt xx
[root@server02 ll]# mv BB BBB
[root@server02 ll]# ls
1.ttx 2.txt aa bb BBB ll.TXT txt.txt xx
[root@server02 ll]#
1.2.7 pwd****
pwd:查看文件所在的当前目录
[root@server02 ll]# pwd
/opt/ll
1.2.8 rename*******
rename 修改的名字 要修改成什么名字 修改的文件有哪些
[root@oldboyedu oldboy02] # rename txt log *.txt rename txt log *.txt
You have new mail in /var/spool/mail/root
[root@oldboyedu oldboy02] # ls
001 008.log 015.log 022.log 029.log 036.log 043.log 050.log 057.log 064.log 071.log 078.log 085.log 092.log 099.log
002.log 009.log 016.log 023.log 030.log 037.log 044.log 051.log 058.log 065.log 072.log 079.log 086.log 093.log 100.log
003.log 010.log 017.log 024.log 031.log 038.log 045.log 052.log 059.log 066.log 073.log 080.log 087.log 094.log
004.log 011.log 018.log 025.log 032.log 039.log 046.log 053.log 060.log 067.log 074.log 081.log 088.log 095.log
005.log 012.log 019.log 026.log 033.log 040.log 047.log 054.log 061.log 068.log 075.log 082.log 089.log 096.log
006.log 013.log 020.log 027.log 034.log 041.log 048.log 055.log 062.log 069.log 076.log 083.log 090.log 097.log
007.log 014.log 021.log 028.log 035.log 042.log 049.log 056.log 063.log 070.log 077.log 084.log 091.log 098.log
[root@oldboyedu oldboy02] #
1.2.8.1 mv和rename的区别
[root@oldboyedu oldboy02] #
[root@oldboyedu oldboy02] # ls
001 008.txt 015.txt 022.txt 029.txt 036.txt 043.txt 050.txt 057.txt 064.txt 071.txt 078.txt 085.txt 092.txt 099.txt
002.txt 009.txt 016.txt 023.txt 030.txt 037.txt 044.txt 051.txt 058.txt 065.txt 072.txt 079.txt 086.txt 093.txt 100.txt
003.txt 010.txt 017.txt 024.txt 031.txt 038.txt 045.txt 052.txt 059.txt 066.txt 073.txt 080.txt 087.txt 094.txt
004.txt 011.txt 018.txt 025.txt 032.txt 039.txt 046.txt 053.txt 060.txt 067.txt 074.txt 081.txt 088.txt 095.txt
005.txt 012.txt 019.txt 026.txt 033.txt 040.txt 047.txt 054.txt 061.txt 068.txt 075.txt 082.txt 089.txt 096.txt
006.txt 013.txt 020.txt 027.txt 034.txt 041.txt 048.txt 055.txt 062.txt 069.txt 076.txt 083.txt 090.txt 097.txt
007.txt 014.txt 021.txt 028.txt 035.txt 042.txt 049.txt 056.txt 063.txt 070.txt 077.txt 084.txt 091.txt 098.txt
[root@oldboyedu oldboy02] # mv *.txt *.log 通过修改发现mv只能单个修改
mv: target '*.log' is not a directory
[root@oldboyedu oldboy02] #
[root@oldboyedu oldboy02] #
[root@oldboyedu oldboy02] # rename txt log *.txt 使用rename修改将txt的名字修改成log名字,并且是全部后缀为*.txt的文件
You have new mail in /var/spool/mail/root
[root@oldboyedu oldboy02] # ls
001 008.log 015.log 022.log 029.log 036.log 043.log 050.log 057.log 064.log 071.log 078.log 085.log 092.log 099.log
002.log 009.log 016.log 023.log 030.log 037.log 044.log 051.log 058.log 065.log 072.log 079.log 086.log 093.log 100.log
003.log 010.log 017.log 024.log 031.log 038.log 045.log 052.log 059.log 066.log 073.log 080.log 087.log 094.log
004.log 011.log 018.log 025.log 032.log 039.log 046.log 053.log 060.log 067.log 074.log 081.log 088.log 095.log
005.log 012.log 019.log 026.log 033.log 040.log 047.log 054.log 061.log 068.log 075.log 082.log 089.log 096.log
006.log 013.log 020.log 027.log 034.log 041.log 048.log 055.log 062.log 069.log 076.log 083.log 090.log 097.log
007.log 014.log 021.log 028.log 035.log 042.log 049.log 056.log 063.log 070.log 077.log 084.log 091.log 098.log
[root@oldboyedu oldboy02] #
1.2.9 rm****
rm:删除文件,但是会有交互过程
[root@server02 ll]# rm 1.ttx
rm:是否删除普通空文件 "1.ttx"?y
[root@server02 ll]# ls
2.xls aa bb BBB bb.xls cc.xls dd.xls ll.TXT xls.txt xx
[root@server02 ll]#
rm -r:删除文件和目录,有交互过程
[root@server02 ll]# rm -r aa 2.xls
rm:是否删除目录 "aa"?y
rm:是否删除普通空文件 "2.xls"?y
[root@server02 ll]#
rm -rf:强制删除文件和目录,没有交互过程(一般不建议使用)
[root@server02 ll]# rm -rf cc.xls bb
[root@server02 ll]#
1.2.10 rmdir****
rmdir:删除空目录
[root@server02 ll]# rmdir BBB
[root@server02 ll]# rmdir xx
rmdir: 删除 "xx" 失败: 目录非空
[root@server02 ll]#
1.2.11 touch***
touch:创建文件/修改文件的时间戳
[root@server02 ll]# touch cc.txt
[root@server02 ll]# ll
总用量 12
drwxr-xr-x 2 root root 4096 2月 27 16:16 bb.xls
-rw-r--r-- 1 root root 0 2月 27 17:09 cc.txt
drwxr-xr-x 2 root root 4096 2月 27 16:16 dd.xls
-rw-r--r-- 1 root root 0 2月 23 11:39 ll.TXT
-rw-r--r-- 1 root root 0 2月 23 11:08 xls.txt
drwxr-xr-x 3 root root 4096 2月 27 15:57 xx
[root@server02 ll]#
1.2.12 tree****
tree:显示目录结构
[root@server02 ll]# tree /opt/ll
/opt/ll
├── bb.xls
├── cc.txt
├── dd.xls
├── ll.TXT
├── xls.txt
└── xx
└── AA
4 directories, 3 files
[root@server02 ll]#
tree -L num:只显示num行目录
[root@server02 ll]# tree -L 1 /opt/ll
/opt/ll
├── bb.xls
├── dd.xls
└── xx
3 directories
1.2.13 basename
basename:即basename的作用是从文件名中去除目录和后缀
[root@server02 ll]# ls
bb.xls cc.txt dd.xls ll.TXT xls.txt xx
[root@server02 ll]# touch aa.txt
[root@server02 ll]# touch aa.txt .
[root@server02 ll]# touch aa.txt txt
[root@server02 ll]# touch aa.txt .txt
[root@server02 ll]# ls
aa.txt bb.xls cc.txt dd.xls ll.TXT txt xls.txt xx
[root@server02 ll]# basename /opt/ll/aa
aa
[root@server02 ll]# basename /opt/ll/aa.txt
aa.txt
[root@server02 ll]# basename /opt/ll/aa.txt .
aa.txt
[root@server02 ll]# basename /opt/ll/aa.txt txt
aa.
[root@server02 ll]# basename /opt/ll/aa.txt .txt
aaq
[root@server02 ll]#
1.2.14 dirname
dirname:令读取指定路径名删除最后一个/及其后面的字符,保留其他部分
[root@server02 ~]# dirname cd /opt
dirname: 额外的操作数 "/opt"
请尝试执行"dirname --help"来获取更多信息。
[root@server02 ~]# dirname cd/opt
cd
[root@server02 ~]# dirname cd
.
[root@server02 ~]#
[root@server02 ~]#
[root@server02 ~]# dirname
dirname: 缺少操作数
请尝试执行"dirname --help"来获取更多信息。
[root@server02 ~]# dirname cd
.
[root@server02 ~]# dirname /cd
/
1.2.15 chattr********
chattr +(-)i:设定文件不能被删除、改名、设定链接关系,同时不能写入或新增内容。
[root@server02 ll]# chattr +i
aa.txt aa.txt~ bb.xls/ cc.txt dd.xls/ ll.TXT txt .txt xls.txt xx/
[root@server02 ll]# chattr +i cc.txt
[root@server02 ll]# rm -rf cc.txt
rm: 无法删除"cc.txt": 不允许的操作
[root@server02 ll]# ln cc.txt /cc.txt
ln: 创建硬链接"/cc.txt" => "cc.txt": 无效的跨设备连接
[root@server02 ll]# ln cc.txt ff.txt
ln: 创建硬链接"ff.txt" => "cc.txt": 不允许的操作
[root@server02 ll]#
chattr +(-):a即append,设定该参数后,只能向文件中添加数据,而不能删除
[root@server02 ll]# chattr +a dd.xls
[root@server02 ll]# ls
aa.txt aa.txt~ bb.xls cc.txt dd.xls ll.TXT txt xls.txt xx
[root@server02 ll]# rm -rf dd.xls
rm: 无法删除"dd.xls": 不允许的操作
[root@server02 ll]# chattr +a ll.TXT
[root@server02 ll]# ls
aa.txt aa.txt~ bb.xls cc.txt dd.xls ll.TXT txt xls.txt xx
[root@server02 ll]# rm -rf ll.TXT
rm: 无法删除"ll.TXT": 不允许的操作
[root@server02 ll]# vim ll.TXT
~
"ll.TXT" 0L, 0C 0,0-1 全部
qqqqqqqqq
"ll.TXT"
"ll.TXT" E212: 无法打开并写入文件
"ll.TXT"
"ll.TXT" E212: 无法打开并写入文件
请按 ENTER 或其它命令继续
1.2.16 lsattr******
lsattr:查看文件是否加锁了
[root@server02 ll]# aa.txt aa.txt~ bb.xls cc.txt dd.xls ll.TXT txt xls.txt xx
-bash: aa.txt: command not found
[root@server02 ll]# ls
aa.txt aa.txt~ bb.xls cc.txt dd.xls ll.TXT ll.TXT~ ll.TXz~ txt xls.txt xx
[root@server02 ll]# lsattr aa.txt
----ia-------e- aa.txt
1.2.17 file****
file:file命令用来识别文件类型,也可用来辨别一些文件的编码格式。它是通过查看文件的头部信息来获取文件类型
file -b:不显示文件名称
[root@nfs ~]# file linuxtest.txt
linuxtest.txt: Bourne-Again shell script text executable
[root@nfs ~]# file -b linuxtest.txt
Bourne-Again shell script text executable
[root@nfs ~]#
file -c:详细显示指令执行过程
[root@nfs ~]# file -c linuxtest.txt
cont offset type opcode mask value desc
[root@nfs ~]#
file -L:查看软连接
[root@nfs etc]# touch aa.txt
[root@nfs etc]# ln -s aa.txt /etc/sysconfig/network-scripts/bb.txt
[root@nfs etc]# cd /etc/sysconfig/network-scripts/bb.txt
-bash: cd: /etc/sysconfig/network-scripts/bb.txt: 没有那个文件或目录
[root@nfs etc]# cd /etc/sysconfig/network-scripts/
[root@nfs network-scripts]# ll bb.txt
lrwxrwxrwx. 1 root root 6 4月 12 21:45 bb.txt -> aa.txt
[root@nfs network-scripts]# file -L bb.txt
bb.txt: cannot open `bb.txt' (No such file or directory)
[root@nfs network-scripts]#
file -f:查看文件中的文件类型
[root@nfs ~]# file -f linuxtest.txt
#!/bin/bash: cannot open `#!/bin/bash' (No such file or directory)
echo "aa": cannot open `echo "aa"' (No such file or directory)
file -z:查看压缩包里面的文件类型
[root@nfs network-scripts]# tar -Pzcvf bb.tar.gz bb.txt
bb.txt
[root@nfs network-scripts]# ls
bb.tar.gz ifcfg-eth1 ifdown-bnep ifdown-ipv6 ifdown-ppp ifdown-tunnel ifup-bnep ifup-ipv6 ifup-plusb ifup-routes ifup-wireless network-functions
bb.txt ifcfg-lo ifdown-eth ifdown-isdn ifdown-routes ifup ifup-eth ifup-isdn ifup-post ifup-sit init.ipv6-global network-functions-ipv6
ifcfg-eth0 ifdown ifdown-ippp ifdown-post ifdown-sit ifup-aliases ifup-ippp ifup-plip ifup-ppp ifup-tunnel net.hotplug
[root@nfs network-scripts]# file -z bb.tar.gz
bb.tar.gz: POSIX tar archive (GNU) (gzip compressed data, from Unix, last modified: Fri Apr 12 21:46:53 2019)
1.2.18 md5sum
md5sum:目标文件传输完成后和源文件进行对比
1.获取包,确保包正确无误
获取包后,验证包的MD5值:md5sum rc*.tar.gz
2. 解压缩到指定目录
确保对应的目录存在
tar -zxvf rc1.tar.gz -C ./test_rc1
tar -zxvf rc2.tar.gz -C ./test_rc2
3. 递归生成各文件的的MD5值
find ./test_rc1 -type f -print0| xargs -0 md5sum >> rc1_md5.txt
find ./test_rc2 -type f -print0| xargs -0 md5sum >> rc2_md5.txt
4. 比较两文件的MD5值
diff -c rc1_md5.txt rc2_md5.txt
或者用UltraCompare Professional比对结果
1.3 查看文件及内容处理命令
1.3.1 cat***
cat -n:查看文件并且给每行编号
[root@nfs2 ~]# cat -n /etc/liangyuxing.txt
1 root:x:0:0:root:/root:/bin/bash
2 bin:x:1:1:bin:/bin:/sbin/nologin
3 daemon:x:2:2:daemon:/sbin:/sbin/nologin
4 adm:x:3:4:adm:/var/adm:/sbin/nologin
5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
6 sync:x:5:0:sync:/sbin:/bin/sync
7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
8 halt:x:7:0:halt:/sbin:/sbin/halt
9 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10 uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
11 operator:x:11:0:operator:/root:/sbin/nologin
12
13
14 games:x:12:100:games:/usr/games:/sbin/nologin
15 gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
16 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
17 nobody:x:99:99:Nobody:/:/sbin/nologin
18 vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
19
20
21 saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
22 postfix:x:89:89::/var/spool/postfix:/sbin/nologin
23 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
24 rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
25 rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
26 nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
cat -b:查看文件并且给每行编号,如果是空行,不给编号
[root@nfs2 ~]# cat -b /etc/liangyuxing.txt
1 root:x:0:0:root:/root:/bin/bash
2 bin:x:1:1:bin:/bin:/sbin/nologin
3 daemon:x:2:2:daemon:/sbin:/sbin/nologin
4 adm:x:3:4:adm:/var/adm:/sbin/nologin
5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
6 sync:x:5:0:sync:/sbin:/bin/sync
7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
8 halt:x:7:0:halt:/sbin:/sbin/halt
9 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10 uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
11 operator:x:11:0:operator:/root:/sbin/nologin
12 games:x:12:100:games:/usr/games:/sbin/nologin
13 gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
14 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
15 nobody:x:99:99:Nobody:/:/sbin/nologin
16 vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
17 saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
18 postfix:x:89:89::/var/spool/postfix:/sbin/nologin
19 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
20 rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
21 rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
22 nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
cat -A:显示所有(会将文件内容默认的$符号显示出来)
[root@oldboy6666 oldboy] # cat -A oldboy.txt
oldboy$
oldgirl$
oldbaby$
olddog$
[root@oldboy6666 oldboy] #
1.3.2 tac*******
tac和cat功能一样,只是tac是从后往前
[root@nfs2 ~]# tac /etc/liangyuxing.txt
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
halt:x:7:0:halt:/sbin:/sbin/halt
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sync:x:5:0:sync:/sbin:/bin/sync
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
root:x:0:0:root:/root:/bin/bash
1.3.3 more****
more:查看文档
- 回车键 换行
- ctrl +F(空格键) 向下滚页
- ctrl +B 向上滚页
-
q 退出
[root@nfs2 ~]# more /etc/init.d/nfs
#!/bin/sh
#
# nfs This shell script takes care of starting and stopping
# the NFS services.
#
# chkconfig: - 30 60
# description: NFS is a popular protocol for file sharing across networks.
# This service provides NFS server functionality, which is \
# configured via the /etc/exports file.
# probe: true
# config: /etc/sysconfig/nfs
### BEGIN INIT INFO
# Provides: nfs
# Required-Start: $local_fs $network $syslog $rpcbind
# Required-Stop: $local_fs $network $syslog $rpcbind
# Default-Stop: 0 1 6
# Short-Description: Start up the NFS server sevice
# Description: NFS is a popular protocol for file sharing across networks \
# This service provides NFS server functionality, \
# which is configured via the /etc/exports file.
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network
# Check for and source configuration file otherwise set defaults
[ -f /etc/sysconfig/nfs ] && . /etc/sysconfig/nfs
# Remote quota server
[ -z "$RQUOTAD" ] && RQUOTAD=`type -path rpc.rquotad`
RETVAL=0
uid=`id | cut -d\( -f1 | cut -d= -f2`
# See how we were called.
case "$1" in
start)
# Check that networking is up.
[ "${NETWORKING}" != "yes" ] && exit 6
--More--(19%)
扩展:空格键:切换页
回车键:换行
q:退出more
b:向上翻页
1.3.4 less****
less:查看文档
- 回车键 换行
- ctrl +F(空格键) 向下滚页
- ctrl +B 向上滚页
- q 退出
- 方向上键 向上切换一行
- 方向下键 向下切换一行
- /文件内容 向下搜索内容
-
?文件内容 向上搜索内容
#!/bin/sh
#
# nfs This shell script takes care of starting and stopping
# the NFS services.
#
# chkconfig: - 30 60
# description: NFS is a popular protocol for file sharing across networks.
# This service provides NFS server functionality, which is \
# configured via the /etc/exports file.
# probe: true
# config: /etc/sysconfig/nfs
### BEGIN INIT INFO
# Provides: nfs
# Required-Start: $local_fs $network $syslog $rpcbind
# Required-Stop: $local_fs $network $syslog $rpcbind
# Default-Stop: 0 1 6
# Short-Description: Start up the NFS server sevice
# Description: NFS is a popular protocol for file sharing across networks \
# This service provides NFS server functionality, \
# which is configured via the /etc/exports file.
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network
# Check for and source configuration file otherwise set defaults
[ -f /etc/sysconfig/nfs ] && . /etc/sysconfig/nfs
# Remote quota server
[ -z "$RQUOTAD" ] && RQUOTAD=`type -path rpc.rquotad`
RETVAL=0
uid=`id | cut -d\( -f1 | cut -d= -f2`
# See how we were called.
case "$1" in
start)
# Check that networking is up.
[ "${NETWORKING}" != "yes" ] && exit 6
:
扩展:空格键(pagedown):向下切换页
回车键:换行
q:退出
ctrl +b(pageup):向上翻页
- 1.3.5 head***
head -n 10:为查看文件的前10行(不加-n,默认也是10行)
[root@nfs2 ~]# head -n 10 /etc/init.d/nfs
#!/bin/sh
#
# nfs This shell script takes care of starting and stopping
# the NFS services.
#
# chkconfig: - 30 60
# description: NFS is a popular protocol for file sharing across networks.
# This service provides NFS server functionality, which is \
# configured via the /etc/exports file.
# probe: true
[root@nfs2 ~]#
head -c 10:为查看文件的前10个字符
[root@nfs2 ~]# head -c 10 /etc/init.d/nfs
#!/bin/sh
[root@nfs2 ~]#
1.3.6 tail****
tail:命令输出文件的最后10行
[root@nfs2 ~]# head -c 10 /etc/init.d/nfs
#!/bin/sh
[root@nfs2 ~]# tail /etc/init.d/nfs
RETVAL=$?
}
;;
*)
echo $"Usage: nfs {start|stop|status|restart|reload|force-reload|condrestart|try-restart|condstop}"
RETVAL=2
;;
esac
exit $RETVAL
tail -c 100:显示文件的最后100个字符
[root@nfs2 ~]# tail -c 100 /etc/init.d/nfs
tus|restart|reload|force-reload|condrestart|try-restart|condstop}"
RETVAL=2
;;
esac
exit $RETVAL
[root@nfs2 ~]#
tail -20f:追踪日志文件的最后20行,如果一旦追踪的文件被删除,就算还原也不会继续追踪
添加的记录
[root@oldboy6666 ~]#
[root@oldboy6666 ~]# echo "123456" >> 1.txt
[root@oldboy6666 ~]# echo "123456" >> 1.txt
[root@oldboy6666 ~]# rm -rf 1.txt
[root@oldboy6666 ~]# echo "123456" >> 1.txt
[root@oldboy6666 ~]#
追踪的日志记录
[root@oldboy6666 ~]# tail -20f 1.txt
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
#alias cman='man -M /usr//share/man/zh_CN'
123456
123456
tail -f -n 20:显示文件的最后20行
[root@nfs2 ~]# tail -f -n 20 /etc/init.d/nfs | cat -n
1 [ -f /var/lock/subsys/nfs ] && {
2 $0 stop
3 $0 start
4 RETVAL=$?
5 }
6 ;;
7 condstop)
8 [ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd condstop
9 [ -f /var/lock/subsys/nfs ] && {
10 $0 stop
11 RETVAL=$?
12 }
13 ;;
14 *)
15 echo $"Usage: nfs {start|stop|status|restart|reload|force-reload|condrestart|try-restart|condstop}"
16 RETVAL=2
17 ;;
18 esac
19
20 exit $RETVAL
tail -20F 查看日志文件的最后20行,并且如果文件删除以后,会暂停追踪,一旦文件恢复,会继续追踪
测试数据
[root@oldboy6666 ~]# echo "123456" >> 1.txt
[root@oldboy6666 ~]# echo "123456" >> 1.txt
[root@oldboy6666 ~]# echo "123456" >> 1.txt
[root@oldboy6666 ~]# echo "123456" >> 1.txt
[root@oldboy6666 ~]# rm -rf 1.txt
[root@oldboy6666 ~]# echo "123456" >> 1.txt
[root@oldboy6666 ~]# echo "123456" >> 1.txt
[root@oldboy6666 ~]# echo "123456" >> 1.txt
[root@oldboy6666 ~]#
日志追踪
[root@oldboy6666 ~]# tail -F 20 1.txt
tail: cannot open '20' for reading: No such file or directory
==> 1.txt <==
1
0
1
1
0
1
1
0
1
1
123456
123456
123456
123456
tail: '1.txt' has become inaccessible: No such file or directory
tail: '1.txt' has appeared; following end of new file
==> 1.txt <==
123456
==> 1.txt <==
123456
123456
1.3.7 cut
cut -f 1-4 -d":"以:分割选择选中的4列(-f 后面接选中的列;-d 后面接分隔符)
[root@nfs2 ~]# cut -f 1-4 -d":" /etc/liangyuxing.txt
root:x:0:0
bin:x:1:1
daemon:x:2:2
adm:x:3:4
lp:x:4:7
sync:x:5:0
shutdown:x:6:0
halt:x:7:0
mail:x:8:12
uucp:x:10:14
operator:x:11:0
games:x:12:100
gopher:x:13:30
ftp:x:14:50
nobody:x:99:99
vcsa:x:69:69
saslauth:x:499:76
postfix:x:89:89
sshd:x:74:74
rpc:x:32:32
rpcuser:x:29:29
nfsnobody:x:65534:65534
cut -c n-m:打印第n到m之间的字符
[root@oldboyedu oldboy02] # echo $RANDOM 生成随机数
27077
[root@oldboyedu oldboy02] # echo $RANDOM | md5sum 使用md5sum来进行匹配
d8bb2da155ce92a832351329439d5a82 -
[root@oldboyedu oldboy02] # echo $RANDOM | md5sum | cut -c 1-6 取出第1到6之间的字符
ebc93b
[root@oldboyedu oldboy02] #
1.3.8 split
split -b 10k +文件:以每字节10K的大小来分割文件
[root@nfs2 data]# dd if=/dev/zero bs=100k count=1 of=file.data
记录了1+0 的读入
记录了1+0 的写出
102400字节(102 kB)已复制,0.000426812 秒,240 MB/秒
[root@nfs2 data]# ls
file.data
[root@nfs2 data]# split -b 10K file.data
[root@nfs2 data]# ls
file.data xaa xab xac xad xae xaf xag xah xai xaj
[root@nfs2 data]#
split -b 10k +文件 -d 2a:以每字节10K的大小来分割文件并且分割的文件首字符为2a开头
- -b:指定切割字符的大小
-
-d:指定切割字符前面以什么开头
[root@nfs2 data]# split -b 10K file.data -d 2a
[root@nfs2 data]# ls
2a00 2a01 2a02 2a03 2a04 2a05 2a06 2a07 2a08 2a09 file.data
[root@nfs2 data]#
1.3.9 paste
-
-d:指定合并文件之间用什么进行分割
[root@oldboyedu oldboy02] # echo oldboy > oldboy.txt
[root@oldboyedu oldboy02] # echo oldboy01 > oldboy01.txt
[root@oldboyedu oldboy02] # echo oldboy02 > oldboy02.txt
[root@oldboyedu oldboy02] # paste oldboy.txt oldboy01.txt oldboy02.txt 合并这3个文件
oldboy oldboy01 oldboy02
[root@oldboyedu oldboy02] # paste -d "\n" oldboy.txt oldboy01.txt oldboy02.txt 合并这3个文件内容并且使用-d参数指定中间使用什么进行分割
oldboy
oldboy01
oldboy02
You have new mail in /var/spool/mail/root
[root@oldboyedu oldboy02] #
1.3.10 sort
sort:排序命令(默认以第一列排序)
[root@nfs2 data]# sort /etc/liangyuxing.txt
adm:x:3:4:adm:/var/adm:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
halt:x:7:0:halt:/sbin:/sbin/halt
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
root:x:0:0:root:/root:/bin/bash
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
[root@nfs2 data]#
sort -u:去除重复(相当于uniq -c)
[root@nfs2 data]# sort -u /etc/liangyuxing.txt
adm:x:3:4:adm:/var/adm:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
halt:x:7:0:halt:/sbin:/sbin/halt
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
root:x:0:0:root:/root:/bin/bash
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
[root@nfs2 data]#
sort -nk 2 -t: +文件:以:为分隔符,第2列进行从小到大排序
- -t:后面加分隔符
- -k:以第几列为分隔符
- -n:从小到大开始排序(先大写字母,在小写字母,在数字,在特殊字符)
-
-r:反向排序
[root@oldboyedu oldboy02] # sort -nk 2 -t: passwd_lyx.txt
AAA:BBB
adm:x:3:4:adm:/var/adm:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
halt:x:7:0:halt:/sbin:/sbin/halt
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
root:x:0:0:root:/root:/bin/bash
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sync:x:5:0:sync:/sbin:/bin/sync
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
123:111
^$:9999
[root@oldboyedu oldboy02] #
1.3.11 uniq****
uniq -c:统计有多少个重复的行(结合sort使用)
[root@model test]# sort uniq.txt | uniq -c
4 11111
1 22222
1 33333
1 4444
1 44444
1 444444
1 44444455555
1 6666666
[root@model test]#
uniq -d:查找出带有重复的行(结合sort使用)
[root@model test]# cat uniq.txt
11111
22222
11111
11111
33333
444444
11111
4444
44444
44444455555
6666666
[root@model test]# sort uniq.txt | uniq -d
11111
[root@model test]#
uniq -u:查找出单一的行
[root@model test]# sort uniq.txt | uniq -u
22222
33333
4444
44444
444444
44444455555
6666666
[root@model test]#
1.3.12 wc****
wc名字用来计算数字,通常前面会将结果查出来后面进行计算
wc -l:用于查看有多少行
[root@model test]# sort uniq.txt | wc -l
11
[root@model test]#
wc -c:用于查看有多少字节
[root@model test]# sort uniq.txt | wc -c
74
[root@model test]#
wc -w:用于查看多少个字
[root@model test]# sort uniq.txt | wc -w
11
[root@model test]#
1.3.13 iconv
iconv -l:列出当前支持的字符编码
[root@model test]# iconv -l
The following list contain all the coded character sets known. This does
not necessarily mean that all combinations of these names can be used for
the FROM and TO command line parameters. One coded character set can be
listed with several different names (aliases).
437, 500, 500V1, 850, 851, 852, 855, 856, 857, 860, 861, 862, 863, 864, 865,
866, 866NAV, 869, 874, 904, 1026, 1046, 1047, 8859_1, 8859_2, 8859_3, 8859_4,
8859_5, 8859_6, 8859_7, 8859_8, 8859_9, 10646-1:1993, 10646-1:1993/UCS4,
ANSI_X3.4-1968, ANSI_X3.4-1986, ANSI_X3.4, ANSI_X3.110-1983, ANSI_X3.110,
ARABIC, ARABIC7, ARMSCII-8, ASCII, ASMO-708, ASMO_449, BALTIC, BIG-5,
BIG-FIVE, BIG5-HKSCS, BIG5, BIG5HKSCS, BIGFIVE, BRF, BS_4730, CA, CN-BIG5,
CN-GB, CN, CP-AR, CP-GR, CP-HU, CP037, CP038, CP273, CP274, CP275, CP278,
CP280, CP281, CP282, CP284, CP285, CP290, CP297, CP367, CP420, CP423, CP424,
CP437, CP500, CP737, CP775, CP803, CP813, CP819, CP850, CP851, CP852, CP855,
CP856, CP857, CP860, CP861, CP862, CP863, CP864, CP865, CP866, CP866NAV,
CP868, CP869, CP870, CP871, CP874, CP875, CP880, CP891, CP901, CP902, CP903,
CP904, CP905, CP912, CP915, CP916, CP918, CP920, CP921, CP922, CP930, CP932,
CP933, CP935, CP936, CP937, CP939, CP949, CP950, CP1004, CP1008, CP1025,
CP1026, CP1046, CP1047, CP1070, CP1079, CP1081, CP1084, CP1089, CP1097,
CP1112, CP1122, CP1123, CP1124, CP1125, CP1129, CP1130, CP1132, CP1133,
CP1137, CP1140, CP1141, CP1142, CP1143, CP1144, CP1145, CP1146, CP1147,
CP1148, CP1149, CP1153, CP1154, CP1155, CP1156, CP1157, CP1158, CP1160,
CP1161, CP1162, CP1163, CP1164, CP1166, CP1167, CP1250, CP1251, CP1252,
CP1253, CP1254, CP1255, CP1256, CP1257, CP1258, CP1282, CP1361, CP1364,
CP1371, CP1388, CP1390, CP1399, CP4517, CP4899, CP4909, CP4971, CP5347,
CP9030, CP9066, CP9448, CP10007, CP12712, CP16804, CPIBM861, CSA7-1, CSA7-2,
CSASCII, CSA_T500-1983, CSA_T500, CSA_Z243.4-1985-1, CSA_Z243.4-1985-2,
CSA_Z243.419851, CSA_Z243.419852, CSDECMCS, CSEBCDICATDE, CSEBCDICATDEA,
CSEBCDICCAFR, CSEBCDICDKNO, CSEBCDICDKNOA, CSEBCDICES, CSEBCDICESA,
CSEBCDICESS, CSEBCDICFISE, CSEBCDICFISEA, CSEBCDICFR, CSEBCDICIT, CSEBCDICPT,
CSEBCDICUK, CSEBCDICUS, CSEUCKR, CSEUCPKDFMTJAPANESE, CSGB2312, CSHPROMAN8,
CSIBM037, CSIBM038, CSIBM273, CSIBM274, CSIBM275, CSIBM277, CSIBM278,
CSIBM280, CSIBM281, CSIBM284, CSIBM285, CSIBM290, CSIBM297, CSIBM420,
CSIBM423, CSIBM424, CSIBM500, CSIBM803, CSIBM851, CSIBM855, CSIBM856,
CSIBM857, CSIBM860, CSIBM863, CSIBM864, CSIBM865, CSIBM866, CSIBM868,
CSIBM869, CSIBM870, CSIBM871, CSIBM880, CSIBM891, CSIBM901, CSIBM902,
CSIBM903, CSIBM904, CSIBM905, CSIBM918, CSIBM921, CSIBM922, CSIBM930,
CSIBM932, CSIBM933, CSIBM935, CSIBM937, CSIBM939, CSIBM943, CSIBM1008,
CSIBM1025, CSIBM1026, CSIBM1097, CSIBM1112, CSIBM1122, CSIBM1123, CSIBM1124,
CSIBM1129, CSIBM1130, CSIBM1132, CSIBM1133, CSIBM1137, CSIBM1140, CSIBM1141,
CSIBM1142, CSIBM1143, CSIBM1144, CSIBM1145, CSIBM1146, CSIBM1147, CSIBM1148,
CSIBM1149, CSIBM1153, CSIBM1154, CSIBM1155, CSIBM1156, CSIBM1157, CSIBM1158,
CSIBM1160, CSIBM1161, CSIBM1163, CSIBM1164, CSIBM1166, CSIBM1167, CSIBM1364,
CSIBM1371, CSIBM1388, CSIBM1390, CSIBM1399, CSIBM4517, CSIBM4899, CSIBM4909,
CSIBM4971, CSIBM5347, CSIBM9030, CSIBM9066, CSIBM9448, CSIBM12712,
CSIBM16804, CSIBM11621162, CSISO4UNITEDKINGDOM, CSISO10SWEDISH,
CSISO11SWEDISHFORNAMES, CSISO14JISC6220RO, CSISO15ITALIAN, CSISO16PORTUGESE,
CSISO17SPANISH, CSISO18GREEK7OLD, CSISO19LATINGREEK, CSISO21GERMAN,
CSISO25FRENCH, CSISO27LATINGREEK1, CSISO49INIS, CSISO50INIS8,
CSISO51INISCYRILLIC, CSISO58GB1988, CSISO60DANISHNORWEGIAN,
CSISO60NORWEGIAN1, CSISO61NORWEGIAN2, CSISO69FRENCH, CSISO84PORTUGUESE2,
CSISO85SPANISH2, CSISO86HUNGARIAN, CSISO88GREEK7, CSISO89ASMO449, CSISO90,
CSISO92JISC62991984B, CSISO99NAPLPS, CSISO103T618BIT, CSISO111ECMACYRILLIC,
CSISO121CANADIAN1, CSISO122CANADIAN2, CSISO139CSN369103, CSISO141JUSIB1002,
CSISO143IECP271, CSISO150, CSISO150GREEKCCITT, CSISO151CUBA,
CSISO153GOST1976874, CSISO646DANISH, CSISO2022CN, CSISO2022JP, CSISO2022JP2,
CSISO2022KR, CSISO2033, CSISO5427CYRILLIC, CSISO5427CYRILLIC1981,
CSISO5428GREEK, CSISO10367BOX, CSISOLATIN1, CSISOLATIN2, CSISOLATIN3,
CSISOLATIN4, CSISOLATIN5, CSISOLATIN6, CSISOLATINARABIC, CSISOLATINCYRILLIC,
CSISOLATINGREEK, CSISOLATINHEBREW, CSKOI8R, CSKSC5636, CSMACINTOSH,
CSNATSDANO, CSNATSSEFI, CSN_369103, CSPC8CODEPAGE437, CSPC775BALTIC,
CSPC850MULTILINGUAL, CSPC862LATINHEBREW, CSPCP852, CSSHIFTJIS, CSUCS4,
CSUNICODE, CSWINDOWS31J, CUBA, CWI-2, CWI, CYRILLIC, DE, DEC-MCS, DEC,
DECMCS, DIN_66003, DK, DS2089, DS_2089, E13B, EBCDIC-AT-DE-A, EBCDIC-AT-DE,
EBCDIC-BE, EBCDIC-BR, EBCDIC-CA-FR, EBCDIC-CP-AR1, EBCDIC-CP-AR2,
EBCDIC-CP-BE, EBCDIC-CP-CA, EBCDIC-CP-CH, EBCDIC-CP-DK, EBCDIC-CP-ES,
EBCDIC-CP-FI, EBCDIC-CP-FR, EBCDIC-CP-GB, EBCDIC-CP-GR, EBCDIC-CP-HE,
EBCDIC-CP-IS, EBCDIC-CP-IT, EBCDIC-CP-NL, EBCDIC-CP-NO, EBCDIC-CP-ROECE,
EBCDIC-CP-SE, EBCDIC-CP-TR, EBCDIC-CP-US, EBCDIC-CP-WT, EBCDIC-CP-YU,
EBCDIC-CYRILLIC, EBCDIC-DK-NO-A, EBCDIC-DK-NO, EBCDIC-ES-A, EBCDIC-ES-S,
EBCDIC-ES, EBCDIC-FI-SE-A, EBCDIC-FI-SE, EBCDIC-FR, EBCDIC-GREEK, EBCDIC-INT,
EBCDIC-INT1, EBCDIC-IS-FRISS, EBCDIC-IT, EBCDIC-JP-E, EBCDIC-JP-KANA,
EBCDIC-PT, EBCDIC-UK, EBCDIC-US, EBCDICATDE, EBCDICATDEA, EBCDICCAFR,
EBCDICDKNO, EBCDICDKNOA, EBCDICES, EBCDICESA, EBCDICESS, EBCDICFISE,
EBCDICFISEA, EBCDICFR, EBCDICISFRISS, EBCDICIT, EBCDICPT, EBCDICUK, EBCDICUS,
ECMA-114, ECMA-118, ECMA-128, ECMA-CYRILLIC, ECMACYRILLIC, ELOT_928, ES, ES2,
EUC-CN, EUC-JISX0213, EUC-JP-MS, EUC-JP, EUC-KR, EUC-TW, EUCCN, EUCJP-MS,
EUCJP-OPEN, EUCJP-WIN, EUCJP, EUCKR, EUCTW, FI, FR, GB, GB2312, GB13000,
GB18030, GBK, GB_1988-80, GB_198880, GEORGIAN-ACADEMY, GEORGIAN-PS,
GOST_19768-74, GOST_19768, GOST_1976874, GREEK-CCITT, GREEK, GREEK7-OLD,
GREEK7, GREEK7OLD, GREEK8, GREEKCCITT, HEBREW, HP-GREEK8, HP-ROMAN8,
HP-ROMAN9, HP-THAI8, HP-TURKISH8, HPGREEK8, HPROMAN8, HPROMAN9, HPTHAI8,
HPTURKISH8, HU, IBM-803, IBM-856, IBM-901, IBM-902, IBM-921, IBM-922,
IBM-930, IBM-932, IBM-933, IBM-935, IBM-937, IBM-939, IBM-943, IBM-1008,
IBM-1025, IBM-1046, IBM-1047, IBM-1097, IBM-1112, IBM-1122, IBM-1123,
IBM-1124, IBM-1129, IBM-1130, IBM-1132, IBM-1133, IBM-1137, IBM-1140,
IBM-1141, IBM-1142, IBM-1143, IBM-1144, IBM-1145, IBM-1146, IBM-1147,
IBM-1148, IBM-1149, IBM-1153, IBM-1154, IBM-1155, IBM-1156, IBM-1157,
IBM-1158, IBM-1160, IBM-1161, IBM-1162, IBM-1163, IBM-1164, IBM-1166,
IBM-1167, IBM-1364, IBM-1371, IBM-1388, IBM-1390, IBM-1399, IBM-4517,
IBM-4899, IBM-4909, IBM-4971, IBM-5347, IBM-9030, IBM-9066, IBM-9448,
IBM-12712, IBM-16804, IBM037, IBM038, IBM256, IBM273, IBM274, IBM275, IBM277,
IBM278, IBM280, IBM281, IBM284, IBM285, IBM290, IBM297, IBM367, IBM420,
IBM423, IBM424, IBM437, IBM500, IBM775, IBM803, IBM813, IBM819, IBM848,
IBM850, IBM851, IBM852, IBM855, IBM856, IBM857, IBM860, IBM861, IBM862,
IBM863, IBM864, IBM865, IBM866, IBM866NAV, IBM868, IBM869, IBM870, IBM871,
IBM874, IBM875, IBM880, IBM891, IBM901, IBM902, IBM903, IBM904, IBM905,
IBM912, IBM915, IBM916, IBM918, IBM920, IBM921, IBM922, IBM930, IBM932,
IBM933, IBM935, IBM937, IBM939, IBM943, IBM1004, IBM1008, IBM1025, IBM1026,
IBM1046, IBM1047, IBM1089, IBM1097, IBM1112, IBM1122, IBM1123, IBM1124,
IBM1129, IBM1130, IBM1132, IBM1133, IBM1137, IBM1140, IBM1141, IBM1142,
IBM1143, IBM1144, IBM1145, IBM1146, IBM1147, IBM1148, IBM1149, IBM1153,
IBM1154, IBM1155, IBM1156, IBM1157, IBM1158, IBM1160, IBM1161, IBM1162,
IBM1163, IBM1164, IBM1166, IBM1167, IBM1364, IBM1371, IBM1388, IBM1390,
IBM1399, IBM4517, IBM4899, IBM4909, IBM4971, IBM5347, IBM9030, IBM9066,
IBM9448, IBM12712, IBM16804, IEC_P27-1, IEC_P271, INIS-8, INIS-CYRILLIC,
INIS, INIS8, INISCYRILLIC, ISIRI-3342, ISIRI3342, ISO-2022-CN-EXT,
ISO-2022-CN, ISO-2022-JP-2, ISO-2022-JP-3, ISO-2022-JP, ISO-2022-KR,
ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6,
ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-8859-9E, ISO-8859-10, ISO-8859-11,
ISO-8859-13, ISO-8859-14, ISO-8859-15, ISO-8859-16, ISO-10646-UCS-2,
ISO-10646, ISO-10646/UCS2, ISO-10646/UCS4, ISO-10646/UTF-8, ISO-10646/UTF8,
ISO-CELTIC, ISO-IR-4, ISO-IR-6, ISO-IR-8-1, ISO-IR-9-1, ISO-IR-10, ISO-IR-11,
ISO-IR-14, ISO-IR-15, ISO-IR-16, ISO-IR-17, ISO-IR-18, ISO-IR-19, ISO-IR-21,
ISO-IR-25, ISO-IR-27, ISO-IR-37, ISO-IR-49, ISO-IR-50, ISO-IR-51, ISO-IR-54,
ISO-IR-55, ISO-IR-57, ISO-IR-60, ISO-IR-61, ISO-IR-69, ISO-IR-84, ISO-IR-85,
ISO-IR-86, ISO-IR-88, ISO-IR-89, ISO-IR-90, ISO-IR-92, ISO-IR-98, ISO-IR-99,
ISO-IR-100, ISO-IR-101, ISO-IR-103, ISO-IR-109, ISO-IR-110, ISO-IR-111,
ISO-IR-121, ISO-IR-122, ISO-IR-126, ISO-IR-127, ISO-IR-138, ISO-IR-139,
ISO-IR-141, ISO-IR-143, ISO-IR-144, ISO-IR-148, ISO-IR-150, ISO-IR-151,
ISO-IR-153, ISO-IR-155, ISO-IR-156, ISO-IR-157, ISO-IR-166, ISO-IR-179,
ISO-IR-193, ISO-IR-197, ISO-IR-199, ISO-IR-203, ISO-IR-209, ISO-IR-226,
ISO/TR_11548-1, ISO646-CA, ISO646-CA2, ISO646-CN, ISO646-CU, ISO646-DE,
ISO646-DK, ISO646-ES, ISO646-ES2, ISO646-FI, ISO646-FR, ISO646-FR1,
ISO646-GB, ISO646-HU, ISO646-IT, ISO646-JP-OCR-B, ISO646-JP, ISO646-KR,
ISO646-NO, ISO646-NO2, ISO646-PT, ISO646-PT2, ISO646-SE, ISO646-SE2,
ISO646-US, ISO646-YU, ISO2022CN, ISO2022CNEXT, ISO2022JP, ISO2022JP2,
ISO2022KR, ISO6937, ISO8859-1, ISO8859-2, ISO8859-3, ISO8859-4, ISO8859-5,
ISO8859-6, ISO8859-7, ISO8859-8, ISO8859-9, ISO8859-9E, ISO8859-10,
ISO8859-11, ISO8859-13, ISO8859-14, ISO8859-15, ISO8859-16, ISO11548-1,
ISO88591, ISO88592, ISO88593, ISO88594, ISO88595, ISO88596, ISO88597,
ISO88598, ISO88599, ISO88599E, ISO885910, ISO885911, ISO885913, ISO885914,
ISO885915, ISO885916, ISO_646.IRV:1991, ISO_2033-1983, ISO_2033,
ISO_5427-EXT, ISO_5427, ISO_5427:1981, ISO_5427EXT, ISO_5428, ISO_5428:1980,
ISO_6937-2, ISO_6937-2:1983, ISO_6937, ISO_6937:1992, ISO_8859-1,
ISO_8859-1:1987, ISO_8859-2, ISO_8859-2:1987, ISO_8859-3, ISO_8859-3:1988,
ISO_8859-4, ISO_8859-4:1988, ISO_8859-5, ISO_8859-5:1988, ISO_8859-6,
ISO_8859-6:1987, ISO_8859-7, ISO_8859-7:1987, ISO_8859-7:2003, ISO_8859-8,
ISO_8859-8:1988, ISO_8859-9, ISO_8859-9:1989, ISO_8859-9E, ISO_8859-10,
ISO_8859-10:1992, ISO_8859-14, ISO_8859-14:1998, ISO_8859-15,
ISO_8859-15:1998, ISO_8859-16, ISO_8859-16:2001, ISO_9036, ISO_10367-BOX,
ISO_10367BOX, ISO_11548-1, ISO_69372, IT, JIS_C6220-1969-RO,
JIS_C6229-1984-B, JIS_C62201969RO, JIS_C62291984B, JOHAB, JP-OCR-B, JP, JS,
JUS_I.B1.002, KOI-7, KOI-8, KOI8-R, KOI8-RU, KOI8-T, KOI8-U, KOI8, KOI8R,
KOI8U, KSC5636, L1, L2, L3, L4, L5, L6, L7, L8, L10, LATIN-9, LATIN-GREEK-1,
LATIN-GREEK, LATIN1, LATIN2, LATIN3, LATIN4, LATIN5, LATIN6, LATIN7, LATIN8,
LATIN9, LATIN10, LATINGREEK, LATINGREEK1, MAC-CENTRALEUROPE, MAC-CYRILLIC,
MAC-IS, MAC-SAMI, MAC-UK, MAC, MACCYRILLIC, MACINTOSH, MACIS, MACUK,
MACUKRAINIAN, MIK, MS-ANSI, MS-ARAB, MS-CYRL, MS-EE, MS-GREEK, MS-HEBR,
MS-MAC-CYRILLIC, MS-TURK, MS932, MS936, MSCP949, MSCP1361, MSMACCYRILLIC,
MSZ_7795.3, MS_KANJI, NAPLPS, NATS-DANO, NATS-SEFI, NATSDANO, NATSSEFI,
NC_NC0010, NC_NC00-10, NC_NC00-10:81, NF_Z_62-010, NF_Z_62-010_(1973),
NF_Z_62-010_1973, NF_Z_62010, NF_Z_62010_1973, NO, NO2, NS_4551-1, NS_4551-2,
NS_45511, NS_45512, OS2LATIN1, OSF00010001, OSF00010002, OSF00010003,
OSF00010004, OSF00010005, OSF00010006, OSF00010007, OSF00010008, OSF00010009,
OSF0001000A, OSF00010020, OSF00010100, OSF00010101, OSF00010102, OSF00010104,
OSF00010105, OSF00010106, OSF00030010, OSF0004000A, OSF0005000A, OSF05010001,
OSF100201A4, OSF100201A8, OSF100201B5, OSF100201F4, OSF100203B5, OSF1002011C,
OSF1002011D, OSF1002035D, OSF1002035E, OSF1002035F, OSF1002036B, OSF1002037B,
OSF10010001, OSF10010004, OSF10010006, OSF10020025, OSF10020111, OSF10020115,
OSF10020116, OSF10020118, OSF10020122, OSF10020129, OSF10020352, OSF10020354,
OSF10020357, OSF10020359, OSF10020360, OSF10020364, OSF10020365, OSF10020366,
OSF10020367, OSF10020370, OSF10020387, OSF10020388, OSF10020396, OSF10020402,
OSF10020417, PT, PT2, PT154, R8, R9, RK1048, ROMAN8, ROMAN9, RUSCII, SE, SE2,
SEN_850200_B, SEN_850200_C, SHIFT-JIS, SHIFT_JIS, SHIFT_JISX0213, SJIS-OPEN,
SJIS-WIN, SJIS, SS636127, STRK1048-2002, ST_SEV_358-88, T.61-8BIT, T.61,
T.618BIT, TCVN-5712, TCVN, TCVN5712-1, TCVN5712-1:1993, THAI8, TIS-620,
TIS620-0, TIS620.2529-1, TIS620.2533-0, TIS620, TS-5881, TSCII, TURKISH8,
UCS-2, UCS-2BE, UCS-2LE, UCS-4, UCS-4BE, UCS-4LE, UCS2, UCS4, UHC, UJIS, UK,
UNICODE, UNICODEBIG, UNICODELITTLE, US-ASCII, US, UTF-7, UTF-8, UTF-16,
UTF-16BE, UTF-16LE, UTF-32, UTF-32BE, UTF-32LE, UTF7, UTF8, UTF16, UTF16BE,
UTF16LE, UTF32, UTF32BE, UTF32LE, VISCII, WCHAR_T, WIN-SAMI-2, WINBALTRIM,
WINDOWS-31J, WINDOWS-874, WINDOWS-936, WINDOWS-1250, WINDOWS-1251,
WINDOWS-1252, WINDOWS-1253, WINDOWS-1254, WINDOWS-1255, WINDOWS-1256,
WINDOWS-1257, WINDOWS-1258, WINSAMI2, WS2, YU
[root@model test]#
1.3.14 dos2unix
用于将dos文本转换成unix
[root@model test]# ls
file1 lin.bat linzhou3Dbobo.bat uniq.txt
[root@model test]# dos2unix lin.bat
dos2unix: converting file lin.bat to UNIX format ...
[root@model test]# cat lin.bat
@ECHO OFF
echo "V?′|-2?·?D2¥2¥Ξ·¨?3£°2?"
echo "--------------------------------"
set /p ip="Please input contorl ip: "
adb kill-server
adb start-server
adb connect %ip%
adb uninstall com.bobo.splayer
adb install C:\Users\Administrator\Desktop\3dbb_5.7.2_dangbei.apk
adb reboot
[root@model test]#
dos2unix -n:不改变原先的脚本,在副本添加(-k:不改变原先的属性)
[root@model test]# dos2unix -n -k linzhou3Dbobo.bat lz3d.bat
dos2unix: converting file linzhou3Dbobo.bat to file lz3d.bat in UNIX format ...
正常的:[root@model test]# vim linzhou3Dbobo.bat
@ECHO OFF
^M
echo "á??Y′|àí2?·?3D2¥2¥?T·¨?y3£°2×°"^M
echo "--------------------------------"^M
set /p ip="Please input contorl ip: " ^M
adb kill-server^M
adb start-server^M
adb connect %ip%^M
adb uninstall com.bobo.splayer
adb install C:\Users\Administrator\Desktop\3dbb_5.7.2_dangbei.apk
adb reboot
修改完的:[root@model test]# vim lz3d.bat
@ECHO OFF
echo "á??Y′|àí2?·?3D2¥2¥?T·¨?y3£°2×°"
echo "--------------------------------"
set /p ip="Please input contorl ip: "
adb kill-server
adb start-server
adb connect %ip%
adb uninstall com.bobo.splayer
adb install C:\Users\Administrator\Desktop\3dbb_5.7.2_dangbei.apk
adb reboot
1.3.15 vimdiff
用命令vimdiff比较aa.txt和passwd的不同
扩展:ctrl +w:却换窗格
1.3.16 rev
rev:将输入的文本反过来
[root@model test]# cat passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
[root@model test]# rev passwd
hsab/nib/:toor/:toor:0:0:x:toor
nigolon/nibs/:nib/:nib:1:1:x:nib
nigolon/nibs/:nibs/:nomead:2:2:x:nomead
nigolon/nibs/:mda/rav/:mda:4:3:x:mda
nigolon/nibs/:dpl/loops/rav/:pl:7:4:x:pl
cnys/nib/:nibs/:cnys:0:5:x:cnys
nwodtuhs/nibs/:nibs/:nwodtuhs:0:6:x:nwodtuhs
tlah/nibs/:nibs/:tlah:0:7:x:tlah
nigolon/nibs/:liam/loops/rav/:liam:21:8:x:liam
nigolon/nibs/:pcuu/loops/rav/:pcuu:41:01:x:pcuu
nigolon/nibs/:toor/:rotarepo:0:11:x:rotarepo
nigolon/nibs/:semag/rsu/:semag:001:21:x:semag
nigolon/nibs/:rehpog/rav/:rehpog:03:31:x:rehpog
nigolon/nibs/:ptf/rav/:resU PTF:05:41:x:ptf
nigolon/nibs/:/:ydoboN:99:99:x:ydobon
nigolon/nibs/:ved/:renwo yromem elosnoc lautriv:96:96:x:ascv
nigolon/nibs/:htualsas/ytpme/rav/:resu dhtualsaS:67:994:x:htualsas
nigolon/nibs/:xiftsop/loops/rav/::98:98:x:xiftsop
nigolon/nibs/:dhss/ytpme/rav/:HSS detarapes-egelivirP:47:47:x:dhss
[root@model test]#
1.3.17 join(后续整理)
join:相当于将2个文件关联的内容进行结合
1.3.18 tr(单个字符之间的替换,不是全部替换)****
tr 'a-z' 'A-Z':将字符小写替换成大写
[root@model test]# vim 1.txt
abcdEFG
[root@model test]# cat 1.txt | tr 'a-z' 'A-Z'
ABCDEFG
tr -d '1-9':将查看你到的文件内容包含数字1-9的删除
[root@model test]# cat 2.txt
AAAAAABBBBBBBBBBBBBB1111112222222233333333344444455
[root@model test]# cat 2.txt | tr -d '1-9'
AAAAAABBBBBBBBBBBBBB
[root@model test]#
tr ' ' '\n':将空格转换成换行
[root@model test]# cat 2.txt
AAAAAABBBBBBBBBBBBBB 111111 2222222233333333344444455
[root@model test]# cat 2.txt | tr ' ' '\n'
AAAAAABBBBBBBBBBBBBB
111111
2222222233333333344444455
[root@model test]#
创建随机密码
[root@oldboy6666 oldboy] # tr -cd 'a-z A-Z 0-9' < /dev/urandom | head -c 5
mpcek
[root@oldboy6666 oldboy] # tr -cd 'a-z A-Z 0-9' < /dev/urandom | head -c 5
QAr7F
[root@oldboy6666 oldboy] #
将文件里面的oldboy全部替换成oldgirl
[root@oldboy6666 oldboy] # tr 'oldboy' 'oldgirl' < oldboy.txt
ildgir
ildgirl
ildgagr
ilddig
[root@oldboy6666 oldboy] #
tr命令口诀
前后一样,直接替换
前短后长,最后不换
前长后短,多个共用
前后重复,最新带上
1.4 信息显示命令
1.4.1 uname****
uname:打印当前系统的信息(-r:查看内核版本;-a:查看所有的信息;-m:查看操作系统;-n:查看主机名)
[root@model test]# uname -r
2.6.32-696.el6.x86_64
[root@model test]# uname -a
Linux model 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@model test]# uname -m
x86_64
[root@model test]# uname -n
model
1.4.2 hostname****
hostname:查看主机名
[root@model test]# hostname
model
hostname +主机名:修改主机名(临时的)将主机名改为aa
[root@model test]# uname -n
model
[root@model test]#hostname aa
[root@model test]# logout
Last login: Sat Apr 20 23:39:56 2019 from 192.168.43.200
[root@aa ~]#
永久修改主机名(centos 6)
[root@aa ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=model
[root@aa ~]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=aa
[root@aa ~]#
[root@aa ~]# . /etc/sysconfig/network
[root@aa ~]#
[root@aa ~]#
永久修改主机名(centos 7)
第一种:修改配置文件
[root@oldboy6666 ~]# cat /etc/hostname
oldboy6666
[root@oldboy6666 ~]#
[root@oldboy6666 ~]# cat /etc/hostname
oldboy6666
[root@oldboy6666 ~]#
第二种
[root@oldboy6666 oldboy] # hostnamectl set-hostname oldboy6666
1.4.3 dmesg
dmesg:用于检查和控制内核的缓冲区;开机信息保存在/var/log/dmesg
[root@model ~]# dmesg |head -10
Initializing cgroup subsys cpuset
Initializing cgroup subsys cpu
Linux version 2.6.32-696.el6.x86_64 (mockbuild@c1bm.rdu2.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) ) #1 SMP Tue Mar 21 19:29:05 UTC 2017
Command line: ro root=UUID=b262ea2c-9e6d-49cb-83ee-47f50e39f195 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
KERNEL supported cpus:
Intel GenuineIntel
AMD AuthenticAMD
Centaur CentaurHauls
Disabled fast string operations
BIOS-provided physical RAM map:
[root@model ~]#
1.4.4 uptime
- (18:23:42:代表当前的系统时间
- up 3:23:运行了3个多小时
- 3users:当前连接用户数为3
-
load:系统在过去的1分钟、5分钟和15分钟内的平均负载
[root@model ~]# uptime
18:23:42 up 3:23, 3 users, load average: 0.08, 0.02, 0.011.4.5 stat
1.4.6 du
du:查看使用空间(查看20190420目录下面的每个文件夹的大小)
[root@model ~]# du 20190420/
40 20190420/test
44 20190420/
[root@model ~]#
du -sh 20190420:查看20190420的占用空间总大小
[root@model ~]# du -sh 20190420/
44K 20190420/
[root@model ~]#
1.4.7 df
df -h:以人类可读的方式
[root@model ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 16G 792M 14G 6% /
tmpfs 601M 0 601M 0% /dev/shm
/dev/sda1 190M 27M 154M 15% /boot
df -a:用于显示磁盘的空间全部信息
[root@model ~]# df -a
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 16276904 810496 14632924 6% /
proc 0 0 0 - /proc
sysfs 0 0 0 - /sys
devpts 0 0 0 - /dev/pts
tmpfs 614692 0 614692 0% /dev/shm
/dev/sda1 194241 27089 156912 15% /boot
none 0 0 0 - /proc/sys/fs/binfmt_misc
[root@model ~]#
df -i:用于显示inode号码
[root@oldboyedu oldboy02] # df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda3 51539456 179242 51360214 1% /
devtmpfs 120529 441 120088 1% /dev
tmpfs 124468 1 124467 1% /dev/shm
tmpfs 124468 1051 123417 1% /run
tmpfs 124468 16 124452 1% /sys/fs/cgroup
/dev/sdb1 768 11 757 2% /mnt
/dev/sda1 75800 346 75454 1% /boot
tmpfs 124468 18 124450 1% /run/user/988
tmpfs 124468 1 124467 1% /run/user/0
You have new mail in /var/spool/mail/root
[root@oldboyedu oldboy02] #
1.4.8 top
top:动态检测系统性能的工具
[root@model ~]# top
top - 18:37:04 up 3:36, 3 users, load average: 0.00, 0.00, 0.00
Tasks: 95 total, 1 running, 94 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.2%sy, 0.0%ni, 99.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1229388k total, 261676k used, 967712k free, 10608k buffers
Swap: 4095996k total, 0k used, 4095996k free, 119320k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
12 root 20 0 0 0 0 S 0.3 0.0 0:03.65 events/1
2439 root 20 0 99.7m 4156 3148 S 0.3 0.3 0:00.58 sshd
1 root 20 0 19236 1500 1228 S 0.0 0.1 0:01.82 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kthreadd
3 root RT 0 0 0 0 S 0.0 0.0 0:00.60 migration/0
4 root 20 0 0 0 0 S 0.0 0.0 0:00.01 ksoftirqd/0
5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0
6 root RT 0 0 0 0 S 0.0 0.0 0:00.03 watchdog/0
top字段的介绍
- 18:37:04 当前系统时间
- up 3:36 运行时间
- 3 users 当前连接用户数
- Tasks 95 total: 总进程数
- 1 running 正在运行的数
- 94 sleeping 正在睡眠的进程数
- 0 stopped 停止的进程数
- 0 zombie 冻结的进程数
- Cpu(s) 用户空间占用CPU百分比
- Us 进程空间占用CPU百分比
- Mem: 总共,使用,剩余,缓存(内存)
-
Swap 总共,使用,剩余,缓存(交换分区)
1.4.9 free****
free -h:以人类可读的形式展示
[root@oldboy6666 oldboy] # free -h
total used free shared buff/cache available
Mem: 972M 487M 87M 14M 397M 272M
Swap: 1.5G 116M 1.4G
[root@oldboy6666 oldboy] #
free字段的介绍
- total 内存总数
- used 已使用的内存数
- free 剩余的内存数
- shared 废弃的内存数
- buffer/cache 写缓冲/读缓存
-
available 空闲的内存数(最重要)
1.4.10 date****
date:查看当前的日期
[root@model ~]# date
2019年 04月 20日 星期六 19:01:08 CST
[root@model ~]#
date字段介绍
-
y 代表年
-
Y 代表年(带世纪)
-
m 代表分钟
-
M 代表月
-
d 代表天
-
S 代表秒
-
W 代表一年的第几周
-
w 代表这周星期几
-
H 代表小时
[root@model ~]# date -d "+1 day" 加一天
2019年 04月 21日 星期日 19:23:38 CST
[root@model ~]# date -d "-1 day" 减一天
2019年 04月 19日 星期五 19:23:47 CST
[root@model ~]# date -d "-1 month" 减一月
2019年 03月 20日 星期三 19:23:55 CST
[root@model ~]# date -d "+1 month" 加一月
2019年 05月 20日 星期一 19:24:00 CST
[root@model ~]# date -d "+1 year" 加一年
2020年 04月 20日 星期一 19:24:08 CST
[root@model ~]# date -d "-1 year" 减一年
2018年 04月 20日 星期五 19:24:13 CST
[root@model ~]#
传说中的1234567890秒
[root@model ~]# date -d "1979-01-01 1234567890 second"
2018年 02月 13日 星期二 23:31:30 CST
[root@model ~]#
1.4.11 cal
cal:打印日历
[root@model ~]# cal
四月 2019
日 一 二 三 四 五 六
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@model ~]#
cal +年份:显示这年的日历
[root@model ~]# cal 2018
2018
一月 二月 三月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 4 5 6 1 2 3 1 2 3
7 8 9 10 11 12 13 4 5 6 7 8 9 10 4 5 6 7 8 9 10
14 15 16 17 18 19 20 11 12 13 14 15 16 17 11 12 13 14 15 16 17
21 22 23 24 25 26 27 18 19 20 21 22 23 24 18 19 20 21 22 23 24
28 29 30 31 25 26 27 28 25 26 27 28 29 30 31
四月 五月 六月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 4 5 6 7 1 2 3 4 5 1 2
8 9 10 11 12 13 14 6 7 8 9 10 11 12 3 4 5 6 7 8 9
15 16 17 18 19 20 21 13 14 15 16 17 18 19 10 11 12 13 14 15 16
22 23 24 25 26 27 28 20 21 22 23 24 25 26 17 18 19 20 21 22 23
29 30 27 28 29 30 31 24 25 26 27 28 29 30
七月 八月 九月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 4 5 6 7 1 2 3 4 1
8 9 10 11 12 13 14 5 6 7 8 9 10 11 2 3 4 5 6 7 8
15 16 17 18 19 20 21 12 13 14 15 16 17 18 9 10 11 12 13 14 15
22 23 24 25 26 27 28 19 20 21 22 23 24 25 16 17 18 19 20 21 22
29 30 31 26 27 28 29 30 31 23 24 25 26 27 28 29
30
十月 十一月 十二月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 4 5 6 1 2 3 1
7 8 9 10 11 12 13 4 5 6 7 8 9 10 2 3 4 5 6 7 8
14 15 16 17 18 19 20 11 12 13 14 15 16 17 9 10 11 12 13 14 15
21 22 23 24 25 26 27 18 19 20 21 22 23 24 16 17 18 19 20 21 22
28 29 30 31 25 26 27 28 29 30 23 24 25 26 27 28 29
30 31
[root@model ~]#
cal -j:显示当前的日期在今年第几天
[root@model ~]# cal -j
四月 2019
日 一 二 三 四 五 六
91 92 93 94 95 96
97 98 99 100 101 102 103
104 105 106 107 108 109 110
111 112 113 114 115 116 117
118 119 120
[root@model ~]#
cal -3:显示临近4个月的日历
[root@model ~]# cal -3
三月 2019 四月 2019 五月 2019
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 1 2 3 4 5 6 1 2 3 4
3 4 5 6 7 8 9 7 8 9 10 11 12 13 5 6 7 8 9 10 11
10 11 12 13 14 15 16 14 15 16 17 18 19 20 12 13 14 15 16 17 18
17 18 19 20 21 22 23 21 22 23 24 25 26 27 19 20 21 22 23 24 25
24 25 26 27 28 29 30 28 29 30 26 27 28 29 30 31
31
[root@model ~]#
1.4.12 lscpu****
查看cpu的命令
[root@oldboy6666 ~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 1
NUMA node(s): 1
Vendor ID: AuthenticAMD
CPU family: 23
Model: 24
Model name: AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx
Stepping: 1
CPU MHz: 2096.060
BogoMIPS: 4192.12
Hypervisor vendor: VMware
Virtualization type: full
L1d cache: 32K
L1i cache: 64K
L2 cache: 512K
L3 cache: 4096K
NUMA node0 CPU(s): 0
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc art rep_good nopl tsc_reliable nonstop_tsc extd_apicid aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw retpoline_amd ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap xsaveopt xsavec xgetbv1 clzero irperf xsaveerptr arat
[root@oldboy6666 ~]#
1.5 搜索文件命令
1.5.1 which****
which:查找系统命令路径
[root@model ~]# which pwd
/bin/pwd
[root@model ~]# which cd
/usr/bin/which: no cd in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root@model ~]# which mkdir
/bin/mkdir
[root@model ~]# which useradd
/usr/sbin/useradd
[root@model ~]# which userdel
/usr/sbin/userdel
[root@model ~]#
1.5.2 whereis****
whereis:用于命令文件路径查找和man手册文件和其他有关文件路径的查找
查找yum文件的路径
[root@model bin]# whereis yum
yum: /usr/bin/yum /etc/yum.conf /etc/yum /usr/share/man/man8/yum.8.gz
只查找二进制文件(-b)
[root@model bin]# whereis -b yum
yum: /usr/bin/yum /etc/yum.conf /etc/yum1.5.4
查找yum的源文件(-s(source))
[root@model bin]# whereis -s yum
yum:
[root@model bin]#
查找yum的man文件(-m(man))
[root@model bin]# whereis -m yum
yum: /usr/share/man/man8/yum.8.gz
[root@model bin]#
1.5.3 find*****
语法格式:find 路径 执行的参数
根据文件名称进行查找(-name,-iname(不区分大小写))
-
查找/root/oldboy01目录下1.txt的文件
[root@oldboy6666 ~] # find /root/oldboy01 -name "1.txt"
/root/oldboy01/1.txt
/root/oldboy01/oldboy02/1.txt
[root@oldboy6666 ~] #
-
查找/root/oldboy01目录下a(A).txt的文件
[root@oldboy6666 oldboy02] # find /root/oldboy01 -iname "a.txt"
/root/oldboy01/oldboy02/a.txt
/root/oldboy01/oldboy02/A.txt
/root/oldboy01/a.txt
[root@oldboy6666 oldboy02] #
根据文件的类型进行查找(-type)
- 文件 f
- 目录 d
- 链接 l
- 块设备 b
- 字符流 c
- 套接字 s
-
查找/root/oldboy01目录下文件的并且名字为a.txt的文件
[root@oldboy6666 oldboy02] # find /root/oldboy01 -type f -name "a.txt"
/root/oldboy01/oldboy02/a.txt
/root/oldboy01/a.txt
[root@oldboy6666 oldboy02] #
根据文件的大小进行查找(-size)
常见的文件大小单位
- c 字节单位
- b 块设备(512字节,块设备查找只能是512字节的倍数才能查找出来)
- w (1w=2字节)
- K KB
- M MB
- G GB
-
查找/root/oldboy01目录下文件大于1M的
[root@oldboy6666 oldboy01] # find /root/oldboy01 -size +1M
/root/oldboy01/2.txt
/root/oldboy01/4.txt
[root@oldboy6666 oldboy01] #
注意
+1M:查找大于1M的文件
-1M:查找小于1M的文件
1M:查找等于1M的文件
根据文件的权限来进行查找(-perm)
-
查找文件的权限为755的文件或者目录
[root@oldboy6666 oldboy01] # find /root/oldboy01 -perm 755
/root/oldboy01
/root/oldboy01/oldboy02
/root/oldboy01/2.txt
[root@oldboy6666 oldboy01] #
根据文件的修改时间来进行查找(-mtime)
-
查找文件的修改时间在7天之内的
[root@oldboy6666 oldboy01] # find /root/oldboy01 -mtime -7
/root/oldboy01
/root/oldboy01/1.txt
/root/oldboy01/oldboy02
/root/oldboy01/oldboy02/2.txt
/root/oldboy01/oldboy02/1.txt
/root/oldboy01/oldboy02/a.txt
/root/oldboy01/oldboy02/A.txt
/root/oldboy01/a.txt
/root/oldboy01/2.txt
/root/oldboy01/3.txt
/root/oldboy01/4.txt
/root/oldboy01/5.txt
[root@oldboy6666 oldboy01] #
注意
- +7 代表7天以前的信息文件
- -7 代表7天之内的信息文件
-
7 代表正好是第7天的信息文件
根据文件的路径进行查找(-path)
-
查找/root/oldboy01/oldboy02目录
[root@oldboy6666 oldboy01] # find /root/oldboy01 -path /root/oldboy01/oldboy02
/root/oldboy01/oldboy02
根据文件的inode来进行查找(-inum)
-
查找inode的数为202165184
[root@oldboy6666 oldboy01] # ll -i
total 13324
202165181 -rwxrw-rw- 1 root root 0 Sep 16 19:14 1.txt
202120440 -rwxr-xr-x 1 root root 2097152 Sep 16 19:28 2.txt
202120442 -rwxrw-rw- 1 root root 1048576 Sep 16 19:28 3.txt
202118699 -rwxrw-rw- 1 root root 10485760 Sep 16 19:28 4.txt
202035674 -rwxrw-rw- 1 root root 10240 Sep 16 19:28 5.txt
202035661 -rwxrw-rw- 1 root root 0 Sep 16 19:19 a.txt
202165184 -rw-r--r-- 2 root root 0 Sep 16 19:14 hard.txt
202165182 drwxr-xr-x 2 root root 58 Sep 16 19:19 oldboy02
[root@oldboy6666 oldboy01] # find /root/oldboy01/ -inum "202165184"
/root/oldboy01/oldboy02/1.txt
/root/oldboy01/hard.txt
[root@oldboy6666 oldboy01] #
根据文件的最大深度进行查找(-maxdepth)
查找/etc/目录下面最大深度为1的目录,并且统计有多少个目录
[root@oldboy6666 ~] # find /etc -maxdepth 1 -type d | wc -l
80
[root@oldboy6666 ~] #
根据文件的最小深度进行查找(mindepth)
查找/etc/目录下面最小深度为2的目录,并且统计有多少个目录
[root@oldboy6666 ~] # find /etc -mindepth 2 -type d | wc -l
534
[root@oldboy6666 ~] #
1.5.3.1 查找文件的信息,并且进行删除
-delete参数的使用
[root@oldboy6666 oldboy01] # find /root/oldboy01/ -inum "202165184"
/root/oldboy01/oldboy02/1.txt
/root/oldboy01/hard.txt
[root@oldboy6666 oldboy01] # find /root/oldboy01/ -inum "202165184" -delete
[root@oldboy6666 oldboy01] # find /root/oldboy01/ -inum "202165184"
[root@oldboy6666 oldboy01] #
-exec命令的使用
[root@oldboy6666 oldboy02] # find /root/oldboy01/ -name "2.txt"
/root/oldboy01/oldboy02/2.txt
/root/oldboy01/2.txt
[root@oldboy6666 oldboy02] # find /root/oldboy01/ -name "2.txt" -exec rm {} \;
[root@oldboy6666 oldboy02] # find /root/oldboy01/ -name "2.txt"
[root@oldboy6666 oldboy02] #
1.5.4 locate****
locate:使用locate命令的时候要记得更新数据库(updatedb),比如查找/etc/*.sh的文件(-i:忽略大小写)
[root@model bin]# updatedb
[root@model bin]# locate /etc/*.sh
/etc/bash_completion.d/gdbus-bash-completion.sh
/etc/dhcp/dhclient-exit-hooks.d/azure-cloud.sh
/etc/profile.d/colorls.sh
/etc/profile.d/glib2.sh
/etc/profile.d/lang.sh
/etc/profile.d/less.sh
/etc/profile.d/vim.sh
/etc/profile.d/which2.sh
1.6 用户管理命令
1.6.1 useradd****
/etc/passwd:用户
/etc/shadow:密码
创建一个用户test1
[root@model aa]# useradd test1
useradd:警告:此主目录已经存在。
不从 skel 目录里向其中复制任何文件。
正在创建信箱文件: 文件已存在
[root@model aa]# cat /etc/passwd
.....................
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
test1:x:500:500::/home/test1:/bin/bash
[root@model aa]# cat /etc/group
......................
sshd:x:74:
slocate:x:21:
test1:x:500:
[root@model aa]#
创建一个用户test2,并且test2可以登陆,不创建用户家目录test
[root@model aa]# useradd test2 -s /bin/bash -d /home/test -M
useradd:警告:此主目录已经存在。
不从 skel 目录里向其中复制任何文件。
正在创建信箱文件: 文件已存在
[root@model aa]# cat /etc/passwd
.....................
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
test1:x:500:500::/home/test1:/bin/bash
test2:x:501:501::/home/test:/bin/bash
[root@model aa]# cat /etc/group
......................
sshd:x:74:
slocate:x:21:
test1:x:500:
test2:x:501
创建一个用户test3,并且test3可以登陆,创建用户家目录
[root@model aa]# useradd test3 -s /bin/bash -d /home/test -m
useradd:警告:此主目录已经存在。
不从 skel 目录里向其中复制任何文件。
正在创建信箱文件: 文件已存在
[root@model aa]# cd /home/test
[root@model aa]# cat /etc/passwd
.....................
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
test1:x:500:500::/home/test1:/bin/bash
test2:x:501:501::/home/test:/bin/bash
test3:x:502:502::/home/test:/bin/bash
[root@model aa]# cat /etc/group
......................
sshd:x:74:
slocate:x:21:
test1:x:500:
test2:x:501
test3:x:502:
创建一个用户test4,并且test4不可以登录,并且指定用户初始化组为aa
[root@model test]# useradd test4 -s /sbin/nologin -g aa
useradd:警告:此主目录已经存在。
不从 skel 目录里向其中复制任何文件。
正在创建信箱文件: 文件已存在
[root@model aa]# cat /etc/passwd
.....................
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
test1:x:500:500::/home/test1:/bin/bash
test2:x:501:501::/home/test:/bin/bash
test3:x:502:502::/home/test:/bin/bash
test4:x:503:503::/home/test4:/sbin/nologin
[root@model aa]# cat /etc/group
......................
sshd:x:74:
slocate:x:21:
test1:x:500:
test2:x:501
test3:x:502:
aa:x:503:
创建一个用户test5,并且test5的用户组初始化
[root@model test]# useradd test5 -N 创建一个与用户不同的用户组
正在创建信箱文件: 文件已存在
[root@model aa]# cat /etc/passwd
.....................
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
test1:x:500:500::/home/test1:/bin/bash
test2:x:501:501::/home/test:/bin/bash
test3:x:502:502::/home/test:/bin/bash
test4:x:503:503::/home/test4:/sbin/nologin
test5:x:504:100::/home/test5:/bin/bash
[root@model aa]# cat /etc/group
......................
sshd:x:74:
slocate:x:21:
test1:x:500:
test2:x:501
test3:x:502:
aa:x:503:
1.6.2 usermod*****
usermod -d:修改用户登录时的家目录(修改登录用户test1的家目录为/home/test)
[root@model test]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
...............................
test1:x:500:500::/home/test1:/bin/bash
[root@model test]# usermod -d /home/test test1
[root@model test]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
...............................
test1:x:500:500::/home/test:/bin/bash
1.6.3 userdel******
userdel:删除用户,但是不删除用户家目录
[root@model test4]# userdel test4
test1:x:500:500::/home/test:/bin/bash
test2:x:501:501::/home/test:/bin/bash
test3:x:502:502::/home/test:/bin/bash
test5:x:504:100::/home/test5:/bin/bash
[root@model test4]# cd /home/test4
[root@model test4]#
userdel -rf:强制删除用户,并且用户家目录也会一并删除(-r:删除家目录,-f:强制删除)
[root@model test5]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
.............................
test1:x:500:500::/home/test:/bin/bash
test2:x:501:501::/home/test:/bin/bash
test3:x:502:502::/home/test3:/bin/bash
[root@model test5]# cd /home/test3
[root@model test3]# userdel -rf test3
[root@model test3]# cd /home/test3
-bash: cd: /home/test3: 没有那个文件或目录
[root@model test3]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
.......................
test1:x:500:500::/home/test:/bin/bash
test2:x:501:501::/home/test:/bin/bash
[root@model test3]#
1.6.4 groupadd*****
/etc/group 组账户信息。
/etc/gshadow 安全组账户信息。
/etc/login.defs Shadow密码套件配置
创建一个用户组bb,并且指定ID为123
[root@model ~]# groupadd -g 123 bb
[root@model ~]# cat /etc/group
root:x:0:
.......................
test1:x:500:
test2:x:501:
aa:x:503:
bb:x:123:
1.6.5 passwd****
[root@model ~]# passwd
更改用户 root 的密码 。
新的 密码:
无效的密码: WAY 过短
无效的密码: 过于简单
重新输入新的 密码:
抱歉,密码不匹配。
新的 密码:
无效的密码: 过于简单化/系统化
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。
[root@model ~]#
passwd修改密码免交互方式
[root@oldboy6666 ~]# echo "123456" | passwd --stdin oldboy101
Changing password for user oldboy101.
1.6.6 chage
chage:用来修改账号和密码的有效期限
/etc/login.dfs里面配置用户的密码、UID、GID的使用期限
[root@model data]# cat /etc/login.defs
#
# Please note that the parameters in this configuration file control the
# behavior of the tools from the shadow-utils component. None of these
# tools uses the PAM mechanism, and the utilities that use PAM (such as the
# passwd command) should therefore be configured elsewhere. Refer to
# /etc/pam.d/system-auth for more information.
#
# *REQUIRED*
# Directory where mailboxes reside, _or_ name of file, relative to the
# home directory. If you _do_ define both, MAIL_DIR takes precedence.
# QMAIL_DIR is for Qmail
#
#QMAIL_DIR Maildir
MAIL_DIR /var/spool/mail
#MAIL_FILE .mail
# Password aging controls:
#
# PASS_MAX_DAYS Maximum number of days a password may be used.
# PASS_MIN_DAYS Minimum number of days allowed between password changes.
# PASS_MIN_LEN Minimum acceptable password length.
# PASS_WARN_AGE Number of days warning given before a password expires.
#
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_MIN_LEN 5
PASS_WARN_AGE 7
#
# Min/max values for automatic uid selection in useradd
#
UID_MIN 500
UID_MAX 60000
#
# Min/max values for automatic gid selection in groupadd
#
GID_MIN 500
GID_MAX 60000
#
# If defined, this command is run when removing a user.
# It should remove any at/cron/print jobs etc. owned by
# the user to be removed (passed as the first argument).
#
#USERDEL_CMD /usr/sbin/userdel_local
#
# If useradd should create home directories for users by default
# On RH systems, we do. This option is overridden with the -m flag on
# useradd command line.
#
CREATE_HOME yes
# The permission mask is initialized to this value. If not specified,
# the permission mask will be initialized to 022.
UMASK 077
# This enables userdel to remove user groups if no members exist.
#
USERGROUPS_ENAB yes
# Use SHA512 to encrypt password.
ENCRYPT_METHOD SHA512
/etc/default/useradd:添加用户的一些默认信息
[root@model data]# cat /etc/default/useradd
# useradd defaults file
GROUP=123
HOME=/data
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
chage命令的一些参数
-m
最小天数
-M
最大天数
-W
提醒天数
-I
密码失效时期
chage -l +用户:查看用户的账号密码策略信息
[root@model data]# chage -l root
最近一次密码修改时间 :4月 21, 2019
密码过期时间 :从不
密码失效时间 :从不
帐户过期时间 :从不
两次改变密码之间相距的最小天数 :0
两次改变密码之间相距的最大天数 :99999
在密码过期之前警告的天数 :7
2次密码更改时间的最大天数
[root@model data]# chage -M 60 root
[root@model data]# chage -l root
最近一次密码修改时间 :4月 21, 2019
密码过期时间 :6月 20, 2019
密码失效时间 :从不
帐户过期时间 :从不
两次改变密码之间相距的最小天数 :0
两次改变密码之间相距的最大天数 :60
在密码过期之前警告的天数 :7
更改密码失效时间
[root@model data]# chage -I 5 root
[root@model data]# chage -l root
最近一次密码修改时间 :4月 21, 2019
密码过期时间 :6月 20, 2019
密码失效时间 :6月 25, 2019
帐户过期时间 :从不
两次改变密码之间相距的最小天数 :0
两次改变密码之间相距的最大天数 :60
在密码过期之前警告的天数 :7
[root@model data]#
1.6.7 id****
[root@model data]# id
uid=0(root) gid=0(root) 组=0(root) 环境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[root@model data]# id aa
id: aa:无此用户
[root@model data]# id test1
uid=500(test1) gid=500(test1) 组=500(test1)
[root@model data]#
1.6.8 su****
su -:用于切换当前用户的身份
[root@model data]# su - test10
[test10@model data]$ ls
test10 test11 test9
[test10@model data]$
1.6.9 visudo*******
vim /etc/sudoers(不检查语法)(visudo检查语法)
## Sudoers allows particular users to run various commands as
## the root user, without needing the root password.
## 该文件允许特定用户像root用户一样使用各种各样的命令,而不需要root用户的密码
##
## Examples are provided at the bottom of the file for collections
## of related commands, which can then be delegated out to particular
## users or groups.
## 在文件的底部提供了很多相关命令的示例以供选择,这些示例都可以被特定用户或
## 用户组所使用
##
## This file must be edited with the 'visudo' command.
## 该文件必须使用"visudo"命令编辑
## Host Aliases
## Groups of machines. You may prefer to use hostnames (perhaps using
## wildcards for entire domains) or IP addresses instead.
## 对于一组服务器,你可能会更喜欢使用主机名(可能是全域名的通配符)
## 、或IP地址,这时可以配置主机别名
# Host_Alias FILESERVERS = fs1, fs2
# Host_Alias MAILSERVERS = smtp, smtp2
## User Aliases
## These aren't often necessary, as you can use regular groups
## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname
## rather than USERALIAS
## 这并不很常用,因为你可以通过使用组来代替一组用户的别名
# User_Alias ADMINS = jsmith, mikem
## Command Aliases
## These are groups of related commands...
## 指定一系列相互关联的命令(当然可以是一个)的别名,通过赋予该别名sudo权限,
## 可以通过sudo调用所有别名包含的命令,下面是一些示例
## Networking 网络操作相关命令别名
# Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient
, /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig
, /sbin/mii-tool
## Installation and management of software 软件安装管理相关命令别名
# Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum
## Services 服务相关命令别名
# Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig
## Updating the locate database 本地数据库升级命令别名
# Cmnd_Alias LOCATE = /usr/bin/updatedb
## Storage 磁盘操作相关命令别名
# Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe
, /bin/mount, /bin/umount
## Delegating permissions 代理权限相关命令别名
# Cmnd_Alias DELEGATING = /usr/sbin/visudo, /bin/chown, /bin/chmod, /bin/chgrp
## Processes 进程相关命令别名
# Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall
## Drivers 驱动命令别名
# Cmnd_Alias DRIVERS = /sbin/modprobe
# Defaults specification
#
# Disable "ssh hostname sudo <cmd>", because it will show the password in clear.
# You have to run "ssh -t hostname sudo <cmd>".
# 一些环境变量的相关配置,具体情况可见man soduers
Defaults requiretty
Defaults env_reset
Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS"
Defaults env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"
Defaults env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"
Defaults env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"
Defaults env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## 下面是规则配置:什么用户在哪台服务器上可以执行哪些命令(sudoers文件可以在多个系统上共享)
## Syntax(语法):
##
## user MACHINE=COMMANDS 用户 登录的主机=(可以变换的身份) 可以执行的命令
##
## The COMMANDS section may have other options added to it.
## 命令部分可以附带一些其它的选项
##
## Allow root to run any commands anywhere
## 允许root用户执行任意路径下的任意命令
root ALL=(ALL) ALL
## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
## 允许sys中户组中的用户使用NETWORKING等所有别名中配置的命令
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE
, DRIVERS
## Allows people in group wheel to run all commands
## 允许wheel用户组中的用户执行所有命令
%wheel ALL=(ALL) ALL
## Same thing without a password
## 允许wheel用户组中的用户在不输入该用户的密码的情况下使用所有命令
# %wheel ALL=(ALL) NOPASSWD: ALL
## Allows members of the users group to mount and unmount the
## cdrom as root
## 允许users用户组中的用户像root用户一样使用mount、unmount、chrom命令
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
## Allows members of the users group to shutdown this system
## 允许users用户组中的用户关闭localhost这台服务器
# %users localhost=/sbin/shutdown -h now
## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
## 读取放置在/etc/sudoers.d/文件夹中的文件(此处的#不意味着这是一个声明)
#includedir /etc/sudoers.d
1.6.10 sudo*******
[root@model sudoers.d]# su admin
[admin@model sudoers.d]$ sudo ls
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for admin:
[admin@model sudoers.d]$ passwd
1.7 基础网络操作命令
1.7.1 telnet****
查看rpcbind的链路是否通
telnet 192.168.1.199 111
Trying 192.168.1.199...
Connected to 192.168.1.199 (192.168.1.199).
Escape character is '^]'.
localhost (Linux release 2.6.18-274.18.1.el5 #1 SMP Thu Feb 9 12:45:44 EST 2012) (1)
login: root
Password:
Login incorrect
1.7.2 ssh(no)
1.7.3 scp(no)
1.7.4 wget****
wget:下载lrzsz安装包
[root@model sudoers.d]# wget https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz
--2019-04-21 12:27:17-- https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz
正在解析主机 ohse.de... 94.130.158.36
正在连接 ohse.de|94.130.158.36|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:280938 (274K) [application/x-gzip]
正在保存至: "lrzsz-0.12.20.tar.gz"
52% [=================================================================> ] 147,456 42.6K/s eta(英国中部时58% [=========================================================================> ] 163,840 37.8K/s eta(英国中部时69% [=======================================================================================> ] 196,608 42.0K/s eta(英国中部时75% [===============================================================================================> ] 212,992 41.9K/s eta(英国中部时81% [======================================================================================================> ] 229,376 38.6K/s eta(英国中部时93% [=========================================================================================================== ==========> ] 262,144 38.3K/s eta(英国中部时99% [============================================================================================================================> ] 278,528 36.5K/s eta(英国中部时100%[==============================================================================================================================>] 280,938 36.8K/s in 7.5s
2019-04-21 12:27:26 (36.8 KB/s) - 已保存 "lrzsz-0.12.20.tar.gz" [280938/280938])
[root@model sudoers.d]#
wget -b:后台下载,默认会输出日志(使用 tail -f wget-log)
[root@model sudoers.d]# wget -b https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz
继续在后台运行,pid 为 1949。
将把输出写入至 "wget-log"。
[root@model sudoers.d]# ll
总用量 280
-rw-r--r--. 1 root root 280938 12月 31 1998 lrzsz-0.12.20.tar.gz
-rw-r--r--. 1 root root 865 4月 21 12:32 wget-log
[root@model sudoers.d]#
wget -spider:测试下载的链接是否有效
[root@model sudoers.d]# wget --spider https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz
开启 Spider 模式。检查是否存在远程文件。
--2019-04-21 12:36:28-- https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz
正在解析主机 ohse.de... 94.130.158.36
正在连接 ohse.de|94.130.158.36|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:280938 (274K) [application/x-gzip]
存在远程文件。
[root@model sudoers.d]#
wget -i:下载多个链接
[root@model sudoers.d]# cat a.txt
https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz
ftp://ftp.vim.org/ftp/pub/vim/unix/vim-7.4.tar.bz2
[root@model sudoers.d]#
[root@model sudoers.d]# wget -i a.txt
--2019-04-21 12:41:25-- https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz
正在解析主机 ohse.de... 94.130.158.36
正在连接 ohse.de|94.130.158.36|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:280938 (274K) [application/x-gzip]
正在保存至: "lrzsz-0.12.20.tar.gz.1"
33% [=========================================> ] 95,011 25.3K/s eta(英国中部时40% [==================================================> ] 114,688 27.1K/s eta(英国中部时46% [============================================================================================================================> ] 278,528 22.5K/s eta(英国中部时100%[==============================================================================================================================>] 280,938 19.9K/s eta(英国中部时100%[==============================================================================================================================>] 280,938 19.9K/s in 14s
2019-04-21 12:41:42 (19.9 KB/s) - 已保存 "lrzsz-0.12.20.tar.gz.1" [280938/280938])
--2019-04-21 12:41:42-- ftp://ftp.vim.org/ftp/pub/vim/unix/vim-7.4.tar.bz2
=> "vim-7.4.tar.bz2"
正在解析主机 ftp.vim.org... 2001:67c:6ec:221:145:220:21:40, 145.220.21.40
正在连接 ftp.vim.org|2001:67c:6ec:221:145:220:21:40|:21... 已连接。
正在以 anonymous 登录 ... 登录成功!
==> SYST ... 完成。 ==> PWD ... 完成。
==> TYPE I ... 完成。 ==> CWD (1) /ftp/pub/vim/unix ... 完成。
==> SIZE vim-7.4.tar.bz2 ... 9843297
==> EPSV ... 完成。 ==> RETR vim-7.4.tar.bz2 ... 完成。
长度:9843297 (9.4M) (非正式数据)
1% [> ] 104,100 31.8K/s eta(英国中部时 1% ] 231,796 29.3K/s eta(英国中部时间) 5m 20s^C
[root@model sudoers.d]#
wget -c:断点续传
[root@model sudoers.d]# wget -c ftp://ftp.vim.org/ftp/pub/vim/unix/vim-7.4.tar.bz2
--2019-04-21 12:53:00-- ftp://ftp.vim.org/ftp/pub/vim/unix/vim-7.4.tar.bz2
=> "vim-7.4.tar.bz2"
正在解析主机 ftp.vim.org... 2001:67c:6ec:221:145:220:21:40, 145.220.21.40
正在连接 ftp.vim.org|2001:67c:6ec:221:145:220:21:40|:21... 已连接。
正在以 anonymous 登录 ... 登录成功!
==> SYST ... 完成。 ==> PWD ... 完成。
==> TYPE I ... 完成。 ==> CWD (1) /ftp/pub/vim/unix ... 完成。
==> SIZE vim-7.4.tar.bz2 ... 9843297
==> EPSV ... 完成。 ==> REST 235960 ... 完成。
==> RETR vim-7.4.tar.bz2 ... 完成。
长度:9843297 (9.4M),9607337 (9.2M) 字节剩余 (非正式数据)
3% [+++> ] 333,120 24.1K/s eta(英国中部时 3% [+++> ] 349,504 26.2K/s eta(英国中部时 3% [+++> ] 366,432 27.1K/s eta(英国中部时 3% [+++> ] 367,820 25.5K/s eta(英国中部时 3% [+++> ] 374,760 24.6K/s eta(英国中部时间) 6m 2s^C
[root@model sudoers.d]#
wget --limit-rate=300k:限速300K下载
[root@model sudoers.d]# wget --limit-rate=10k https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz
--2019-04-21 12:57:51-- https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz
正在解析主机 ohse.de... 94.130.158.36
正在连接 ohse.de|94.130.158.36|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:280938 (274K) [application/x-gzip]
正在保存至: "lrzsz-0.12.20.tar.gz.2"
11% [=============> ] 32,768 10.0K/s eta(英国中部时15% [==================> ] 43,008 10.0K/s eta(英国中部时19% [=======================> ] 53,619 [==========================================================> ] 131,072 10.0K/s eta(英国中部时50% [==============================================================> ] 141,312 10.0K/s eta(英国中部时52% [=================================================================> ] 147,456 10.0K/s eta(英国中部时间) 14s^C
[root@model sudoers.d]#
1.7.5 ping****
ping 192.168.43.200地址
-c num
要求返回的次数
-I 网卡
从指定网卡ping
-s 包大小
设定每一个包的大小
-t
设定每一个ttl的大小
[root@model sudoers.d]# ping 192.168.43.200
PING 192.168.43.200 (192.168.43.200) 56(84) bytes of data.
64 bytes from 192.168.43.200: icmp_seq=1 ttl=128 time=0.511 ms
64 bytes from 192.168.43.200: icmp_seq=2 ttl=128 time=0.613 ms
64 bytes from 192.168.43.200: icmp_seq=3 ttl=128 time=0.605 ms
^C
--- 192.168.43.200 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2459ms
rtt min/avg/max/mdev = 0.511/0.576/0.613/0.050 ms
[root@model sudoers.d]#
1.7.6 route(centos 6)****
route:查看路由
[root@model sudoers.d]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 eth1
192.168.43.0 * 255.255.255.0 U 0 0 0 eth0
link-local * 255.255.0.0 U 1002 0 0 eth0
link-local * 255.255.0.0 U 1003 0 0 eth1
default bogon 0.0.0.0 UG 0 0 0 eth0
route -n:直接显示数字形式的IP地址
[root@model sudoers.d]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.43.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1
0.0.0.0 192.168.43.1 0.0.0.0 UG 0 0 0 eth0
U
路由为启动
UG
表示此网关为一路由器
H
表示为主机路由
添加一条路由(192.168.43.1)
[root@model sudoers.d]# route add host 192.168.43.210 gw 192.168.43.1 dev eth0 主机路由(H)
[root@model sudoers.d]# route add -net 192.168.43.210 netmask 255.255.255.255 gw 192.168.43.1 dev eth0 网络路由(N)
[root@model sudoers.d]# route add default gw 192.168.43.1 添加一条默认路由
屏蔽一条已经添加的路由(192.168.1.1)
[root@model sudoers.d]# route add host 192.168.43.210 gw 192.168.43.1 dev eth0 reject 主机路由(H)
[root@model sudoers.d]# route add -net 192.168.43.210 netmask 255.255.255.255 gw 192.168.43.1 dev eth0 reject 网络路由(N)
[root@model sudoers.d]# route add default gw 192.168.43.1 reject 添加一条默认路由
删除路由
[root@model sudoers.d]# route del host 192.168.43.210 gw 192.168.43.1 dev eth0 主机路由(H)
[root@model sudoers.d]# route del -net 192.168.43.210 netmask 255.255.255.255 gw 192.168.43.1 dev eth0 网络路由(N)
[root@model sudoers.d]# route del default gw 192.168.43.1 添加一条默认路由
1.7.7 ifconfig(centos6)****
ifconfig:查看开机自启的网卡
[root@model sudoers.d]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:89:18:0B
inet addr:192.168.43.210 Bcast:192.168.43.255 Mask:255.255.255.0
inet6 addr: 2408:805f:e222:eefa:20c:29ff:fe89:180b/64 Scope:Global
inet6 addr: fe80::20c:29ff:fe89:180b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:107820 errors:0 dropped:0 overruns:0 frame:0
TX packets:116404 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:13020163 (12.4 MiB) TX bytes:12201465 (11.6 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:254 errors:0 dropped:0 overruns:0 frame:0
TX packets:254 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:982788 (959.7 KiB) TX bytes:982788 (959.7 KiB)
[root@model sudoers.d]#
ifconfig -a:查看所有的网卡
[root@model sudoers.d]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:0C:29:89:18:0B
inet addr:192.168.43.210 Bcast:192.168.43.255 Mask:255.255.255.0
inet6 addr: 2408:805f:e222:eefa:20c:29ff:fe89:180b/64 Scope:Global
inet6 addr: fe80::20c:29ff:fe89:180b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:107833 errors:0 dropped:0 overruns:0 frame:0
TX packets:116413 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:13021219 (12.4 MiB) TX bytes:12203289 (11.6 MiB)
eth1 Link encap:Ethernet HWaddr 00:0C:29:89:18:15
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:367 errors:0 dropped:0 overruns:0 frame:0
TX packets:11 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:44019 (42.9 KiB) TX bytes:766 (766.0 b)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:254 errors:0 dropped:0 overruns:0 frame:0
TX packets:254 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:982788 (959.7 KiB) TX bytes:982788 (959.7 KiB)
[root@model sudoers.d]#
查找eth0的网卡信息
[root@model sudoers.d]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:89:18:0B
inet addr:192.168.43.210 Bcast:192.168.43.255 Mask:255.255.255.0
inet6 addr: 2408:805f:e222:eefa:20c:29ff:fe89:180b/64 Scope:Global
inet6 addr: fe80::20c:29ff:fe89:180b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:107849 errors:0 dropped:0 overruns:0 frame:0
TX packets:116422 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:13022547 (12.4 MiB) TX bytes:12205603 (11.6 MiB)
[root@model sudoers.d]#
1.7.8 ifup(centos6,7)****
ifup:只适用于centos 6版本:启动单个网卡
[root@model sudoers.d]# ifup eth1
Determining if ip address 192.168.1.197 is already in use for device eth1...
[root@model sudoers.d]#
1.7.9 ifdown(centos6,7)****
ifdown:只适用于centos 6版本:启关闭单个网卡
[root@model sudoers.d]# ifdown eth1
[root@model sudoers.d]#
1.7.10 netstat(centos6)****
netstat -anptu
- a All,显示全部的信息
- n 直接使用IP地址,不使用域名服务器
- p 程序名称
- t 显示tcp端口的传输信息
- u 显示udp端口的传输信息
- l Licence:显示监听端口
-
c 持续输出netstat信息(1秒)
[root@model sudoers.d]# netstat -anptulc
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1280/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1360/master
tcp 0 0 192.168.43.210:22 192.168.43.200:52229 ESTABLISHED 1649/sshd
tcp 0 0 :::22 :::* LISTEN 1280/sshd
tcp 0 0 ::1:25 :::* LISTEN 1360/master
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1280/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1360/master
tcp 0 0 192.168.43.210:22 192.168.43.200:52229 ESTABLISHED 1649/sshd
tcp 0 0 :::22 :::* LISTEN 1280/sshd
tcp 0 0 ::1:25 :::* LISTEN 1360/master
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1280/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1360/master
tcp 0 0 192.168.43.210:22 192.168.43.200:52229 ESTABLISHED 1649/sshd
tcp 0 0 :::22 :::* LISTEN 1280/sshd
tcp 0 0 ::1:25 :::* LISTEN 1360/master
^C
[root@model sudoers.d]#
netstat -rn(相当于route -n):查看路由
[root@model sudoers.d]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.43.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.43.1 0.0.0.0 UG 0 0 0 eth0
netstat -ie(相当于ifconfig):查看网卡信息
[root@model sudoers.d]# netstat -ie
Kernel Interface table
eth0 Link encap:Ethernet HWaddr 00:0C:29:89:18:0B
inet addr:192.168.43.210 Bcast:192.168.43.255 Mask:255.255.255.0
inet6 addr: 2408:805f:e222:eefa:20c:29ff:fe89:180b/64 Scope:Global
inet6 addr: fe80::20c:29ff:fe89:180b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:108250 errors:0 dropped:0 overruns:0 frame:0
TX packets:116700 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:13057114 (12.4 MiB) TX bytes:12258698 (11.6 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:254 errors:0 dropped:0 overruns:0 frame:0
TX packets:254 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:982788 (959.7 KiB) TX bytes:982788 (959.7 KiB)
[root@model sudoers.d]#
1.7.11 ss(centos7)
ss -anptu:(相当于netstat,但是查询速度比netstat较快)
- a All,显示全部的信息
- n 直接使用IP地址,不使用域名服务器
- p 程序名称
- t 显示tcp端口的传输信息
- u 显示udp端口的传输信息
[root@model sudoers.d]# ss -aputn
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 128 :::22 :::* users:(("sshd",1280,4))
tcp LISTEN 0 128 *:22 *:* users:(("sshd",1280,3))
tcp LISTEN 0 100 ::1:25 :::* users:(("master",1360,13))
tcp LISTEN 0 100 127.0.0.1:25 *:* users:(("master",1360,12))
tcp ESTAB 0 52 192.168.43.210:22 192.168.43.200:52229 users:(("sshd",1649,3))
[root@model sudoers.d]#
1.7.12 ip route(centos 7)****
ip route:查看路由
[root@oldboyedu ~]# ip route show
default via 10.0.0.254 dev eth0 proto static metric 100
10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.200 metric 100
添加一条路由
[root@oldboyedu ~]# ip route add 10.0.0.0/24 via 10.0.0.254 dev eth0
删除一条路由
[root@oldboyedu ~]# ip route del 10.0.0.0/24
1.7.13 ip addr:(centos7)*****
查看IP地址:ip addr show
[root@oldboyedu ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:16:07:30 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.200/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::b736:dc22:2ec6:1b47/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@oldboyedu ~]#
查看指定IP地址:ip addr show interface
[root@oldboyedu ~]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:16:07:30 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.200/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::b736:dc22:2ec6:1b47/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@oldboyedu ~]#
1.7.14
1.8 深入网络操作命令
1.8.1 nmap
nmap命令: 一款开放源代码的网络探测和安全审核工具
[root@oldboyedu ~]# nmap www.baidu.com
Starting Nmap 6.40 ( http://nmap.org ) at 2019-09-06 10:15 CST
[root@oldboyedu ~]#
nmap -sn:查看10.0.0.0/24位主机里面的所有IP和mac地址
[root@oldboyedu ~]# nmap -sn 10.0.0.0/24
Starting Nmap 6.40 ( http://nmap.org ) at 2019-09-06 10:27 CST
Nmap scan report for 10.0.0.1
Host is up (0.00019s latency).
MAC Address: 00:50:56:C0:00:08 (VMware)
Nmap scan report for 10.0.0.254
Host is up (0.000086s latency).
MAC Address: 00:50:56:E9:AC:6B (VMware)
Nmap scan report for 10.0.0.200
Host is up.
Nmap done: 256 IP addresses (3 hosts up) scanned in 2.33 seconds
[root@oldboyedu ~]#
1.8.2 lsof
lsof:查看打开的进程文件
[root@oldboyedu ~]# lsof
COMMAND PID TID USER FD TYPE DEVICE SIZE/OFF NODE NAME
systemd 1 root cwd DIR 8,3 4096 64 /
systemd 1 root rtd DIR 8,3 4096 64 /
systemd 1 root txt REG 8,3 1616360 410278 /usr/lib/systemd/systemd
systemd 1 root mem REG 8,3 20112 84983 /usr/lib64/libuuid.so.1.3.0
lsof -i TCP:只显示TCP的连接
[root@oldboyedu ~]# lsof -i TCP
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 7389 root 3u IPv4 40544 0t0 TCP *:ssh (LISTEN)
sshd 7389 root 4u IPv6 40553 0t0 TCP *:ssh (LISTEN)
master 7547 root 13u IPv4 41145 0t0 TCP localhost:smtp (LISTEN)
master 7547 root 14u IPv6 41146 0t0 TCP localhost:smtp (LISTEN)
sshd 7761 root 3u IPv4 45009 0t0 TCP oldboyedu.com:ssh->10.0.0.1:59778 (ESTABLISHED)
[root@oldboyedu ~]#
lsof -i :port:查询端口为(port)的网络信息
[root@oldboyedu ~]# lsof -i :22
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 7389 root 3u IPv4 40544 0t0 TCP *:ssh (LISTEN)
sshd 7389 root 4u IPv6 40553 0t0 TCP *:ssh (LISTEN)
sshd 7761 root 3u IPv4 45009 0t0 TCP oldboyedu.com:ssh->10.0.0.1:59778 (ESTABLISHED)
[root@oldboyedu ~]#
lsof -i@IP地址:指定某个主机的连接是否成功
[root@oldboyedu ~]# lsof -i@10.0.0.200
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 7761 root 3u IPv4 45009 0t0 TCP oldboyedu.com:ssh->10.0.0.1:59778 (ESTABLISHED)
[root@oldboyedu ~]# lsof -i@192.168.21.109
[root@oldboyedu ~]# lsof -i@192.168.21.109
[root@oldboyedu ~]# lsof -i@192.168.21.109
[root@oldboyedu ~]#
lsof | grep "EST*":查找以EST为首字母的进程信息
[root@oldboyedu ~]# lsof | grep "EST*"
abrtd 6329 root mem REG 8,3 546 201865084 /usr/share/locale/en_US/LC_MESSAGES/abrt.mo
abrt-watc 6330 root mem REG 8,3 546 201865084 /usr/share/locale/en_US/LC_MESSAGES/abrt.mo
sshd 7761 root 3u IPv4 45009 0t0 TCP oldboyedu.com:ssh->10.0.0.1:59778 (ESTABLISHED)
[root@oldboyedu ~]#
1.8.3 mail(后续整理)
mail:电子邮件的接收和发送命令
1.8.4 mutt(后续整理)
1.8.5 nslookup
安装: yum install bind-utils -y
nslookup:查看域名服务器的程序(非交互模式)
[root@oldboyedu ~]# nslookup baidu.com
Server: 223.5.5.5
Address: 223.5.5.5#53
Non-authoritative answer:
Name: baidu.com
Address: 39.156.69.79
Name: baidu.com
Address: 220.181.38.148
nslookup:查看域名服务器的程序(交互模式)
[root@oldboyedu ~]# nslookup
> baidu.com
Server: 223.5.5.5
Address: 223.5.5.5#53
Non-authoritative answer:
Name: baidu.com
Address: 39.156.69.79
Name: baidu.com
Address: 220.181.38.148
> qq.com
Server: 223.5.5.5
Address: 223.5.5.5#53
Non-authoritative answer:
Name: qq.com
Address: 111.161.64.48
Name: qq.com
Address: 111.161.64.40
1.8.6 dig(后续整理)
dig dns 查询样式
dig dns
[root@oldboyedu ~]# dig baidu.com
; <<>> DiG 9.9.4-RedHat-9.9.4-74.el7_6.2 <<>> baidu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47861
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;baidu.com. IN A
;; ANSWER SECTION:
baidu.com. 15 IN A 39.156.69.79
baidu.com. 15 IN A 220.181.38.148
;; Query time: 30 msec
;; SERVER: 223.5.5.5#53(223.5.5.5)
;; WHEN: Fri Sep 06 11:30:36 CST 2019
;; MSG SIZE rcvd: 59
1.8.7 host
host:查询的DNS地址,转换主机名称的主机名为IP地址
host DNS:查询DNS
[root@oldboyedu ~]# host baidu.com
baidu.com has address 39.156.69.79
baidu.com has address 220.181.38.148
baidu.com mail is handled by 20 mx50.baidu.com.
baidu.com mail is handled by 20 mx1.baidu.com.
baidu.com mail is handled by 20 jpmx.baidu.com.
baidu.com mail is handled by 15 mx.n.shifen.com.
baidu.com mail is handled by 10 mx.maillb.baidu.com.
[root@oldboyedu ~]#
host -a DNS:详细列出DNS信息
[root@oldboyedu ~]# host -a baidu.com
Trying "baidu.com"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56447
;; flags: qr rd ra; QUERY: 1, ANSWER: 12, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;baidu.com. IN ANY
;; ANSWER SECTION:
baidu.com. 503 IN MX 20 mx1.baidu.com.
baidu.com. 503 IN MX 20 jpmx.baidu.com.
baidu.com. 503 IN MX 20 mx50.baidu.com.
baidu.com. 503 IN MX 10 mx.maillb.baidu.com.
baidu.com. 503 IN MX 15 mx.n.shifen.com.
baidu.com. 503 IN A 220.181.38.148
baidu.com. 503 IN A 39.156.69.79
baidu.com. 503 IN NS ns2.baidu.com.
baidu.com. 503 IN NS dns.baidu.com.
baidu.com. 503 IN NS ns3.baidu.com.
baidu.com. 503 IN NS ns4.baidu.com.
baidu.com. 503 IN NS ns7.baidu.com.
Received 265 bytes from 223.5.5.5#53 in 68 ms
[root@oldboyedu ~]#
1.8.8 traceroute
traceroute:追踪数据包的路由途径
[root@oldboyedu ~]# traceroute baidu.com
traceroute to baidu.com (220.181.38.148), 30 hops max, 60 byte packets
1 gateway (10.0.0.254) 0.140 ms 0.092 ms 0.109 ms
2 * * *
3 * * *
traceroute -m 10:将跳数设置为10次
[root@oldboyedu ~]# traceroute -m 10 baidu.com
traceroute to baidu.com (39.156.69.79), 10 hops max, 60 byte packets
1 gateway (10.0.0.254) 0.157 ms 0.086 ms 0.062 ms
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
traceroute -n :显示IP地址不显示主机名
[root@oldboyedu ~]# traceroute -n baidu.com
traceroute to baidu.com (220.181.38.148), 30 hops max, 60 byte packets
1 10.0.0.254 0.086 ms 0.066 ms 0.060 ms
7 * * *
8 * * *
9 * * *
traceroute -p 6888 baidu.com :探测包使用的基本UDP端口设置6888
[root@oldboyedu ~]# traceroute -p 6888 baidu.com
traceroute to baidu.com (220.181.38.148), 30 hops max, 60 byte packets
1 gateway (10.0.0.254) 0.322 ms 0.203 ms 0.203 ms
2 * * *
3 * * *
4 * * *
5 * * *
[root@oldboyedu ~]#
1.8.9 tcpdump(后续整理)
1.9 有关磁盘与文件系统的命令
1.9.1 mount****
mount:磁盘存储设备挂载命令
[root@oldboy6666 ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@oldboy6666 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 99G 1.7G 97G 2% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 197M 105M 93M 54% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /mnt
[root@oldboy6666 ~]#
1.9.2 umount****
umount:磁盘设备卸载命令
[root@oldboy6666 ~]# umount /mnt
[root@oldboy6666 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 99G 1.7G 97G 2% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 197M 105M 93M 54% /boot
tmpfs 98M 0 98M 0% /run/user/0
[root@oldboy6666 ~]#
1.9.3 fsck
fsck:用于检查试图修复文件中的错误
fsck -y:用于检查指定硬盘的错误,检查完毕就可以reboot重启
[root@oldboy6666 ~] # fsck -y /dev/sda3
fsck from util-linux 2.23.2
/sbin/fsck.xfs: XFS file system.
[root@oldboy6666 ~] #
fsck -a:自动修复文件,不进行任何提示
[root@oldboy6666 ~] # fsck -a /dev/sda3
fsck from util-linux 2.23.2
/sbin/fsck.xfs: XFS file system.
[root@oldboy6666 ~] #
fsck -r :互动方式检查
[root@oldboy6666 ~] # fsck -r /dev/sda3
fsck from util-linux 2.23.2
If you wish to check the consistency of an XFS filesystem or
repair a damaged filesystem, see xfs_repair(8).
/dev/sda3: status 0, rss 1464, real 0.001992, user 0.001653, sys 0.000000
[root@oldboy6666 ~] #
1.9.4 dd****
dd:用于复制文件对源文件的格式进行转换和格式化的处理
[root@oldboy6666 ~] # dd if=/dev/zero of=sun.txt bs=1b count=10000
10000+0 records in
10000+0 records out
5120000 bytes (5.1 MB) copied, 0.0259372 s, 197 MB/s
[root@oldboy6666 ~] # du -sh sun.txt
4.9M sun.txt
[root@oldboy6666 ~] #
参数解释
- if 输入的设备文件(从黑洞中拿出来多少信息)
- of 输出的文件(将这些信息放到硬盘什么地方)
- bs 每个块的大小(每次取出来多少)
-
count 一共有多少块(一共取多少次)
1.9.5 dumpe2fs(centos 6)
dumpe2fs:用于打印文件系统的快组信息
[root@oldboyedu ~] # dumpe2fs /dev/sda1
dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: /boot
Filesystem UUID: 0dc58de8-08a7-46dd-af2d-668a34a440cc
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 51200
Block count: 204800
Reserved block count: 10240
Free blocks: 167150
Free inodes: 51162
First block: 1
Block size: 1024
Fragment size: 1024
Reserved GDT blocks: 256
Blocks per group: 8192
Fragments per group: 8192
Inodes per group: 2048
Inode blocks per group: 256
Flex block group size: 16
Filesystem created: Mon Sep 9 22:07:07 2019
Last mount time: Sat Sep 14 23:32:06 2019
Last write time: Sat Sep 14 23:32:06 2019
Mount count: 12
Maximum mount count: -1
Last checked: Mon Sep 9 22:07:07 2019
Check interval: 0 (<none>)
Lifetime writes: 36 MB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 128
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: de2e40af-8694-4d07-be95-bfd80a33b5d5
Journal backup: inode blocks
Journal features: (none)
Journal size: 4096k
Journal length: 4096
Journal sequence: 0x0000001a
Journal start: 0
1.9.6 dump(后续整理)
1.9.7 fdisk********
- d delete a partition 删除一个分区
- g create a new empty GPT partition table 创建一个新的GPT分区表(默认dos)
- l list known partition types 列出已知的分区类型
- m print this menu 列出帮助菜单
- n add a new partition 添加一个新的分区
- p print the partition table 打印分区表
- q quit without saving changes 退出不保存
- t change a partition's system id 改变一个分区的系统ID
-
w write table to disk and exit 保存并且退出
fdisk分区的方式
[root@oldboyedu scripts] # fdisk /dev/sdb 开始磁盘分区
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x12ca22cf.
Command (m for help): n 创建一个新的分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1 开始分第一个主分区
First sector (2048-2097151, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +100M 第一个主分区分100M
Partition 1 of type Linux and of size 100 MiB is set
Command (m for help): n 再次创建新的主分区
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2): 2 开始分第二个分区
First sector (206848-2097151, default 206848):
Using default value 206848
Last sector, +sectors or +size{K,M,G} (206848-2097151, default 2097151): +100M 第二个主分区分100M
Partition 2 of type Linux and of size 100 MiB is set
Command (m for help):
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0x12ca22cf
Device Boot Start End Blocks Id System
/dev/sdb1 2048 206847 102400 83 Linux 查看分的2个主分区
/dev/sdb2 206848 411647 102400 83 Linux
Command (m for help):
Command (m for help):
….
继续分区…………..
1.9.8 parted*****
- mklabel,mktable LABEL-TYPE 创建分区表的类型
- mkpart PART-TYPE [FS-TYPE] START END 创建主分区并且设置类型其实和终点
- print [devices|free|list,all|NUMBER] 查看分区信息
- quit 退出,并且会自动保存
-
rm NUMBER 删除分区(以ID代表)
parted分区方式
[root@oldboyedu ~] # parted /dev/sdc 使用parted开始分区
GNU Parted 3.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt 修改分区类型为GPT
Warning: The existing disk label on /dev/sdc will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) p 查看当前是否有分区信息
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 3221GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
(parted) mkpart primary xfs 0 2500G 创建一个文件系统为xfs的并且大小为2500G的分区
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I
(parted) p 分区创建成功
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 3221GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 2500GB 2500GB primary
(parted) q 保存与退出
Information: You may need to update /etc/fstab.
[root@oldboyedu ~] # mkfs.xfs /dev/sdc1 格式化分区
meta-data=/dev/sdc1 isize=512 agcount=4, agsize=152587890 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=610351558, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=298023, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
You have new mail in /var/spool/mail/root
[root@oldboyedu ~] # mount /dev/sdc1 /mnt/ 挂载分区
[root@oldboyedu ~] # df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 99G 5.2G 94G 6% /
devtmpfs 471M 0 471M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 8.4M 478M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 197M 160M 37M 82% /boot
tmpfs 98M 12K 98M 1% /run/user/42
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdc1 2.3T 33M 2.3T 1% /mnt 查看创建的分区是否挂载成功并且分区大小一致
[root@oldboyedu ~] #
1.9.9 mkfs*****
centos6将xfs改成ext4则可
[root@oldboyedu ~] # mkfs.xfs /dev/sdc1 格式化分区,不使用参数的方法
meta-data=/dev/sdc1 isize=512 agcount=4, agsize=152587890 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=610351558, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=298023, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
You have new mail in /var/spool/mail/root
[root@oldboyedu ~] # mkfs -t xfs /dev/sdc1 格式化分区,使用参数-t的方法
meta-data=/dev/sdc1 isize=512 agcount=4, agsize=152587890 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=610351558, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=298023, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
You have new mail in /var/spool/mail/root
1.9.10 partprobe(后续整理)
1.9.11 e2fsck(后续整理)
1.9.12 mkswap******
[root@oldboyedu mnt] # dd if=/dev/zero of=/tmp/1G bs=100M count=10
从黑洞中拿出来1G交给/tmp/1G使用
10+0 records in
10+0 records out
1048576000 bytes (1.0 GB) copied, 3.58782 s, 292 MB/s
[root@oldboyedu mnt] # ll -h /tmp/1G
-rw-r--r-- 1 root root 1000M Oct 5 15:26 /tmp/1G
[root@oldboyedu mnt] #
标记给swap空间
[root@oldboyedu mnt] # mkswap /tmp/1G 标记给swap空间
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=8eea78e2-8f88-4c77-89a4-9910047d1983
[root@oldboyedu mnt] #
1.9.13 swapon******
[root@oldboyedu mnt] # free -h
total used free shared buff/cache available
Mem: 972M 343M 154M 10M 473M 436M
Swap: 1.5G 0B 1.5G 空闲1.5G
You have new mail in /var/spool/mail/root
[root@oldboyedu mnt] # swap
swaplabel swapoff swapon
[root@oldboyedu mnt] # swapon /tmp/1G 增加1G
swapon: /tmp/1G: insecure permissions 0644, 0600 suggested.
[root@oldboyedu mnt] # free -h
total used free shared buff/cache available
Mem: 972M 344M 153M 10M 474M 435M
Swap: 2.5G 0B 2.5G 空闲2.5G
[root@oldboyedu mnt] #
1.9.14 swapoff*****
[root@oldboyedu mnt] # free -h
total used free shared buff/cache available
Mem: 972M 344M 153M 10M 474M 435M
Swap: 2.5G 0B 2.5G 空闲2.5G
[root@oldboyedu mnt] # swapoff /tmp/1G 增加1G
You have new mail in /var/spool/mail/root
[root@oldboyedu mnt] # free -h
total used free shared buff/cache available
Mem: 972M 344M 154M 10M 474M 436M
Swap: 1.5G 0B 1.5G 空闲1.5G
[root@oldboyedu mnt] #
1.9.15 sync(后续整理)
1.9.16 resize2fs(后续整理)
1.9.17 blkid****
blkid:查看磁盘的UUID
[root@oldboy6666 ~]# blkid /dev/cdrom
/dev/cdrom: UUID="2018-11-25-23-54-16-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
[root@oldboy6666 ~]#
1.10 系统权限及用户授权相关命令
1.10.1 chmod*******
chmod命令单个来修改权限
(1) u+r:修改单个用户的属主读权限
[root@oldboyedu oldboy02] # chmod a=- aa.txt
[root@oldboyedu oldboy02] # ll
total 0
d--------- 2 root root 6 Oct 1 20:00 aa.txt
[root@oldboyedu oldboy02] # chmod u+r aa.txt
[root@oldboyedu oldboy02] # ll
total 0
dr-------- 2 root root 6 Oct 1 20:00 aa.txt
[root@oldboyedu oldboy02] #
(2) u+w:修改单个用户的属主写权限
[root@oldboyedu oldboy02] # chmod u+w aa.txt
[root@oldboyedu oldboy02] # ll
total 0
drw------- 2 root root 6 Oct 1 20:00 aa.txt
[root@oldboyedu oldboy02] #
(3) u+x:修改单个用户的属主执行权限
[root@oldboyedu oldboy02] # chmod u+x aa.txt
[root@oldboyedu oldboy02] # ll
total 0
drwx------ 2 root root 6 Oct 1 20:00 aa.txt
[root@oldboyedu oldboy02] #
同样:g(group):代表用户的属组
o(other):代表其他用户
chmod命令批量修改权限
(1).利用数值进行修改
[root@oldboyedu oldboy02] # chmod 777 aa.txt 将aa.txt属主,属组,其他全部修改成777
[root@oldboyedu oldboy02] # ll
total 0
drwxrwxrwx 2 root root 6 Oct 1 20:00 aa.txt
[root@oldboyedu oldboy02] #
(2).利用符号a进行修改
[root@oldboyedu oldboy02] # chmod a=rwx aa.txt 将aa.txt属主,属组,其他全部修改成777
[root@oldboyedu oldboy02] # ll
total 0
drwxrwxrwx 2 root root 6 Oct 1 20:00 aa.txt
[root@oldboyedu oldboy02] #
(3).利用-R遍历修改
[root@oldboyedu oldboy02] # chmod -R 777 aa 将aa/bb/cc.txt全部修改成权限777
[root@oldboyedu oldboy02] # ll aa
total 0
drwxrwxrwx 3 root root 20 Oct 1 20:08 bb
[root@oldboyedu oldboy02] # cd bb
-bash: cd: bb: No such file or directory
[root@oldboyedu oldboy02] # cd aa/bb
[root@oldboyedu bb] # ll
total 0
drwxrwxrwx 2 root root 6 Oct 1 20:08 cc.txt
[root@oldboyedu bb] #
1.10.2 chown*******
chown命令修改权限
(1).属主信息
[root@oldboyedu oldboy02] # chown oldboy01 aa.txt 将属主更换成oldboy01
[root@oldboyedu oldboy02] # ll
total 0
drwxrwxrwx 3 root root 16 Oct 1 20:08 aa
d--------- 2 oldboy01 root 6 Oct 1 20:00 aa.txt
[root@oldboyedu oldboy02] #
(2).属组信息
[root@oldboyedu oldboy02] # chown .oldboy01 aa.txt 将属组更换成oldboy01(.oldboy01)
[root@oldboyedu oldboy02] # l
bash: l: command not found...
[root@oldboyedu oldboy02] # ll
total 0
drwxrwxrwx 3 root root 16 Oct 1 20:08 aa
d--------- 2 oldboy01 oldboy01 6 Oct 1 20:00 aa.txt
[root@oldboyedu oldboy02] #
(3).全部信息
drwxrwxrwx 3 root root 16 Oct 1 20:08 aa
d--------- 2 oldboy01 oldboy01 6 Oct 1 20:00 aa.txt
[root@oldboyedu oldboy02] # chown root.root aa.txt 将属主和属组都更换成root
[root@oldboyedu oldboy02] # ll
total 0
drwxrwxrwx 3 root root 16 Oct 1 20:08 aa
d--------- 2 root root 6 Oct 1 20:00 aa.txt
[root@oldboyedu oldboy02]
[root@oldboyedu oldboy02] # ll
total 0
drwxrwxrwx 3 root root 16 Oct 1 20:08 aa
d--------- 2 root root 6 Oct 1 20:00 aa.txt
[root@oldboyedu oldboy02] # chown oldboy01. aa.txt 将属主和属组都更换成oldboy01
[root@oldboyedu oldboy02] # ll
total 0
drwxrwxrwx 3 root root 16 Oct 1 20:08 aa
d--------- 2 oldboy01 oldboy01 6 Oct 1 20:00 aa.txt
[root@oldboyedu oldboy02] #
(4).属主.属组遍历(-R)
[root@oldboyedu oldboy02] # chown -R oldboy01. aa 将aa目录下面的所有文件和目录都更换成 oldboy01的属主和属组
[root@oldboyedu oldboy02] # ll
total 0
drwxrwxrwx 3 oldboy01 oldboy01 16 Oct 1 20:08 aa
d--------- 2 oldboy01 oldboy01 6 Oct 1 20:00 aa.txt
[root@oldboyedu oldboy02] # ll -d aa/bb
drwxrwxrwx 3 oldboy01 oldboy01 20 Oct 1 20:08 aa/bb
[root@oldboyedu oldboy02] # ll aa/bb/cc.txt
total 0
[root@oldboyedu oldboy02] # cd aa/bb/cc.txt
[root@oldboyedu cc.txt] # ll
total 0
[root@oldboyedu cc.txt] # ls
[root@oldboyedu cc.txt] # cd ..
[root@oldboyedu bb] # ls
cc.txt
[root@oldboyedu bb] # ll
total 0
drwxrwxrwx 2 oldboy01 oldboy01 6 Oct 1 20:08 cc.txt
[root@oldboyedu bb] #
1.10.3 chgrp
- -c 效果类似"-v"参数,但仅回报更改的部分;
- -f或–quiet 不显示错误信息;
- -h 只对符号连接的文件作修改,而不是该其他任何相关文件;
- -R 递归处理,将指令目录下的所有文件及子目录一并处理;
- -v 显示指令执行过程;
-
–reference 把指定文件或目录的所属群组全部设成和参考文件或目录
的所属群组相同;
将bb.txt文件的属组用户更改为oldboy10
[root@oldboyedu ~] # ll
total 0
dr--r--r-- 2 root root 6 Sep 29 17:05 bb
-r--r--r-- 1 root root 0 Sep 29 17:05 bb.txt
[root@oldboyedu ~] # chgrp oldboy10 bb.txt
[root@oldboyedu ~] # ll
total 0
dr--r--r-- 2 root root 6 Sep 29 17:05 bb
-r--r--r-- 1 root oldboy10 0 Sep 29 17:05 bb.txt
[root@oldboyedu ~] #
1.10.4 umask******
umask值的查看
[root@oldboyedu /] # umask
0022
[root@oldboyedu /] #
uamsk的修改
umask的临时修改
[root@oldboyedu /] # umask 000 将umask值修改为000
[root@oldboyedu /] # touch aa.txt
[root@oldboyedu /] # ll aa.txt
-rw-rw-rw- 1 root root 0 Sep 29 16:58 aa.txt 查看文件umask值发现是666
[root@oldboyedu /] #
[root@oldboyedu /] # mkdir aa
[root@oldboyedu /] # ll aa
total 0
[root@oldboyedu /] # ll aa -d
drwxrwxrwx 2 root root 6 Sep 29 17:00 aa 查看目录umask值为777
[root@oldboyedu /] #
[root@oldboyedu ~] # umask 333 将umask改为333
[root@oldboyedu ~] # rm aa.txt
rm: cannot remove 'aa.txt': No such file or directory
[root@oldboyedu ~] # touch aa.txt
[root@oldboyedu ~] # ll aa.txt
-r--r--r-- 1 root root 0 Sep 29 17:05 aa.txt 文件权限为444
[root@oldboyedu ~] # mkdir bb
[root@oldboyedu ~] # ll -d bb
dr--r--r-- 2 root root 6 Sep 29 17:05 bb 目录权限为444
[root@oldboyedu ~] #
文件权限umaks为333的时候,为什么创建出来的文件默认权限为444?
文件默认权限创建出来为奇数的时候回默认加1(333)+(111)=(444)
umask的永久修改
在/etc/profile文件中查找出if判断语句
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
umask 002
else
umask 022
fi
if判断语句的说明
- $UID 得到当前用户的ID值
- -gn 代表用户组的ID和名称
-
-un 代表用户的ID和名称
1.11 查看系统用户登陆信息的命令
1.11.1 whoami****
whoami:查看当前登陆的用户
[root@oldboy6666 ~] # whoami
root
[root@oldboy6666 ~]
1.11.2 who****
who:显示目前用户登陆的信息(这个信息是以终端开启为主的,目前开了1个)
[root@oldboy6666 ~] # who
root pts/0 2019-09-14 15:35 (10.0.0.1)
1.11.3 w***
w:用于登陆系统的用户信息
[root@oldboy6666 ~] # w
18:08:21 up 9:30, 3 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 10.0.0.1 17:11 5.00s 0.08s 0.03s w
root pts/3 10.0.0.1 15:11 57:33 0.04s 0.04s -bash
root pts/4 10.0.0.1 15:00 57:41 0.38s 0.28s -bash
[root@oldboy6666 ~] #
- USER 目前登陆的用户
- TTY 连接用户的方式为远程连接
- FROM 从哪台机器登陆的
- LOGIN@ 几点开始连接服务器的
- IDLE 目前连接了多长时间
- JCPU/PCPU cpu的使用率
-
WHAT 终端目前正在操作什么
1.11.4 last****
last:显示用户最近登陆的信息(-n)
[root@oldboy6666 ~] # last -10
root pts/1 10.0.0.1 Sat Sep 14 16:55 - 16:58 (00:03)
root pts/0 10.0.0.1 Sat Sep 14 15:35 still logged in
reboot system boot 3.10.0-957.el7.x Sat Sep 14 15:34 - 17:00 (01:26)
root pts/0 10.0.0.1 Thu Sep 12 16:55 - down (00:45)
root pts/0 10.0.0.1 Thu Sep 12 16:00 - 16:55 (00:55)
root pts/0 10.0.0.1 Thu Sep 12 11:05 - 16:00 (04:54)
root pts/0 10.0.0.1 Thu Sep 12 11:05 - 11:05 (00:00)
root pts/0 10.0.0.1 Thu Sep 12 10:42 - 11:05 (00:22)
reboot system boot 3.10.0-957.el7.x Thu Sep 12 10:42 - 17:41 (06:59)
root pts/0 10.0.0.1 Thu Sep 12 10:28 - down (00:13)
wtmp begins Fri Aug 30 12:29:17 2019
[root@oldboy6666 ~] #
last -x +命令:输出最近执行命令的信息
[root@oldboy6666 ~] # last -x reboot -n 2
reboot system boot 3.10.0-957.el7.x Sat Sep 14 15:34 - 17:05 (01:31)
reboot system boot 3.10.0-957.el7.x Thu Sep 12 10:42 - 17:41 (06:59)
wtmp begins Fri Aug 30 12:29:17 2019
[root@oldboy6666 ~] #
1.11.5 lastlog********
lastlog:用于显示最近所有登陆用户信息记录
[root@oldboy6666 ~] # lastlog
Username Port From Latest
root pts/1 10.0.0.1 Sat Sep 14 16:55:14 +0800 2019
bin **Never logged in**
daemon **Never logged in**
adm **Never logged in**
lp **Never logged in**
sync **Never logged in**
shutdown **Never logged in**
halt **Never logged in**
mail **Never logged in**
operator **Never logged in**
games **Never logged in**
ftp **Never logged in**
nobody **Never logged in**
systemd-network **Never logged in**
dbus **Never logged in**
polkitd **Never logged in**
tss **Never logged in**
abrt **Never logged in**
sshd **Never logged in**
postfix **Never logged in**
chrony **Never logged in**
apache **Never logged in**
oldboy01 **Never logged in**
oldboy02 **Never logged in**
oldboy03 **Never logged in**
oldboy04 **Never logged in**
oldboy05 **Never logged in**
oldboy06 **Never logged in**
oldboy07 **Never logged in**
oldboy08 **Never logged in**
oldboy09 **Never logged in**
oldboy10 **Never logged in**
ntp **Never logged in**
[root@oldboy6666 ~] #
1.11.6 users
users: 用于显示当前登录系统所有的用户的用户列表
[root@oldboy6666 ~] # users
root
1.11.7 finger
finger:显示用户的登陆信息(包括帐号名称,真实姓名,登入终端机)
[root@oldboy6666 ~] # finger
Login Name Tty Idle Login Time Office Office Phone Host
root root pts/0 Sep 14 15:35 (10.0.0.1)
root root pts/1 27 Sep 14 17:10 (10.0.0.1)
[root@oldboy6666 ~] #
1.12 内置命令及其它
1.12.1 echo*****
echo:将信息输入到屏幕上
[root@oldboy6666 ~]# echo "aa"
aa
[root@oldboy6666 ~]#
标准输出重定向
[root@oldboy6666 ~]# echo "aa" > 2.txt
[root@oldboy6666 ~]# cat 2.txt
aa
[root@oldboy6666 ~]#
标准追加输出重定向
[root@oldboy6666 ~]# echo "bb" >> 2.txt
[root@oldboy6666 ~]# cat 2.txt
aa
bb
[root@oldboy6666 ~]#
echo -e:可以支持控制字符
-n:输出内容后不会在下一行切换
[root@oldboy6666 scripts] # echo -n "c.biancheng.net"
c.biancheng.net[root@oldboy6666 scripts] #
错误输出重定向
[root@oldboy6666 scripts] # ech 111 2> error.log
[root@oldboy6666 scripts] # cat error.log
-bash: ech: command not found
错误追加输出重定向
[root@oldboy6666 scripts] # ech 222 2>> error.log
[root@oldboy6666 scripts] # cat error.log
-bash: ech: command not found
-bash: ech: command not found
生成序列
[root@oldboy6666 oldboy] # echo {01..10}
01 02 03 04 05 06 07 08 09 10
[root@oldboy6666 oldboy] #
1.12.2 printf
进行格式化的输出
printf 格式 文本1 文本2 ..
普通格式转换符
- %s 字符串
- %f 浮点格式
- %c ASCII字符,即显示对应参数的第一个字符
- %d,%i 十进制整数
- %o 八进制值
- %u 不带正负号的十进制值
- %x 十六进制值(a-f)
- %X 十六进制值(A-F)
-
%% 表示%本身
常用的转义字符
- \a 警告字符,通常为ASCII的BEL字符
- \b 后退
- \f 换页
- \n 换行
- \r 回车
- \t 水平制表符
- \v 垂直制表符
-
\\ 表示\本身
字符串格式并且换行
[root@oldboyedu scripts] # printf "%s\n" 1 2 3 4
1
2
3
4
[root@oldboyedu scripts] #
浮点格式并且换行(默认6位)
[root@oldboyedu scripts] # printf "%f\n" 1 2 3 4
1.000000
2.000000
3.000000
4.000000
[root@oldboyedu scripts] #
浮点格式只保留2位并切换行
[root@oldboyedu scripts] # printf "%.2f\n" 1.1 2.1 3 4
1.10
2.10
3.00
4.00
[root@oldboyedu scripts] #
浮点格式第一个保留2位,第二个保留3位,第三个保留1位,并且换行
[root@oldboyedu scripts] # printf "%.2f %.3f %.1f\n" 1.1 2.1 3 4
1.10 2.100 3.0
4.00 0.000 0.0
[root@oldboyedu scripts] #
字符格式显示出下列姓名,性别,学历信息
"-":表示左边对齐
-n:n代表的是中间隔几个字符
[root@oldboyedu scripts] # printf "%-8s %-6s %-7s\n" 姓名 性别 学历 梁宇星 男 大专
姓名 性别 学历
梁宇星 男 大专
[root@oldboyedu scripts] #
10进制转16进制%x(小写)%X(大写)
[root@oldboyedu scripts] # printf "%x\n" 14 printf 需要被转换成的进制数 转换的进制数
e
[root@oldboyedu scripts] #
[root@oldboyedu scripts] # printf "%X\n" 14 printf 需要被转换成的进制数 转换的进制数
E
[root@oldboyedu scripts] #
16进制转10进制%d或者%i
[root@oldboyedu scripts] # printf "%i\n" 0xc
12
[root@oldboyedu scripts] # printf "%d\n" 0xc
12
[root@oldboyedu scripts] #
1.12.3 rpm*****
语法:rpm -ivh *.rpm
- i:install 安装的意思
- v: verbose 显示安装信息的详细过程
- h:human 以人类可以认知的方式阅读
- -qa 查找软件包完整名字
- -ql 查找软件包的详细信息
- rpm -e 卸载软件包(需要该软件没有关联性)
-
rpm -e *.rpm –nodes 卸载软件包(可以忽略关联包的信息)
特点:先要把软件包下载好,在安装
没有解决依赖关系
1.12.4 yum****
- yum -y groupinstall 软件名称 安装包组
- yum -y reinstall 软件名称 重新安装
- yum list 遍历软件
- yum grouplist 遍历软件包
- yum repolist 查看系统具有的yum源信息
-
yum provides 查看安装的软件属于哪个大礼包
[root@oldboy6666 ~] # yum -y install figner
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
No package figner available.
Error: Nothing to do
[root@oldboy6666 ~] # yum -y install finger
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package finger.x86_64 0:0.17-52.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================
Installing:
finger x86_64 0.17-52.el7 base 25 k
Transaction Summary
======================================================================================================================================================
Install 1 Package
Total download size: 25 k
Installed size: 32 k
Downloading packages:
finger-0.17-52.el7.x86_64.rpm | 25 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : finger-0.17-52.el7.x86_64 1/1
Verifying : finger-0.17-52.el7.x86_64 1/1
Installed:
finger.x86_64 0:0.17-52.el7
Complete!
查找yum指定安装包的包名(provides)
[root@oldboy6666 ~] # yum install -y locate
Loaded plugins: fastestmirror
No package locate available.
Error: Nothing to do----------------没有找到这个安装包
[root@oldboy6666 ~] # yum provides locate
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
mlocate-0.26-8.el7.x86_64 : An utility for finding files by name 安装包的名字为mlocate
Repo : base
Matched from:
Filename : /usr/bin/locate
[root@oldboy6666 ~] # yum install -y mlocate 重新安装mlocate
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Installed:
mlocate.x86_64 0:0.26-8.el7
Complete! 安装成功
1.12.5 watch
watch :会周期性的检测一个命令的运行结果
1.12.6 alias*****
将别名ifname输入,得到查看主机名的信息
[root@oldboy6666 ~] # alias ifname='cat /etc/hostname'
[root@oldboy6666 ~] # ifname
oldboy6666
[root@oldboy6666 ~] #
1.12.7 unalias*****
将别名ifname失效
[root@oldboy6666 ~] # unalias ifname
[root@oldboy6666 ~] # ifname
-bash: ifname: command not found
[root@oldboy6666 ~] #
1.12.8 date*****
-
y 代表年
-
Y 代表年(带世纪)
-
m 代表分钟
-
M 代表月
-
d 代表天
-
S 代表秒
-
W 代表一年的第几周
-
w 代表这周星期几
-
H 代表小时
11.5.1.1 date命令
[root@oldboy6666 oldboy] # date
Tue Sep 17 08:28:48 CST 2019
[root@oldboy6666 oldboy] #
将时间修改成人类可读的时间类型
[root@oldboy6666 oldboy] # date "+%Y-%m-%d %H:%M:%S"
2019-09-17 10:05:20
[root@oldboy6666 oldboy] #
修改时间
-
-s 修改时间
[root@oldboy6666 oldboy] # date -s "20190918 10:20:00"
Wed Sep 18 10:20:00 CST 2019
[root@oldboy6666 oldboy] # date
Wed Sep 18 10:20:02 CST 2019
[root@oldboy6666 oldboy] # date "+%Y-%m-%d %H:%M:%S"
2019-09-18 10:20:05
[root@oldboy6666 oldboy] #
将时间进行穿越式的修改
查看后20天的时间
[root@oldboy6666 ~] # date -d "+20 day" "+%Y-%m-%d"
2019-10-08
[root@oldboy6666 ~] #
查看前5天的时间
[root@oldboy6666 ~] # date -d "-5 day" "+%Y-%m-%d"
2019-09-13
[root@oldboy6666 ~] #
查看1970年01-01后的1234567890秒时间
[root@oldboy6666 tmp] # date -d "1970-01-01 +1234567890second" "+%F %T"
2009-02-13 23:31:30
[root@oldboy6666 tmp] #
1.12.9 clear
清除终端信息
1.12.10 history****
history:查看历史记录
[root@oldboy6666 ~] # history
35 192.168.21.201
36 ping 192.168.21.201
37 ping 192.168.22.201
38 ping 10.0.0.202
39 ip route del gw 10.0.0.254
40 ip route del default gw 10.0.0.254
41 systemctl restart network
42 ip route show
43 ping 223.5.5.5
44 ping 10.0.0.1
45 ping 10.0.0.254
46 ping 192.168.21.21
47 vi /etc/sysconfig/network-scripts/ifcfg-eth0
48 ls
49 vi /etc/sysconfig/network-scripts/ifcfg-eth0
50 ls
51 systemctl restrat network
52 systemctl restart network
53 poweroff
54 c
55 ls --help
56 ls -d /mnt/
57 ls
58 ls /m
59 ls /mnt/
60 ks
history 10:显示最近的10条记录
[root@oldboy6666 ~] # history 10
1028 date -d "-1 day" +"%Y-%m-%d"
1029 date -d "-1 mo'n't'ho" +"%Y-%m-%d"
1030 date -d "-1 month" +"%Y-%m-%d"
1031 date -d "+1 month" +"%Y-%m-%d"
1032 date -d "+1 year" +"%Y-%m-%d"
1033 date -d "-1 year" +"%Y-%m-%d"
1034 history
1035 history -n 10
1036 history 10
1037 history 10
history -c:清除历史记录
[root@oldboy6666 ~] # history -c
[root@oldboy6666 ~] # histoy
-bash: histoy: command not found
[root@oldboy6666 ~] # history
39 histoy
40 history
[root@oldboy6666 ~] #
[root@oldboy6666 ~] #
history -w:保存历史数据到~/.bash_history目录下
[root@oldboy6666 ~] # history -w
[root@oldboy6666 ~] # cat ~/.bash_history
cat ~/.bash_history
ls
cat
cd .
ls
ll
history
history -w
[root@oldboy6666 ~] #
1.12.11 eject
用于退出抽取式设备
[root@oldboyedu scripts] # eject /dev/cdrom
[root@oldboyedu scripts] #
1.12.12 time****
[root@oldboy6666 ~] # ntpdate ntp1.aliyun.com
12 Sep 16:57:03 ntpdate[8479]: adjust time server 120.25.115.20 offset 0.000488 sec
[root@oldboy6666 ~] #
自动更新时间常用的参数
[root@oldboy6666 ~] # timedatectl
list-timezones 显示所有时区(timedatectl list-timezones)
set-local-rtc 更新硬件(bios)时间(timedatectl set-local-rtc 1)
1:代表开启 0代表关闭
set-ntp ntp服务器时间的更新(timedatectl set-ntp 1)
1:代表开启 0代表关闭
set-time 更新时间(timedatectl set-time 20190528)
set-timezone 设置时区(timedatectl set-timezone +时区)
[root@oldboy6666 ~] # timedatectl
1.12.13 nc(后续整理)
nc:简称neicat用来设置路由器
1.12.14 xargs*********
用于整合数据和分组
xargs -n num:分组为n num, 分组
[root@oldboy6666 oldboy01] # find /root/oldboy01/ -name "*.txt" | xargs -n2
/root/oldboy01/oldboy1.txt /root/oldboy01/oldboy2.txt
/root/oldboy01/oldboy3.txt /root/oldboy01/oldboy4.txt
/root/oldboy01/oldboy5.txt /root/oldboy01/oldboy6.txt
/root/oldboy01/oldboy7.txt /root/oldboy01/oldboy8.txt
/root/oldboy01/oldboy9.txt /root/oldboy01/oldboy10.txt
[root@oldboy6666 oldboy01] #
xargs -i :将执行结果放循环放到后面的{}里面 整合
[root@oldboy6666 oldboy01] # find /root/oldboy01/ -name "*.txt" | xargs -i cp {} /tmp/oldboy_tmp/
[root@oldboy6666 oldboy01] # cd /tmp/oldboy_tmp/
[root@oldboy6666 oldboy_tmp] # ls
oldboy10.txt oldboy1.txt oldboy2.txt oldboy3.txt oldboy4.txt oldboy5.txt oldboy6.txt oldboy7.txt oldboy8.txt oldboy9.txt
[root@oldboy6666 oldboy_tmp] #
1.12.15 exec******
\;和+;的区别
1.exec执行原理不同
- \;会查找出来一条数据就会进行直接处理,处理完成才会进行第二条数据的处理,直到处理完毕
-
+;会讲所有数据查询完毕,在一起处理,例如(tar命令打包操作)
2.输入方式有区别
- \;可以在{}后面添加数据
-
+;只能和{}直接相连,不能中间插入数据
查找文件并且删除(使用\来解决)
[root@oldboy6666 oldboy02] # find /root/oldboy01/ -name "2.txt"
/root/oldboy01/oldboy02/2.txt
/root/oldboy01/2.txt
[root@oldboy6666 oldboy02] # find /root/oldboy01/ -name "2.txt" -exec rm {} \;
[root@oldboy6666 oldboy02] # find /root/oldboy01/ -name "2.txt"
[root@oldboy6666 oldboy02] #
将文件进行打包(使用+号来不进行覆盖,进行累加)
[root@oldboy6666 tmp] # find /oldboy -name "*.txt" -exec tar zcvf /tmp/oldboy1.tar.gz {} +;
tar: Removing leading `/' from member names
/oldboy/1.txt
/oldboy/2.txt
/oldboy/3.txt
/oldboy/4.txt
/oldboy/aa.txt
/oldboy/bb.txt
[root@oldboy6666 tmp] # tar tf oldboy1.tar.gz
oldboy/1.txt
oldboy/2.txt
oldboy/3.txt
oldboy/4.txt
oldboy/aa.txt
oldboy/bb.txt
[root@oldboy6666 tmp] #1.12.16 export
用于设置和显示环境变量
列出当前环境的变量名
[root@oldboyedu ~] # export -p
declare -x HISTCONTROL="ignoredups"
declare -x HISTSIZE="1000"
declare -x HOME="/root"
declare -x HOSTNAME="oldboyedu"
declare -x LANG="en_US.UTF-8"
declare -x LESSOPEN="||/usr/bin/lesspipe.sh %s"
declare -x LOGNAME="root"
declare -x LS_COLORS="rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:"
declare -x MAIL="/var/spool/mail/root"
declare -x OLDPWD
declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin"
declare -x PS1="[\\[\\e[35;1m\\]\\u\\[\\e[31;1m\\]@\\[\\e[36;1m\\]\\h \\[\\e[33;1m\\]\\W\\[\\e[0m\\]] \\[\\e[34;1m\\]\\\$ \\[\\e[0m\\]"
declare -x PWD="/root"
declare -x QT_GRAPHICSSYSTEM_CHECKED="1"
declare -x SHELL="/bin/bash"
declare -x SHLVL="1"
declare -x SSH_CLIENT="10.0.0.1 61038 22"
declare -x SSH_CONNECTION="10.0.0.1 61038 10.0.0.200 22"
declare -x SSH_TTY="/dev/pts/1"
declare -x TERM="linux"
declare -x USER="root"
declare -x XDG_DATA_DIRS="/root/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share"
declare -x XDG_RUNTIME_DIR="/run/user/0"
declare -x XDG_SESSION_ID="243"
[root@oldboyedu ~] #
1.12.17 unset
取消变量的设置
[root@oldboyedu ~] # aa=`cat /etc/hosts`
[root@oldboyedu ~] # echo $aa
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@oldboyedu ~] # unset aa
[root@oldboyedu ~] # echo $aa
1.12.18 type
判断一个名字当前是否是alias、keyword、function、builtin、file或者什么都不是
-
type ls 的输出是 ls 是 `ls --color=auto' 的别名
-
type if 的输出是 if 是 shell 关键字
-
type type 的输出是 type 是 shell 内嵌
-
type frydsh 的输出是 bash: type: frydsh: 未找到
判断一个名字当前是否是alias、keyword、function、builtin、file或者什么都不是的另一种方法(适用于脚本编程)
-
type -t ls 的输出是 alias
-
type -t if 的输出是 keyword
-
type -t type 的输出是 builtin
-
type -t gedit 的输出是 file
-
type -t frydsh 没有输出
显示一个名字的所有可能
-
type -a kill 的输出是 kill 是 shell 内嵌 和 kill 是 /bin/kill
-
type -at kill 的输出是 builtin 和 file
查看一个命令的执行路径(如果它是外部命令的话)
-
type -p gedit 的输出是 /usr/bin/gedit
-
type -p kill 没有输出(因为kill是内置命令)
强制搜索外部命令
-
type -P kill 的输出是 /bin/kill
1.12.19 bc
整数计算,并且结果是整数
[root@oldboyedu ~] # bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
3+2+5+9
19
整数计算,最后得出的有小数的(需要输入scale=n[n代表的是小数位有几位])
[root@oldboyedu ~] # bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
scale=4
100/3
33.3333
1.12.20 seq*****
生成序列
[root@oldboy6666 oldboy] # seq 1 10
1
2
3
4
5
6
7
8
9
10
[root@oldboy6666 oldboy] #
生成等差序列
生成奇数序列
[root@oldboy6666 oldboy] # seq 1 2 10
1
3
5
7
9
生成偶数序列
[root@oldboy6666 oldboy] # seq 0 2 10
0
2
4
6
8
10
[root@oldboy6666 oldboy] #
对齐序列
[root@oldboy6666 oldboy] # seq -w 1 10
01
02
03
04
05
06
07
08
09
10
[root@oldboy6666 oldboy] #
1.13 系统管理与性能监视命令
1.13.1 chkconfig(后续整理)
1.13.2 vmstat(后续整理)
1.13.3 mpstat(后续整理)
1.13.4 iostat(后续整理)
1.13.5 sar(后续整理)
1.13.6 ipcs(后续整理)
1.13.7 ipcrm(后续整理)
1.13.8 strace(后续整理)
1.13.9 ltrace(后续整理)
1.14 关机/重启/注销和查看系统信息的命令
1.14.1 shutdown****
shutdown :重启/关闭
shutdown -r 5:5分钟之后重启(0/now是立即重启)
[root@oldboyedu ~]# shutdown -r 5 "system will 5 after reboot"
Shutdown scheduled for Wed 2019-09-04 14:38:14 CST, use 'shutdown -c' to cancel.
Broadcast message from root@oldboyedu.com (Wed 2019-09-04 14:33:14 CST):
system will 5 after reboot
The system is going down for reboot at Wed 2019-09-04 14:38:14 CST!
Shutdown -h 5:5分钟之后关机(0/now是立即关机)
[root@oldboyedu ~]# shutdown -h 5 "system will 5 after poweroff"
Shutdown scheduled for Wed 2019-09-04 14:42:33 CST, use 'shutdown -c' to cancel.
[root@oldboyedu ~]#
Broadcast message from root@oldboyedu.com (Wed 2019-09-04 14:37:33 CST):
system will 5 after poweroff
The system is going down for power-off at Wed 2019-09-04 14:42:33 CST
1.14.2 halt****
halt:用来关闭linux系统,关闭会检测linux的运行状态(0,6才会使用)
halt -d:关闭系统,但不留下记录
halt -f:不论目前什么等级都不调用shutdown来强制关闭系统
halt -p:关闭系统后关闭电源
1.14.3 poweroff*****
poweroff:立即关闭系统
Last login: Wed Sep 4 14:49:25 2019 from 10.0.0.1
[root@oldboyedu ~]# poweroff
Connection closed by foreign host.
Disconnected from remote host(老男孩66期-模板主机) at 14:50:17.
Type `help' to learn how to use Xshell prompt.
1.14.4 logout*****
Logout:退出当前登陆的shell,相当于ctrl+d
[root@oldboyedu ~]# logout
Connection closed by foreign host.
Disconnected from remote host(老男孩66期-模板主机) at 14:52:54.
Type `help' to learn how to use Xshell prompt.
1.14.5 exit*****
exit:和logout差不多,也是指退出当前shell
[root@oldboyedu ~]# exit
logout
Connection closed by foreign host.
Disconnected from remote host(老男孩66期-模板主机) at 14:57:04.
Type `help' to learn how to use Xshell prompt.
在shell脚本里面,指状态值,如果是0,则成功,如果是其他数字,则表示失败
[root@oldboyedu ~]# cd aa | exit 0
-bash: cd: aa: No such file or directory
[root@oldboyedu ~]# cd aa | exit 1
-bash: cd: aa: No such file or directory
[root@oldboyedu ~]#
1.14.6 init*****
init 0:关机命令
init 6:重启命令
init1:单用户模式(救援模式)
init 3:多用户模式
init 2:多用户模式(没有网络)
init4:未设置的,空余的
1.15 进程管理相关命令
1.15.1 bg
将一个后台暂停的命令,变成继续执行
1.15.2 fg
将一个前台暂停的命令变成继续执行
1.15.3 jobs
有多少在后台暂停的任务
[root@oldboyedu oldboy01] # jobs
[1]- Stopped vim /etc/hosts
[2]+ Stopped vim /etc/selinux/config
[root@oldboyedu oldboy01] #
1.15.4 kill
kill表示的是杀死指定进程,默认不带任何参数是15信号发送
- 1 终端断线
- 2 等同 Ctrl + C
- 3 等同Ctrl + \
- 15 终止(可以使得进程在退出之前清理并释放资源)
- 9 强制终止
- 18 继续(与19相反)
-
19 暂停(等同 Ctrl + Z)
查看kill的所有信号信息
[root@oldboyedu oldboy01] # kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
[root@oldboyedu oldboy01] #
强制杀死crond(定时任务)的进程
[root@oldboyedu oldboy01] # ps -ef | grep crond
root 1330 1 0 07:48 ? 00:00:00 /usr/sbin/crond -n
root 2704 1385 0 08:26 pts/1 00:00:00 grep --color=auto crond
[root@oldboyedu oldboy01] # kill -9 1330
[root@oldboyedu oldboy01] # ps -ef | grep crond
root 2706 1385 0 08:26 pts/1 00:00:00 grep --color=auto crond
[root@oldboyedu oldboy01] #
init进程是杀不死的
[root@oldboyedu oldboy01] # ps -ef | grep init 查看init进程
root 950 1 0 07:47 ? 00:00:00 /usr/sbin/alsactl -s -n 19 -c -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf --initfile=/lib/alsa/init/00main rdaemon
root 2734 1385 0 08:29 pts/1 00:00:00 grep --color=auto init
[root@oldboyedu oldboy01] # pkill -9 950 杀死init进程ID
[root@oldboyedu oldboy01] # ps -ef | grep init 再次查看发现进程还存在
root 950 1 0 07:47 ? 00:00:00 /usr/sbin/alsactl -s -n 19 -c -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf --initfile=/lib/alsa/init/00main rdaemon
root 2737 1385 0 08:29 pts/1 00:00:00 grep --color=auto init
[root@oldboyedu oldboy01] # pkill -9 950 再强制杀死进程ID
[root@oldboyedu oldboy01] # ps -ef | grep init 再次查看发现进程还存在
root 950 1 0 07:47 ? 00:00:00 /usr/sbin/alsactl -s -n 19 -c -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf --initfile=/lib/alsa/init/00main rdaemon
root 2740 1385 0 08:29 pts/1 00:00:00 grep --color=auto init
杀死连接在终端不需要的用户(-t指定终断连接的用户)
[root@oldboyedu ~] # w 查看
08:39:28 up 51 min, 2 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/1 10.0.0.1 07:48 10:08 0.37s 0.30s -bash
root pts/0 10.0.0.1 08:35 0.00s 0.03s 0.00s w
[root@oldboyedu ~] # pkill -kill -t pts/1
[root@oldboyedu ~] # 2
bash: 2: command not found...
[root@oldboyedu ~] # w
08:40:30 up 52 min, 1 user, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 10.0.0.1 08:35 6.00s 0.03s 0.00s w
[root@oldboyedu ~] #
1.15.5 killall
-
-9 强制杀死进程名称
杀死指定进程的名称
[root@oldboyedu ~] # ps -ef | grep crond 查看进程
root 3541 1 0 09:36 ? 00:00:00 /usr/sbin/crond -n
root 3546 3439 0 09:36 pts/1 00:00:00 grep --color=auto crond
[root@oldboyedu ~] # killall crond 杀死指定进程名称
[root@oldboyedu ~] # ps -ef | grep crond 再次查看发现已经杀死
root 3549 3439 0 09:36 pts/1 00:00:00 grep --color=auto crond
[root@oldboyedu ~] #
1.15.6 pkill
pkill和killall的使用基本一样,都是杀死进程名称
1.15.7 crontab********
一个命令
crontab -l:查看配置的定时任务
[root@oldboyedu ~] # crontab -l
30 2 * * * cp -rf /etc/hosts /etc/hosts.bak
[root@oldboyedu ~] #
crontab -e:编写定时任务
[root@oldboyedu ~] # crontab -e
no crontab for root - using an empty one
30 2 * * *
crontab -r:清空定时任务配置的任务信息
[root@oldboyedu ~] # crontab -l 查看定时任务信息
#30 */1 * * * cp /etc/hosts /etc/hosts_lyx.bak
#*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com
#*/5 * * * * sh /server/scripts/ntpdate_sync.sh & > /dev/null
#* * * * * tar zcvf /opt/hosts_$(date +\%F).tar.gz /etc/hosts
#* * * * * sh /server/scripts/tar_sync.sh & >/dev/null
[root@oldboyedu ~] # crontab -r 清除定时任务信息
[root@oldboyedu ~] # crontab -l 再次查看发现已经没有信息
no crontab for root
[root@oldboyedu ~] #
俩个文件
root用户设置定时任务的配置文件
[root@oldboyedu ~] # ll /var/spool/cron/root root用户设置定时任务的配置文件
-rw------- 1 root root 44 Oct 2 15:25 /var/spool/cron/root
[root@oldboyedu ~] #
root用户定时任务的日志文件
[root@oldboyedu ~] # tail -f /var/log/cron root用户定时任务的日志文件
Oct 2 19:30:01 oldboyedu CROND[8172]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Oct 2 19:40:01 oldboyedu CROND[8258]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Oct 2 19:50:01 oldboyedu CROND[8345]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Oct 2 20:00:01 oldboyedu CROND[8431]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Oct 2 20:01:02 oldboyedu CROND[8444]: (root) CMD (run-parts /etc/cron.hourly)
Oct 2 20:01:02 oldboyedu run-parts(/etc/cron.hourly)[8444]: starting 0anacron
Oct 2 20:01:02 oldboyedu run-parts(/etc/cron.hourly)[8453]: finished 0anacron
- Oct 2 20:01:02 产生定时任务信息的时间
- oldboyedu 用户主机名
- run-parts(/etc/cron.hourly)[8453] 读取什么定时任务文件信息
-
finished 0anacron 执行了什么定时任务
1.15.8 ps
ps -ef:查看所有进程
[root@oldboyedu ~] # ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 07:47 ? 00:00:05 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root 634 2 0 07:47 ? 00:00:00 [xfs-log/sda1]
root 636 2 0 07:47 ? 00:00:00 [xfs-eofblocks/s]
root 641 2 0 07:47 ? 00:00:00 [xfsaild/sda1]
root 691 2 0 07:47 ? 00:00:00 [jbd2/sdb1-8]
root 694 2 0 07:47 ? 00:00:00 [ext4-rsv-conver]
root 787 2 0 07:47 ? 00:00:00 [kdmflush]
root 788 2 0 07:47 ? 00:00:00 [bioset]
root 790 2 0 07:47 ? 00:00:00 [kdmflush]
root 791 2 0 07:47 ? 00:00:00 [bioset]
root 918 1 0 07:47 ? 00:00:00 /sbin/auditd
root 920 918 0 07:47 ? 00:00:00 /sbin/audispd
root 922 920 0 07:47 ? 00:00:00 /usr/sbin/sedispatch
root 925 2 0 07:47 ? 00:00:00 [rpciod]
root 926 2 0 07:47 ? 00:00:00 [xprtiod]
libstor+ 949 1 0 07:47 ? 00:00:00 /usr/bin/lsmd -d
dbus 971 1 0 07:47 ? 00:00:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
……….省略进程信息
root 3598 1 0 09:41 ? 00:00:00 /usr/sbin/crond -n
root 3604 3439 0 09:41 pts/1 00:00:00 ps -ef
ps -ef | grep 进程名字:查找指定进程名称
[root@oldboyedu ~] # ps -ef | grep crond 查找crond进程信息
root 3598 1 0 09:41 ? 00:00:00 /usr/sbin/crond -n
root 3603 3439 0 09:41 pts/1 00:00:00 grep --color=auto crond
1.15.9 pstree
以树状图的方式展现进程之间的派生关系,显示效果比较直观
pstree -p:显示所有的进程
[oldboy10@oldboyedu sysconfig] $ pstree -p
systemd(1)─┬─ModemManager(970)─┬─{ModemManager}(978)
│ └─{ModemManager}(982)
├─NetworkManager(1021)─┬─{NetworkManager}(1039)
│ └─{NetworkManager}(1042)
├─VGAuthService(986)
│ └─{ibus-portal}(1911)
├─ibus-x11(1902)─┬─{ibus-x11}(1909)
…………..省略
│ └─{ibus-x11}(1912)
licant(1934)
└─xdg-permission-(1915)─┬─{xdg-permission-}(1916)
└─{xdg-permission-}(1918)
[oldboy10@oldboyedu sysconfig] $
pstree -u:显示所有的用户名称
[oldboy10@oldboyedu sysconfig] $ pstree -u
systemd─┬─ModemManager───2*[{ModemManager}]
├─NetworkManager───2*[{NetworkManager}]
├─auditd─┬─audispd─┬─sedispatch
│ │ └─{audispd}
│ └─{auditd}
……….省略
├─dnsmasq(nobody)───dnsmasq(root)
├─gdm─┬─X───{X}
│ ├─gdm-session-wor─┬─gnome-session-b(gdm)─┬─gnome-shell─┬─
├─vmtoolsd───{vmtoolsd}
├─wpa_supplicant
└─xdg-permission-(gdm)───2*[{xdg-permission-}]
[oldboy10@oldboyedu sysconfig] $
1.15.10 nice/renice
调整程序优先执行的命令
[root@oldboyedu ~] # ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 4524 4520 0 80 0 - 29195 do_wai pts/1 00:00:00 bash
0 R 0 4585 4524 0 80 0 - 38309 - pts/1 00:00:00 ps
[root@oldboyedu ~] # nice -n 5 cat&
[1] 4586
[root@oldboyedu ~] # ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 4524 4520 0 80 0 - 29195 do_wai pts/1 00:00:00 bash
0 T 0 4586 4524 0 85 5 - 26993 do_sig pts/1 00:00:00 cat
0 R 0 4587 4524 0 80 0 - 38309 - pts/1 00:00:00 ps
[1]+ Stopped nice -n 5 cat
1.15.11 nohup(后续整理)
1.15.12 pgrep
以程序为名称从运行进程队列中查找进程
pgrep -la:你要查找的进程名称的详细信息
[root@oldboyedu ~] # pgrep -la httpd
2378 /usr/sbin/httpd -DFOREGROUND
2379 /usr/sbin/httpd -DFOREGROUND
2380 /usr/sbin/httpd -DFOREGROUND
2381 /usr/sbin/httpd -DFOREGROUND
2382 /usr/sbin/httpd -DFOREGROUND
2383 /usr/sbin/httpd -DFOREGROUND
[root@oldboyedu ~] #
pgrep -l:查看进程ID和名称
[root@oldboyedu ~] # pgrep -l httpd
2378 httpd
2379 httpd
2380 httpd
2381 httpd
2382 httpd
2383 httpd
[root@oldboyedu ~] #
pgrep -lo:查看进程名称最小的ID号码
[root@oldboyedu ~] # pgrep -lo httpd
2378 httpd
[root@oldboyedu ~] #
pgrep -ln: 查看进程名称最大ID号码
[root@oldboyedu ~] # pgrep -ln httpd
2383 httpd
[root@oldboyedu ~] #
pgrep:查看进程名称的ID
[root@oldboyedu ~] # pgrep ttpd
2378
2379
2380
2381
2382
2383
[root@oldboyedu ~] #
1.15.13 runlevel
查看系统的运行级别
[root@oldboy6666 ~] # runlevel
N 3
[root@oldboy6666 ~] #
1.15.14 init
init 0:关机命令
init 6:重启命令
init1:单用户模式(救援模式)
init 3:多用户模式
init 2:多用户模式(没有网络)
init4:未设置的,空余的
1.15.15 service
service默认等于/etc/init.d
- service 服务名称 status 查看服务的状态
- service 服务名称 start 将服务启动
- service 服务名称 stop 将服务停止
-
service 服务名称 restart 将服务重启
1.15.16 systemctl
- systemctl status 服务名称 查看服务状态
- systemctl start 务名称 启动服务(临时)
- systemctl stop 服务名称 停止服务(临时)
- systemctl enable 服务名称 永久开启服务
- systemctl disable 服务名称 永远关闭服务
- systemctl set-default 运行target 设置什么模式开启系统
-
systemctl get-default 查看当前是什么模式运行的系统
1.16 文件压缩及解压缩命令
1.16.1 tar*******
1.16.1.1 压缩命令
压缩常见的参数详解
标准模式czvf 特殊模式:czvPhf
- c 创建一个压缩文件
- z 压缩成gzip文件格式的
- v 详细显示压缩的过程
- f 指定压缩包的路径
- h 压缩的时候不会压缩软连接文件,会直接压缩真正的文件
- P 压缩的时候采用绝对路径的压缩,解压的时候也是,(会造成文件的覆盖)
- --exclude-from=指定的文件 将文件中的内容排除,不进行打包
-
--exclude=排除的文件目录 将指定的文件进行排除
压缩文件格式
格式:tar czvf 压缩包的名字 压缩的数据
将/root/oldboy01/下面的文件找到,并且进行打包,打包名字为oldboy_tar.tar.gz
[root@oldboy6666 ~] # find /root/oldboy01/ -name "*.txt" | xargs tar czvf /root/oldboy_tar.tar.gz
tar: Removing leading `/' from member names
/root/oldboy01/oldboy1.txt
/root/oldboy01/oldboy2.txt
/root/oldboy01/oldboy3.txt
/root/oldboy01/oldboy4.txt
/root/oldboy01/oldboy5.txt
/root/oldboy01/oldboy6.txt
/root/oldboy01/oldboy7.txt
/root/oldboy01/oldboy8.txt
/root/oldboy01/oldboy9.txt
/root/oldboy01/oldboy10.txt
[root@oldboy6666 ~] # ls
anaconda-ks.cfg oldboy01 oldboy_tar.tar.gz passwd
[root@oldboy6666 ~] #
将/etc/rc.local进行打包(必须加参数h,要不就的去打包本身的路径)
[root@oldboy6666 ~] # tar zcvfh rc.local.tar.gz /etc/rc.local
tar: Removing leading `/' from member names
/etc/rc.local
[root@oldboy6666 ~] # ls
anaconda-ks.cfg h oldboy01 oldboy_tar.tar.gz passwd rc.local.tar.gz
[root@oldboy6666 ~] # tar tf rc.local.tar.gz
etc/rc.local
[root@oldboy6666 ~] #
将/oldboy/oldboy01下面的a.txt,b.txt打包, 将/oldboy/oldboy02下面的c.txt,a.txt不打包,剩余的打包
-
使用- -exclude-from方法解决
[root@oldboy6666 oldboy] # tar zcvf oldboy01.tar.gz ./oldboy01 ./oldboy02 --exclude-from=./1.txt
./oldboy01/
./oldboy01/a.txt
./oldboy01/b.txt
./oldboy02/
./oldboy02/b.txt
./oldboy02/c.txt
[root@oldboy6666 oldboy] # cat 1.txt
./oldboy01/c.txt
./oldboy02/a.txt
[root@oldboy6666 oldboy] #
(2)使用- -exclude进行解决
[root@oldboy6666 oldboy] # tar zcvf oldboy01.tar.gz ./oldboy01 --exclude=./oldboy01/c.txt ./oldboy02 --exclude=./oldboy02/a.txt
./oldboy01/
./oldboy01/a.txt
./oldboy01/b.txt
./oldboy02/
./oldboy02/b.txt
./oldboy02/c.txt
[root@oldboy6666 oldboy] #
解答
-
tar: Removing leading `/' from member names?
出现这个问题是因为:一个警告,告诉你打包的时候会将根排除,因为如果将根打包会造成解压的时候数据覆盖
解决办法
- 采取相对路径进行打包操作
- 采取带P参数进行操作
1.16.1.2 查看压缩命令
查看压缩文件的格式
tar tf 查看的压缩包
查看oldboy_tar.tar.gz里面的内容是否压缩完整
[root@oldboy6666 ~] # tar tf oldboy_tar.tar.gz
root/oldboy01/oldboy1.txt
root/oldboy01/oldboy2.txt
root/oldboy01/oldboy3.txt
root/oldboy01/oldboy4.txt
root/oldboy01/oldboy5.txt
root/oldboy01/oldboy6.txt
root/oldboy01/oldboy7.txt
root/oldboy01/oldboy8.txt
root/oldboy01/oldboy9.txt
[root@oldboy6666 ~] #
1.16.1.3 解压命令
解压常见的参数
- x 进行解压
-
-C 指定解压的路径
解压格式
tar xf 解压的压缩包
将oldboy01.tar.gz进行解压
[root@oldboy6666 oldboy_tmp] # tar xf oldboy01.tar.gz
[root@oldboy6666 oldboy_tmp] # ls
oldboy01.tar,gz oldboy01.tar.gz root
[root@oldboy6666 oldboy_tmp] # ls
oldboy01.tar,gz oldboy01.tar.gz root
[root@oldboy6666 oldboy_tmp] # ls
oldboy01.tar,gz oldboy01.tar.gz root
[root@oldboy6666 oldboy_tmp] # cd /root/oldboy01/
[root@oldboy6666 oldboy01] # ls
oldboy02 oldboy10.txt oldboy1.txt oldboy2.txt oldboy3.txt oldboy4.txt oldboy5.txt oldboy6.txt oldboy7.txt oldboy8.txt oldboy9.txt
[root@oldboy6666 oldboy01] #
将oldboy01.tar.gz解压到/tmp目录下
[root@oldboy6666 oldboy] # ls
oldboy01.tar.gz oldboy01.txt oldboy02.txt oldboy03.txt
[root@oldboy6666 oldboy] # tar xf oldboy01.tar.gz -C /tmp
[root@oldboy6666 oldboy] # cd -
/tmp
[root@oldboy6666 tmp] # ls
oldboy01.txt oldboy02.txt oldboy03.txt
[root@oldboy6666 tmp] #
1.16.2 unzip
unzip是解压后缀为zip的压缩包
[root@oldboyedu oldboy01] # unzip /oldboy02/oldboy.zip
Archive: /oldboy02/oldboy.zip
extracting: oldboy01.txt
extracting: oldboy02.txt
extracting: oldboy.txt
inflating: passwd_lyx.txt
[root@oldboyedu oldboy01] # ll
total 16
dr-xr-xr-x 2 1019 root 20 Sep 28 22:07 aa
-rw-r--r-- 1 root root 9 Oct 8 20:08 oldboy01.txt
-rw-r--r-- 1 root root 9 Oct 8 20:08 oldboy02.txt
-rw-r--r-- 1 root root 7 Oct 8 20:08 oldboy.txt
-rw-r--r-- 1 root root 654 Oct 8 20:31 passwd_lyx.txt
[root@oldboyedu oldboy01] #
1.16.3 gzip
压缩文件(-v)
[root@oldboyedu oldboy02] # gzip -v *
oldboy01.txt: -22.2% -- replaced with oldboy01.txt.gz
oldboy02.txt: -22.2% -- replaced with oldboy02.txt.gz
oldboy.txt: -28.6% -- replaced with oldboy.txt.gz
passwd_lyx.txt: 54.0% -- replaced with passwd_lyx.txt.gz
[root@oldboyedu oldboy02] # ll
total 16
-rw-r--r-- 1 root root 42 Oct 8 20:08 oldboy01.txt.gz
-rw-r--r-- 1 root root 42 Oct 8 20:08 oldboy02.txt.gz
-rw-r--r-- 1 root root 38 Oct 8 20:08 oldboy.txt.gz
-rw-r--r-- 1 root root 334 Oct 8 20:31 passwd_lyx.txt.gz
[root@oldboyedu oldboy02] #
压缩目录(-vr)
[root@oldboyedu oldboy02] # gzip -vr /oldboy01 压缩目录.使用递归r
/oldboy01/aa/aa.txt: 0.0% -- replaced with /oldboy01/aa/aa.txt.gz
/oldboy01/oldboy01.txt: -22.2% -- replaced with /oldboy01/oldboy01.txt.gz
/oldboy01/oldboy02.txt: -22.2% -- replaced with /oldboy01/oldboy02.txt.gz
/oldboy01/oldboy.txt: -28.6% -- replaced with /oldboy01/oldboy.txt.gz
/oldboy01/passwd_lyx.txt: 54.0% -- replaced with /oldboy01/passwd_lyx.txt.gz
/oldboy01/oldboy02/oldboy.txt: -28.6% -- replaced with /oldboy01/oldboy02/oldboy.txt.gz
/oldboy01/oldboy02/oldboy01.txt: -22.2% -- replaced with /oldboy01/oldboy02/oldboy01.txt.gz
/oldboy01/oldboy02/oldboy02.txt: -22.2% -- replaced with /oldboy01/oldboy02/oldboy02.txt.gz
/oldboy01/oldboy02/passwd_lyx.txt: 54.0% -- replaced with /oldboy01/oldboy02/passwd_lyx.txt.gz
/oldboy01/oldboy02/oldboy.zip: 41.8% -- replaced with /oldboy01/oldboy02/oldboy.zip.gz
/oldboy01/oldboy02.zip: 67.7% -- replaced with /oldboy01/oldboy02.zip.gz
[root@oldboyedu oldboy02] # ll /oldboy01 查看oldboy01里面的内容都为后缀*.gz的文件
total 20
-rw-r--r-- 1 root root 42 Oct 8 20:08 oldboy01.txt.gz
-rw-r--r-- 1 root root 42 Oct 8 20:08 oldboy02.txt.gz
-rw-r--r-- 1 root root 773 Oct 9 17:56 oldboy02.zip.gz
-rw-r--r-- 1 root root 38 Oct 8 20:08 oldboy.txt.gz
-rw-r--r-- 1 root root 334 Oct 8 20:31 passwd_lyx.txt.gz
查看压缩的文件(-l)
[root@oldboyedu oldboy02] # gzip -l /oldboy01/*
gzip: /oldboy01/aa is a directory -- ignored
compressed uncompressed ratio uncompressed_name
42 9 -22.2% /oldboy01/oldboy01.txt
gzip: /oldboy01/oldboy02 is a directory -- ignored
42 9 -22.2% /oldboy01/oldboy02.txt
773 2296 67.7% /oldboy01/oldboy02.zip
38 7 -28.6% /oldboy01/oldboy.txt
334 654 54.0% /oldboy01/passwd_lyx.txt
1229 2975 59.8% (totals)
[root@oldboyedu oldboy02] #
解压文件(-dv)
[root@oldboyedu oldboy02] # gzip -dv *
oldboy01.txt.gz: -22.2% -- replaced with oldboy01.txt
oldboy02.txt.gz: -22.2% -- replaced with oldboy02.txt
oldboy.txt.gz: -28.6% -- replaced with oldboy.txt
passwd_lyx.txt.gz: 54.0% -- replaced with passwd_lyx.txt
[root@oldboyedu oldboy02] # ll
total 16
-rw-r--r-- 1 root root 9 Oct 8 20:08 oldboy01.txt
-rw-r--r-- 1 root root 9 Oct 8 20:08 oldboy02.txt
-rw-r--r-- 1 root root 7 Oct 8 20:08 oldboy.txt
-rw-r--r-- 1 root root 654 Oct 8 20:31 passwd_lyx.txt
[root@oldboyedu oldboy02] #
解压目录(-drv)
[root@oldboyedu oldboy02] # gzip -dvr /oldboy01
/oldboy01/aa/aa.txt.gz: 0.0% -- replaced with /oldboy01/aa/aa.txt
/oldboy01/oldboy02/oldboy.txt.gz: -28.6% -- replaced with /oldboy01/oldboy02/oldboy.txt
/oldboy01/oldboy02/oldboy01.txt.gz: -22.2% -- replaced with /oldboy01/oldboy02/oldboy01.txt
/oldboy01/oldboy02/oldboy02.txt.gz: -22.2% -- replaced with /oldboy01/oldboy02/oldboy02.txt
/oldboy01/oldboy02/passwd_lyx.txt.gz: 54.0% -- replaced with /oldboy01/oldboy02/passwd_lyx.txt
/oldboy01/oldboy02/oldboy.zip.gz: 41.8% -- replaced with /oldboy01/oldboy02/oldboy.zip
/oldboy01/oldboy01.txt.gz: -22.2% -- replaced with /oldboy01/oldboy01.txt
/oldboy01/oldboy02.txt.gz: -22.2% -- replaced with /oldboy01/oldboy02.txt
/oldboy01/oldboy.txt.gz: -28.6% -- replaced with /oldboy01/oldboy.txt
/oldboy01/passwd_lyx.txt.gz: 54.0% -- replaced with /oldboy01/passwd_lyx.txt
/oldboy01/oldboy02.zip.gz: 67.7% -- replaced with /oldboy01/oldboy02.zip
[root@oldboyedu oldboy02] #
1.16.4 zip
打包为后缀为.zip的文件
[root@oldboyedu oldboy01] # zip oldboy02.zip *
adding: aa/ (stored 0%)
adding: oldboy01.txt (stored 0%)
adding: oldboy02/ (stored 0%)
adding: oldboy02.txt (stored 0%)
adding: oldboy.txt (stored 0%)
adding: passwd_lyx.txt (deflated 54%)
[root@oldboyedu oldboy02] # ll
total 20
-rw-r--r-- 1 root root 9 Oct 8 20:08 oldboy01.txt
-rw-r--r-- 1 root root 9 Oct 8 20:08 oldboy02.txt
-rw-r--r-- 1 root root 7 Oct 8 20:08 oldboy.txt
-rw-r--r-- 1 root root 956 Oct 9 17:48 oldboy.zip
-rw-r--r-- 1 root root 654 Oct 8 20:31 passwd_lyx.txt
[root@oldboyedu oldboy02] #
打包目录需要加r进行遍历打包
错误的操作
[root@oldboyedu oldboy01] # zip oldboy02.zip /oldboy02 打包只把目录本身打包进去,并未将目录里面的
文件打包进去
adding: oldboy02/ (stored 0%)
[root@oldboyedu oldboy01] # unzip oldboy02.zip
Archive: oldboy02.zip
creating: oldboy02/
[root@oldboyedu oldboy01] #
正确的操作
[root@oldboyedu oldboy01] # zip -r oldboy02.zip /oldboy02 打包已经将目录里面的内容都已经遍历打包
进去
adding: oldboy02/ (stored 0%)
adding: oldboy02/oldboy.txt (stored 0%)
adding: oldboy02/oldboy01.txt (stored 0%)
adding: oldboy02/oldboy02.txt (stored 0%)
adding: oldboy02/passwd_lyx.txt (deflated 54%)
adding: oldboy02/oldboy.zip (stored 0%)
[root@oldboyedu oldboy01] # unzip oldboy02.zip
Archive: oldboy02.zip
extracting: oldboy02/oldboy.txt
extracting: oldboy02/oldboy01.txt
extracting: oldboy02/oldboy02.txt
inflating: oldboy02/passwd_lyx.txt