五一作业-day02
文章目录
- 1. 每日基操
- 2. 模拟故障
- 2.1 **remove regular empty file 是否删除普通文件(空的)?**
- 2.2 **is a directory xxx是一个目录**
- 2.3 **xxx not a directory 不是一个目录**
- 2.4 Can't open file for writing
- 2.5 **No write since last change**
- 3. 习题
- 4. **进阶习题**
1. 每日基操
[ ] 创建一个空文件,批量创建多个空文件。
[ ] 创建一个目录,创建多个目录,创建多层目录。
[ ] 编辑文件内容vim快捷键。
[ ] 移动到第一行,最后一行,某一行。
[ ] 复制,删除,粘贴操作。
[ ] 在文件中查找内容,显示文件行号。
[ ] 查看文件内容,对文件内容进行过滤。
[ ] 显示目录内容,显示目录本身属性。
[ ] 可以通过ls判断出目标是文件,目录还是软链接。
[ ] 可以通过ls查看文件或目录的属性信息。
[ ] 删除文件,删除目录。
[ ] 对文件或目录进行重命名。
[root@oldboy99-Kylin ~/oldboy]# touch test01.txt
[root@oldboy99-Kylin ~/oldboy]# touch test{02..05}.txt
[root@oldboy99-Kylin ~/oldboy]# ls
02-【awk练习文件】access-服务的访问日志-v3.zip secure-20161219 sort.txt test03.txt test.txt
access.log secure-20161219.zip test01.txt test04.txt uniq.txt
awk.txt sort2.txt test02.txt test05.txt
[root@oldboy99-Kylin ~/oldboy]# mkdir dir
[root@oldboy99-Kylin ~/oldboy]# mkdir dir{01..05}
[root@oldboy99-Kylin ~/oldboy]# ls
02-【awk练习文件】access-服务的访问日志-v3.zip dir01 dir05 sort.txt test04.txt
access.log dir02 secure-20161219 test01.txt test05.txt
awk.txt dir03 secure-20161219.zip test02.txt test.txt
dir dir04 sort2.txt test03.txt uniq.txt
[root@oldboy99-Kylin ~/oldboy]# mkdir -p dir/d01/d02/d03
[root@oldboy99-Kylin ~/oldboy]# tree dir
dir
└── d01└── d02└── d033 directories, 0 files
[root@oldboy99-Kylin ~/oldboy]# vim test01.txt
[root@oldboy99-Kylin ~/oldboy]# vim test01.txt
[root@oldboy99-Kylin ~/oldboy]# grep '山东' -n
^C
[root@oldboy99-Kylin ~/oldboy]# grep '山东' -n test01.txt
2:山东
3:山东
4:山东
5:山东
6:山东
7:山东
8:山东
9:山东
10:山东
11:山东
12:山东
13:山东
14:山东
15:山东
16:山东
68:山东
[root@oldboy99-Kylin ~/oldboy]# cat test01.txt |grep '山东'
山东
山东
山东
山东
山东
山东
山东
山东
山东
山东
山东
山东
山东
山东
山东
山东
[root@oldboy99-Kylin ~/oldboy]# ls
02-【awk练习文件】access-服务的访问日志-v3.zip dir01 dir05 sort.txt test04.txt
access.log dir02 secure-20161219 test01.txt test05.txt
awk.txt dir03 secure-20161219.zip test02.txt test.txt
dir dir04 sort2.txt test03.txt uniq.txt
[root@oldboy99-Kylin ~/oldboy]# ll -d ~/oldboy/
drwxr-xr-x 8 root root 4096 5月 5 16:49 /root/oldboy/
[root@oldboy99-Kylin ~/oldboy]# ls
02-【awk练习文件】access-服务的访问日志-v3.zip dir01 dir05 sort.txt test04.txt
access.log dir02 secure-20161219 test01.txt test05.txt
awk.txt dir03 secure-20161219.zip test02.txt test.txt
dir dir04 sort2.txt test03.txt uniq.txt
[root@oldboy99-Kylin ~/oldboy]# ll
总用量 113172
-rw-r--r-- 1 root root 3765999 4月 30 10:48 02-【awk练习文件】access-服务的访问日志-v3.zip
-rw-r--r-- 1 root root 58817074 9月 21 2017 access.log
-rw-r--r-- 1 root root 137 4月 30 10:19 awk.txt
drwxr-xr-x 3 root root 17 5月 5 16:44 dir
drwxr-xr-x 2 root root 6 5月 5 16:44 dir01
drwxr-xr-x 2 root root 6 5月 5 16:44 dir02
drwxr-xr-x 2 root root 6 5月 5 16:44 dir03
drwxr-xr-x 2 root root 6 5月 5 16:44 dir04
drwxr-xr-x 2 root root 6 5月 5 16:44 dir05
-rw-r--r-- 1 root root 51053780 2月 15 2017 secure-20161219
-rw-r--r-- 1 root root 2218287 4月 30 10:48 secure-20161219.zip
-rw-r--r-- 1 root root 46 4月 30 14:13 sort2.txt
-rw-r--r-- 1 root root 41 4月 30 14:02 sort.txt
-rw-r--r-- 1 root root 1372 5月 5 16:49 test01.txt
-rw-r--r-- 1 root root 0 5月 5 16:43 test02.txt
-rw-r--r-- 1 root root 0 5月 5 16:43 test03.txt
-rw-r--r-- 1 root root 0 5月 5 16:43 test04.txt
-rw-r--r-- 1 root root 0 5月 5 16:43 test05.txt
-rw-r--r-- 1 root root 1133 5月 4 12:24 test.txt
-rw-r--r-- 1 root root 209 4月 30 14:41 uniq.txt
[root@oldboy99-Kylin ~/oldboy]# ls ~/anaconda-ks.cfg
/root/anaconda-ks.cfg
[root@oldboy99-Kylin ~/oldboy]# ls ~/anaconda-ks.cfg -l
-rw------- 1 root root 2743 4月 23 18:49 /root/anaconda-ks.cfg
[root@oldboy99-Kylin ~/oldboy]# rm -f test*.txt
[root@oldboy99-Kylin ~/oldboy]# rm -rf dir*
[root@oldboy99-Kylin ~/oldboy]# ls
02-【awk练习文件】access-服务的访问日志-v3.zip awk.txt secure-20161219.zip sort.txt
access.log secure-20161219 sort2.txt uniq.txt
[root@oldboy99-Kylin ~/oldboy]# touch test.txt
[root@oldboy99-Kylin ~/oldboy]# mkdir test
[root@oldboy99-Kylin ~/oldboy]# ls
02-【awk练习文件】access-服务的访问日志-v3.zip awk.txt secure-20161219.zip sort.txt test.txt
access.log secure-20161219 sort2.txt test uniq.txt
[root@oldboy99-Kylin ~/oldboy]# mv test.txt a.txt
[root@oldboy99-Kylin ~/oldboy]# mv test/ ./t
[root@oldboy99-Kylin ~/oldboy]# ls
02-【awk练习文件】access-服务的访问日志-v3.zip a.txt secure-20161219 sort2.txt t
access.log awk.txt secure-20161219.zip sort.txt uniq.txt
2. 模拟故障
2.1 remove regular empty file 是否删除普通文件(空的)?
[root@oldboy99-Kylin ~/oldboy]# rm a.txt
rm:是否删除普通空文件 'a.txt'?
[root@oldboy99-Kylin ~/oldboy]# alias |grep 'rm'
alias rm='rm -i'
[root@oldboy99-Kylin ~/oldboy]# man rm
-i prompt before every removal # 每次删除时都提示
解决方法:
使用rm时不加选项会提示,因为与rm的别名有关。
2.2 is a directory xxx是一个目录
[root@oldboy99-Kylin ~/oldboy]# rm t
rm: 无法删除 't': 是一个目录
###################################
[root@oldboy99-Kylin ~/oldboy]# cat /tmp/
cat: /tmp/: 是一个目录
解决方法:
使用rm删除目录时需要加上-r,表示逐级递归删除目录。或使用其他命令时参数需要是文件而不是目录。或使用vi、vim编辑目录是会提示该警告。
2.3 xxx not a directory 不是一个目录
[root@oldboy99-Kylin ~/oldboy]# mv a.txt ./a.txt/b.txt
mv: 访问 './a.txt/b.txt' 失败: 不是目录
[root@oldboy99-Kylin ~/oldboy]# ls ./a.txt/b.txt
ls: 无法访问 './a.txt/b.txt': 不是目录
解决方法:
使用mv或ls时需要指定目标路径,路径错误时会报错。
2.4 Can’t open file for writing
解决方法:
在vim使用时,路径错误或文件不存在会报错。
2.5 No write since last change
解决方法:
在vim中,编辑了文件但是没有保存就退出。使用‘w’保存或用‘!’强制退出。
3. 习题
#### 1.2.1.25 如何删除一个非空目录/tmp? B
del /tmp/*
rm -rf /tmp
rm -Ra /tmp/*
rm -rf /tmp/*
#### 1.2.1.26 如果要列出一个目录下的所有文件需要使用命令行(C )
ls -l ls ls -a ls -d
#### 1.2.1.27 除非特别指定,cp /etc/hosts . 假定要拷贝的文件在下面那个目录下(D )
用户目录 home目录 root目录 当前目录
#### 1.2.1.28 用来分离目录名和文件名的字符是(B )
dash(-) slash(/) period(,) asterisk(*)
#### 1.2.2.1 rm命令可以删除目录和文件,其主要差别就是是否使用(-r )参数。
#### 1.2.2.2 (mv )命令可以移动目录或文件,还可以为文件或目录重命名。
#### 1.2.2.3 用(>> )符号将输出重定向内容附加在原文的后面
#### 1.2.2.4 只有(root )用户才能改变文件属主或群组关系。
#### 1.2.2.5 在Linux系统中,用来存放系统所需要的配置文件的目录是_/etc ___
#### 1.2.2.6 在使用手工的方式配置网络时,可通过修改_/etc/hostname___文件来改变主机名,若要配置该计算机的域名解析客户端(DNS),需配置_/etc/sysconfig/network-scripts/ifcfg-ens33 或 /etc/resolv.conf__文件。
#### 1.2.2.9 Linux下,复制/root/source到当前目录的命令是_cp /root/source ._
#### 1.2.2.10 将前一个命令的标准输出做为后一个命令的标准输入,称之为_管道_
#### 1.2.2.11 若要配置该计算机的域名解析客户端,需配置_网卡配置文件或/etc/resolv.conf文件_文件
#### 1.2.2.12 Linux系统查看文件内容是_cat_,_vim_,_less/more_命令
#### 1.2.2.13 _/sbin_目录用来存放系统管理员使用的管理程序
#### 1.2.3.5 创建目录 /data/oldboy,并在该目录下创建文件oldboy.txt, 然后在文件oldboy.tx里写入内容inet addr:10.0.0.8 Bcast:10.0.0.255 Mask:255.255.255.0(不包含引号)。
[root@oldboy99-Kylin ~]# mkdir -p /data/oldboy
[root@oldboy99-Kylin ~]# cd /data/oldboy
[root@oldboy99-Kylin /data/oldboy]# vim oldboy.txt
[root@oldboy99-Kylin /data/oldboy]# cat oldboy.txt
inet addr:10.0.0.8
Bcast:10.0.0.255
Mask:255.255.255.0#### 1.2.3.7 如何查看文件内容,命令有哪些?查看文件第1行到第3行,查看文件最后一行
cat/vim/less/more/head/tail/grep/awk
head -n3 oldboy.txt
tail oldboy.txt -n1#### 1.3.1.5 全面查看硬件信息的命令 D
cpuinfo
meminfo
cat /etc/fstab
dmidecode#### 1.4.1.1 vi保存退出命令 B
w!
wq!
q!
www
#### 1.4.1.2 vi移动光标到文件最后一行 A
G
g
ggg
4444
#### 1.4.1.3 vi删除一行的命令 A
dd
d
D
shift+4#### 1.4.1.4 在vi编辑器中的命令模式下,键入(B )可在光标当前所在行下添加一新行。
a
o
I
A
4. 进阶习题
#### 1.10.1.14 可以得出linux物理内存大小的命令包含(ABC)
cat /proc/meminfo free top dmidecode
#### 1.11.1.6 Linux查当前目录下30天以前的文件并移动到/tmp/下的命令:(多选) C
find . -mtime 30 -type f xargs mv {} /tmp/ \;
find . -mtime +30 -type xargs mv {} /tmp/ \;
find . -mtime +30 -type f -exec mv {} /tmp/ \;
find . -mtime +30 -type f -exec rm –rf {} \;
#### 1.11.4.13 如何查看占用端口8080的进程
[root@oldboy99-Kylin ~]# ss -lntup |grep '8080'
然后查询pid
[root@oldboy99-Kylin ~]# ps -ef |grep pid