day 11 第二关练习题

Day 11 第二关练习题
1.1 linux启动过程

    1. day 11 第二关练习题
      1.2 PATH
      目前遇到的环境变量(PS1 LANG PATH)
      PATH 存放的是linux下命令的路径(位置)
      [root@oldboyedu50-lnb ~]# echo $PATH
      /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

1.3 linux执行命令过程
1.3.1 是否是别名
1.3.2 在PATH中找命令 是否存在
1).提示
command not found
2).执行

1.4 小结:
1.4.1 linux启动过程
1.4.2 PATH作用
PS1 LANG PATH
1.4.3 linux执行命令过程
1.5 如何过滤出已知当前目录下oldboy中的所有一级目录(提示:不包含oldboy目录下面目录的子目录及隐藏目录,即只能是第一级目录)?
1.5.1 环境准备
[root@oldboyedu50-lnb /oldboy]# mkdir /oldboy -p
[root@oldboyedu50-lnb /oldboy]# cd /oldboy
[root@oldboyedu50-lnb /oldboy]# mkdir ext/oldboy test xiaodong xiaofan xingfujie -p
[root@oldboyedu50-lnb /oldboy]# touch jeacen oldboy wodi.gz yingsui.gz
[root@oldboyedu50-lnb /oldboy]# find
[root@oldboyedu50-lnb /oldboy]# ll

方法1-tree
[root@oldboyedu50-lnb /oldboy]# tree -dL 1
├── ext
├── test
├── xiaodong
├── xiaofan
└── xingfujie

5 directories

#-d 只显示目录
#-L level 最多显示多少层

1.5.2 方法2-find
[root@oldboyedu50-lnb /oldboy]# find -maxdepth 1 -type d
.
./xiaodong
./xiaofan
./test
./ext
./xingfujie

#-maxdepth 最大的深度 最多显示多少层

[root@oldboyedu50-lnb /oldboy]# find -maxdepth 1 -type d
.
./xiaodong
./xiaofan
./test
./ext
./xingfujie
[root@oldboyedu50-lnb /oldboy]# find -maxdepth 1 -type d -name "."
./xiaodong
./xiaofan
./test
./ext
./xingfujie

#! 排除 取反 非

1.5.3 方法3 d开头的
[root@oldboyedu50-lnb /oldboy]# ll |grep "^d"
drwxr-xr-x 3 root root 4096 Jul 19 23:59 ext
drwxr-xr-x. 2 root root 4096 Jul 16 19:24 test
drwxr-xr-x 2 root root 4096 Jul 19 23:59 xiaodong
drwxr-xr-x 2 root root 4096 Jul 19 23:59 xiaofan
drwxr-xr-x 2 root root 4096 Jul 19 23:59 xingfujie
[root@oldboyedu50-lnb /oldboy]# #^ 以....开头的行 三剑客使用 正则表达式

扫描二维码关注公众号,回复: 2325472 查看本文章

1.5.4 方法4 第2列大于1
[root@oldboyedu50-lnb /oldboy]# ll |awk '$2>1'
total 40
drwxr-xr-x 3 root root 4096 Jul 19 23:59 ext
drwxr-xr-x. 2 root root 4096 Jul 16 19:24 test
drwxr-xr-x 2 root root 4096 Jul 19 23:59 xiaodong
drwxr-xr-x 2 root root 4096 Jul 19 23:59 xiaofan
drwxr-xr-x 2 root root 4096 Jul 19 23:59 xingfujie

1.5.5 方法5 ls
[root@oldboyedu50-lnb /oldboy]# ls -F
alex.txt jeacen oldboy.txt test.sh t.sh.bak xiaodong/ xingfujie/
ext/ oldboy test/ t.sh wodi.gz xiaofan/ yingsui.gz
[root@oldboyedu50-lnb /oldboy]# #-F 不同类型的文件 加上不同的标记 目录/
[root@oldboyedu50-lnb /oldboy]# ls -F |grep "/"
ext/
test/
xiaodong/
xiaofan/
xingfujie/

[root@oldboyedu50-lnb /oldboy]# ls -ld */
drwxr-xr-x 3 root root 4096 Jul 19 23:59 ext/
drwxr-xr-x. 2 root root 4096 Jul 16 19:24 test/
drwxr-xr-x 2 root root 4096 Jul 19 23:59 xiaodong/
drwxr-xr-x 2 root root 4096 Jul 19 23:59 xiaofan/
drwxr-xr-x 2 root root 4096 Jul 19 23:59 xingfujie/

1.5.6 小结:
1.tree find
2.grep awk
3.ls
2.1/etc/目录为linux系统的默认的配置文件及服务启动命令的目录
2.1.1 a.请用tar打包/etc整个目录(打包及压缩)。
创建压缩包 (v==过程可省略)
tar zcvf /tmp/etc.tar.gz
查看压缩包
tar zctf /tmp/etc.tar.gz
解压
tar zxvf /tmp/etc.tar.gz
2.1.2 b.请用tar打包/etc整个目录(打包及压缩,但需要排除/etc/services文件)。
[root@oldboyedu50-lnb /tmp]# tar zcf /tmp/etc-pai.tar.gz /etc/ --exclude /etc/services
tar: Removing leading `/' from member names
[root@oldboyedu50-lnb /tmp]# tar tf /tmp/etc-pai.tar.gz |grep services 排除掉
etc/init/readahead-disable-services.conf

tar zcf /tmp/etc-pai.tar.gz /etc/ --exclude /etc/services

--exclude-from name.txt

name.txt
oldboy.txt
/oldboy/oldboy

2.1.3 c.请把a点命令的压缩包,解压到/tmp指定目录下(最好只用tar命令实现)。
tar xf /tmp/etc.tar.gz -C /opt/
ll /opt/
windows 压缩 winrar/好压/2345压缩
linux 打包压缩 tar

2.2 创建压缩包
tar zcvf /tmp/etc.tar.gz /etc/
压缩之后的放在那里 目标
#z gzip 通过gzip 软件压缩
#c create 创建包
#v verbose 显示过程
#f file 指定文件

tar zcf /tmp/etc.tar.gz /etc/
2.3 查看压缩包内容
tar ztf /tmp/etc.tar.gz
#t list 显示压缩包内容

2.4解压
tar zxf etc.tar.gz
#x extract 解压
2.5小结
2.5.1创建压缩包 :tar zcf
2.5.2查看 tar tf
2.5.3解压 tar xf
[root@oldboyedu50-lnb /tmp]# ll /tmp/etc.tar.gz查看/tmp下压缩包
-rw-r--r-- 1 root root 9734648 Jul 20 01:41 /tmp/etc.tar.gz
2.6解压到/opt指定目录
[root@oldboyedu50-lnb /tmp]# tar xf /tmp/etc.tar.gz -C /opt/
[root@oldboyedu50-lnb /tmp]# ll /opt/
total 12
drwxr-xr-x. 2 root root 4096 Jul 11 01:16 data
drwxr-xr-x 78 root root 4096 Jul 19 20:43 etc
drwxr-xr-x. 2 root root 4096 Mar 26 2015 rh

2.7打包压缩:
2.7.1创建
2.7.2查看
2.7.3解压
2.7.4解压到指定位置
2.7.5排除(了解)

3.1假如当前目录是# cd /etc/sysconfig/network-scripts/ 则 # cd /tmp/如何回到上一次所在目录
cd - 进入到上一次所在的位置
cd - === cd $OLDPWD
cd. 当前目录 cp/mv
cd.. 上一级目录
cd ~ ==== cd 当前用户家目录

3.2 创建文件显示最新文件
[root@oldboyedu50-lnb /tmp]# cd /etc/
[root@oldboyedu50-lnb /etc]# touch oldboy.txt

ls -lrt
#-r 逆序
#-t 按照修改时间

3.3 调试系统服务时,希望能实时查看系统日志/var/log/secure的更新,如何做?
3.3.1 tail -f /var/log/secure ==== tailf /var/log/secure
echo /var/log/secure >> oldboy.txt
-f
-F == -f --try 如果文件不存在 会不断重试

3.4 打印配置文件nginx.conf内容的行号及内容,该如何做?

[root@oldboyedu50-lnb /oldboy]# #{1..5} 生成序列
[root@oldboyedu50-lnb /oldboy]# echo {1..10}
1 2 3 4 5 6 7 8 9 10
[root@oldboyedu50-lnb /oldboy]# echo {01..10}
01 02 03 04 05 06 07 08 09 10
[root@oldboyedu50-lnb /oldboy]# echo stu{01..10} |xargs -n1
stu01
stu02
stu03
stu04
stu05
stu06
stu07
stu08
stu09
stu10
[root@oldboyedu50-lnb /oldboy]# echo stu{01..10} |xargs -n1 >nginx.conf
3.4.1方法1 cat
[root@oldboyedu50-lnb /oldboy]# cat -n nginx.conf
1 stu01
2 stu02
3 stu03
4 stu04
5 stu05
6 stu06
7 stu07
8 stu08
9 stu09
10 stu10

3.4.2方法2 vim
:set nu #显示行号 (最后一行输入)
#nu === number
:set nonu #取消显示行号

3.5总结:
3.5.1Linux启动流程
3.5.2PATH作用
3.5.3查找 grep awk
3.5.4打包压缩 :创建 查看 解压 解压到xxx
3.5.5基础命令
3.5.6显示行号
tar命令经典故障 Removing leading /' from member names<br/>创建压缩包都见过这个提示吧?<br/>[root@oldboyedu50-lnb /oldboy]# tar zcf /tmp/etc.tar.gz /etc/<br/>tar: Removing leading/' from member names
什么意思呢?
翻译:
Removing leading `/' from member names
把压缩包中的开头的/(根)删除掉

背后过程:
打包压缩过程中 文件或目录 绝对路径---->相对路径
打包的时候:
/etc/host
/etc/profile
压缩包中样子
etc/host
etc/profile
这个提示原因:
防止解压的时候覆盖源文件。

vmware 经典故障:

该虚拟机似乎正在使用中。
如果该虚拟机未在使用,请按“获取所有权(T)”按钮获取它的所有权。否则,请按“取消(C)”按钮以防损坏。
配置文件: G:\VMware\模板机01\老男孩教育50期-模板机01.vmx。
方法1.重启计算机
方法2.通过everything 搜索 .lck 删除 虚拟机名称.lck 目录 重启vmware

猜你喜欢

转载自blog.51cto.com/13859649/2149106
今日推荐