第1章 Linux启动过程
开机自检(BIOS)##硬件检查
MBR引导
GRUB菜单(选择不同的内核)
加载内核
运行init进程(Linux系统里面第一个进程)
读取/etc/inittab配置文件(读取运行级别)
执行/etc/rc.d/sysinit脚本(系统的初始化脚本 设置IP地址)
执行/etc/rc.d/rc脚本(根据系统的运行级别 在开机的时候启动不同的软件)
启动mingetty进程
显示界面
第2章 PATH 变量
PATH 存放的是Linux下命令的位置
[root@oldboyedu-50 ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin 规律 /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin
Linux执行命令的过程
是否是别名
在PATH中找命令是否存在
没有的话提示command not fonund
有就执行
第3章 显示一级目录
问题:
如何过滤出已知当前目录下oldboy中的所有一级目录
(提示:不包含oldboy目录下面目录的子目录及隐藏目录,即只能是一级目录)?
创建环境 mkdir /oldboy -p cd /oldboy mkdir ext/oldboy test xiaodong xiaofan xingfujie -p touch jeacen oldboy wodi.gz yingsui.gz
3.1 方法一 tree
-d 只显示目录
-L level 最多显示多少层 -L 1 最多显示一层
[root@oldboyedu-50 oldboy]# tree -dL 1 . ├── ext ├── test ├── xiaodong ├── xiaofan └── xingfujie 5 directories
3.2 方法二 find
-maxdepth 最大的深度
-maxdepth 最大的深度 [root@oldboyedu-50 oldboy]# find -maxdepth 1 -type d . 显示出了目录 但是多了一个. ./xingfujie ./test ./xiaofan ./xiaodong ./ext
!排除取反 非
排除. 只显示目录 [root@oldboyedu-50 oldboy]# find -maxdepth 1 -type d ! -name "." ./xingfujie ./test ./xiaofan ./xiaodong ./ext
3.3 方法三grep
^以xxx/开头的行 三剑客使用 正则表达式
[root@oldboyedu-50 oldboy]# ls -l |grep "^d" drwxr-xr-x. 3 root root 4096 Jul 10 19:45 ext drwxr-xr-x. 2 root root 4096 Jul 10 19:45 test drwxr-xr-x. 2 root root 4096 Jul 10 19:45 xiaodong drwxr-xr-x. 2 root root 4096 Jul 10 19:45 xiaofan drwxr-xr-x. 2 root root 4096 Jul 10 19:45 xingfujie ^以xxx/开头的行 三剑客使用 正则表达式
3.4 方法四awk
$2表示第二列
[root@oldboyedu-50 oldboy]# ls -l |awk '$2>1' 第二列大于一的 total 20 drwxr-xr-x. 3 root root 4096 Jul 10 19:45 ext drwxr-xr-x. 2 root root 4096 Jul 10 19:45 test drwxr-xr-x. 2 root root 4096 Jul 10 19:45 xiaodong drwxr-xr-x. 2 root root 4096 Jul 10 19:45 xiaofan drwxr-xr-x. 2 root root 4096 Jul 10 19:45 xingfujie
3.5 拓展方法两种
[root@oldboyedu-50 oldboy]# ls -F |grep "/" -F 不同的类型文件 加上不同的标记 目录加上/
[root@oldboyedu-50 oldboy]# ls -ld */ ##看以/结尾的
第4章 压缩
问题:
/etc/目录为linux系统的默认的配置文件及服务启动命令的目录
a.请用tar打包/etc整个目录(打包及压缩)
b.请用tar打包/etc整个目录(打包及压缩,但需要排除/etc/services文件)
c.请把a点命令的压缩包,解压到/tmp指定目录下(最好只用tar命令实现)
4.1 tar下的参数
tar zcvf /tmp/etc.tar.gz /etc/
压缩之后放在哪 要压缩的
z gzip 通过gzip软件压缩
c create 创建包
v verbose 显示过程
f file 指定文件 (在tar中 f 必须要在最后边)
t list 显示压缩包内容
x extaact 解压
压缩 zcvf zcf
查看 ztf tf
解压 zxf xf
4.2 创建压缩包
一般压缩不用参数v 不用显示压缩过程 所以直接用zcf即可
[root@oldboyedu-50 tmp]# tar ztf /tmp/etc.tar.gz 打包及压缩
4.3 解压
解压前先进入要解压到的目录
[root@oldboyedu-50 tmp]# tar zxf etc.tar.gz ##先进入tmp目录
4.4 解压到指定目录
解压使用参数zxf z可以省略 xf即可
[root@oldboyedu-50 tmp]# tar xf /tmp/etc.tar.gz -C /opt/ 解压到opt目录 [root@oldboyedu-50 tmp]# ll /opt/ 解压后检查 total 8 drwxr-xr-x. 78 root root 4096 Jul 10 19:41 etc drwxr-xr-x. 2 root root 4096 Mar 26 2015 rh
4.5 排除某个文件或目录
要求:排除services
排除多个
--exclude-from 加个名单 .txt
.txt里写上路径内容
[root@oldboyedu-50 ~]# tar zcf /tmp/etc.tar.gz /etc/ --exclude /etc/services [root@oldboyedu-50 ~]# tar tf /tmp/etc.tar.gz |grep "services" 检查是否排除 etc/init/readahead-disable-services.conf
4.6 tar经典故障
tar: Removing leading `/' from member names 安全警告 删除 开始 / 把压缩包的 开头的/ 删除掉 由绝对路径 变为了相对路径 防止解压的时候覆盖源文件
第5章 显示行号
打印配置文件nginx.conf内容的行号及内容 如何做?
创建环境
[root@oldboyedu-50 ~]# mkdir /oldboy && echo stu{01..10} |xargs -n1 > /oldboy/ngingx.conf
5.1 方法一 cat
-n 显示行号
[root@oldboyedu-50 oldboy]# cat -n ngingx.conf 1 stu01 2 stu02 3 stu03 4 stu04 5 stu05 6 stu06 7 stu07 8 stu08 9 stu09 10 stu10
5.2 方法二 vim
vim /oldboy/nginx.conf
进入后
:set nu 显示行号
:set nonu 取消显示行号
5.3 方法三 awk
NR 行号
$1 表示第一列
$0 表示一整行的内容
[root@oldboyedu-50 ~]# awk '{print NR,$1}' /oldboy/ngingx.conf 1 stu01 2 stu02 3 stu03 4 stu04 5 stu05 6 stu06 7 stu07 8 stu08 9 stu09 10 stu10
5.4 方法四 nl
nl number of lines 专门用于显示行号的
[root@oldboyedu-50 oldboy]# nl ngingx.conf 1 stu01 2 stu02 3 stu03 4 stu04 5 stu05 6 stu06 7 stu07 8 stu08 9 stu09 10 stu10
5.5 第五种方法 grep
-n /显示行号
. 正则表达式 表示任意一个字符
[root@oldboyedu-50 oldboy]# grep -n "." ngingx.conf 1:stu01 2:stu02 3:stu03 4:stu04 5:stu05 6:stu06 7:stu07 8:stu08 9:stu09 10:stu10
5.6 第六种方法 sed
= 表示显示行号
[root@oldboyedu-50 oldboy]# sed '=' ngingx.conf |xargs -n2 1 stu01 2 stu02 3 stu03 4 stu04 5 stu05 6 stu06 7 stu07 8 stu08 9 stu09 10 stu10
5.7 第七种方法 less (了解)
[root@oldboyedu-50 logs]# less -N /oldboy/ngingx.conf
第6章 运行级别及iptables补充
6.1 运行级别补充
查看运行级别 runlevel
切换 init
6.2 关闭iptable
装完Centos系统后,希望iptables,仅关闭3运行级别 怎么做
[root@oldboyedu-50 logs]# chkconfig |grep "ipt" ##查看 iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@oldboyedu-50 logs]# chkconfig --level 3 iptables off ##关闭3 [root@oldboyedu-50 logs]# chkconfig |grep "ipt" ##关闭后检查 iptables 0:off 1:off 2:on 3:off 4:on 5:on 6:off
第7章 单独取一列命令补充
已知如下命令及结果:
[oldboy@test ~]$ echo "I am oldboy,myqq is 31333741">>oldboy.txt
[oldboy@test ~]$ cat oldboy.txt
I am oldboy,myqq is 31333741
创建环境
mkdir /oldboy echo "I am oldboy,myqq is 31333741">/oldboy/oldboy.txt
7.1 方法一 sed |awk
[root@oldboyedu-50 oldboy]# sed 's#,# #g' oldboy.txt |awk '{print $3,$6}' oldboy 31333741
7.2 方法二 tr | awk
tr sed命令的阉割版
tr 一对一的替换
[root@oldboyedu-50 oldboy]# tr "," " " <oldboy.txt |awk '{print $3,$6}' oldboy 31333741
7.3 方法三 tr | cut
-d 指定分隔符
-f 某一列
[root@oldboyedu-50 oldboy]# tr "," " " < oldboy.txt |cut -d " " -f3,6 oldboy 31333741
7.4 方法四 sed | cut
[root@oldboyedu-50 oldboy]# sed 's#,# #g' oldboy.txt |cut -d " " -f3,6 oldboy 31333741
7.5 方法五 awk
-F 指定新的分隔符
$NF 表示最后一列
[root@oldboyedu-50 oldboy]# awk -F "[, ]" '{print $3,$6}' oldboy.txt oldboy 31333741
7.6 方法六 sed
[root@oldboyedu-50 oldboy]# sed 's#I am ##g' oldboy.txt |sed 's#,myqq is # #g' oldboy 31333741
第8章 认识wc命令
8.1 统计信息
wc 统计文件的信息
[root@oldboyedu-50 oldboy]# wc /etc/services 统计文件的信息 10774 58108 641020 /etc/services [root@oldboyedu-50 oldboy]# wc -l /etc/services 只看有多少行 10774 /etc/services
8.2 统计总数
统计出/etc目录下 以.conf 结尾的文件的数量
[root@oldboyedu-50 oldboy]# find /etc/ -type f -name "*.conf" |wc -l 195
第9章 egrep
过滤出/etc/services 文件包含3306或1521两数据库端口的行的内容。
| 扩展正则表达式 egrep ==grep -E
[root@oldboyedu-50 oldboy]# grep -E "3306|1521" /etc/services mysql 3306/tcp # MySQL mysql 3306/udp # MySQL ncube-lm 1521/tcp # nCube License Manager ncube-lm 1521/udp # nCube License Manager [root@oldboyedu-50 oldboy]# egrep "3306|1521" /etc/services mysql 3306/tcp # MySQL mysql 3306/udp # MySQL ncube-lm 1521/tcp # nCube License Manager ncube-lm 1521/udp # nCube License Manager
- 还没有人评论,欢迎说说您的想法!