day4、Linux基础题目
第一题
我想在/data/da 目录下面创建 一个 da.txt 文件
[root@ll ~]# cd /data/oldboyedu
-bash: cd: /data/oldboyedu: No such file or directory
1.为何出现这样的错误
因为没有这个目录
2.如何解决这个错误呢?
创建这两个目录:mkdir -p /data/da
第二题
接上题,向 da.txt 加入内容 "I love studying Linux." (不少于 2 种方法)
方法一
命令格式:echo "I love studying Linux." >> /data/da.txt
[root@ll-01 ~]# echo "I love studying Linux." >> /data/da.txt
[root@ll-01 ~]# cat /data/da.txt
I love studying Linux.
方法二
命令格式:cat >/data/da.txt <<EOF
> I love studying Linux.
> EOF
[root@ll-01 ~]# cat >/data/da.txt <<EOF
> I love studying Linux.
> EOF
[root@ll-01 ~]# cat /data/da.txt
I love studying Linux.
第三题
把/data 目录复制到 /tmp 目录下
命令格式:cp -r /data/ /tmp/
[root@ll-01 ~]# cp -r /data/ /tmp/
第四题
说说这些特殊符号含义: > >> 2> 2>> #(井号) .(点) ..(两个点)
>:标准输出重定向,先清除文件内容,再将新内容放入文件。
>>:追加输出重定向,不清除文件内容,将新内容放入文件末尾。
2>:错误输出重定向,先清除文件内容,再将命令错误的提示放入文件。
2>>:错误追加输出重定向,不清楚文件内容,将命令错误的提示追加到文件末尾。
#(号):Linux中的注释符号,
.(点):表示当前路径。
..(点点):表示上一层路径。
第五题
test.txt 内容为:
trainning
fanbingbing
lidao
请给出输出 test.txt 文件内容时,不包含 trainning 字符串的命令。
方法一
命令格式: tail -2 /test.txt
[root@ll-01 ~]# tail -2 /test.txt
fanbingbing
lidao
方法二
命令格式:sed '/trainning/d' /test.txt
[root@ll-01 ~]# sed '/trainning/d' /test.txt
fanbingbing
lidao
方法三
命令格式:grep -v " trainning " /test.txt
[root@ll-01 ~]# grep -v " trainning " /test.txt
fanbingbing
lidao
方法四
命令格式:awk '!/trainning/' test.txt
[root@ll-01 ~]# awk '!/trainning/' test.txt
fanbingbing
lidao
第六题
入职新公司,老大让你在服务器上限制 rm 命令,当用户输入 rm 命令时候提示”rm command is not allowed to use.” 请问实现的步骤是?。
第一步:
命令格式:alias rm='echo rm command is not allowed to use.'
[root@ll-01 ~]# alias rm='echo rm command is not allowed to use.'
[root@ll-01 ~]# rm test.txt
rm command is not allowed to use. test.txt
第二步:写入 /etc/profile 配置文件
[root@ll-01 ~]# echo "alias rm='echo rm command is not allowed to use.'" >> /etc/profile
第三步:生效
[root@ll-01 ~]# source /etc/profile
第七题
取出文件 ett.txt 的第 30 到 40 行的内容。
方法一
命令格式:sed -n '30,40p' /ett.txt
[root@ll-01 ~]# sed -n '30,40p' /ett.txt
30
31
32
33
34
35
36
37
38
39
40
方法二
命令格式:awk 'NR==30,NR==40' /ett.txt
[root@ll-01 ~]# awk 'NR==30,NR==40' /ett.txt
30
31
32
33
34
35
36
37
38
39
40
方法三
命令格式:head -40 /ett.txt |tail -11
[root@ll-01 ~]# head -40 /ett.txt |tail -11
30
31
32
33
34
35
36
37
38
39
40
第八题
把 test.txt 文件中的 trainning 修改为 lll.
方法一
命令格式:find /data/ -type f -name "test.txt" |xargs sed -i 's#trainning#lll#g'
[root@ll-01 ~]# find /data/ -type f -name "test.txt" |xargs sed 's#trainning#lll#g'
lll
fanbingbing
lidao
[root@ll-01 ~]# find /data/ -type f -name "test.txt" |xargs sed -i 's#trainning#lll#g'
方法二
命令格式:sed -i 's#trainning#lll#g' $(find /data/ -type f -name "test.txt")
[root@ll-01 ~]# sed 's#trainning#lll#g' $(find /data/ -type f -name "test.txt")
lll
fanbingbing
lidao
[root@ll-01 ~]# sed -i 's#trainning#lll#g' $(find /data/ -type f -name "test.txt")
方法三
命令格式:find /data/ -type f -name "test.txt" -exec sed -i 's#trainning#lll#g' {} ;
[root@ll-01 ~]# find /data/ -type f -name "test.txt" -exec sed -i 's#trainning#lll#g' {} ;
[root@ll-01 ~]# find /data/ -type f -name "test.txt" -exec sed 's#trainning#lll#g' {} ;
lll
fanbingbing
lidao
第九题
查找出/data 目录下所有以.txt 结尾的文件,并且把文件中的 trainning 修改为 lll.
命令格式:
find /data/ -type f -name "*.txt" |xargs sed -i 's#trainning#lll#g'
sed -i 's#trainning#lll#g' $(find /data/ -type f -name "*.txt")
find /data/ -type f -name "*.txt" -exec sed -i 's#trainning#lll#g' {} ;
第十题
查找/data 下所有以 log 结尾的大于 1M 的文件复制到/tmp 下。
命令格式:find /data -type f -name "*.log" -size +1M
方法1
cp $(find /data -type f -name "*.log" -size +1M ) /tmp
方法2
find /data -type f -name "*.log" -size +1M |xargs cp -t /tmp
方法3
find /data -type f -name "*.log" -size +1M |xargs -i cp {} /tmp
方法4
find /data -type f -name "*.log" -size +1M -exec cp {} /tmp ;
第十一题
什么是 linux 的运行级别,请描述 linux 的运行级别不同数字的含义?(附加题)
运行级别0-6
0表示关机
1表示单用户
2 表示多用户但是没有NFS
3 表示完整的多用户状态 命令行模式 命令模式
4 没有使用
5 图形化界面模式
6 重启
如何查看运行级别
runlevel命令
如何配置运行级别
/etc/inittab文件
临时修改init命令
init 5
第十二题
请描述 buffer 和 cache 的区别(附加题)?
buffer:缓冲区,写buffer 数据写入到内存中的缓冲区
cache:缓存区,读cache 从内存中的缓存区读取数据
- 使用 ETW 对 .NET 应用程序进行性能诊断
- ORB_SLAM论文解读
- Mono.Addins 插件式框架
- 通过多说服务器缓存加速Gravatar 头像,解决被墙问题
- asp.net mvc脚手架代码生成工具
- Page.FindControl方法找不到指定控件的原因
- Silverlight 2 DispatcherTimer和通过XAML创建UI元素
- 腾讯移动安全实验室发布《2013年手机安全报告》
- 自定义Unity 容器的扩展 --- Unity Application Block Event Broker
- LINQ to SQL集成到应用程序中需考虑的一些问题
- WCF的追踪分析工具——SvcPerf
- 解决七牛云存储缓存加速Gravatar 头像图片路径url 参数失效的问题
- 命令行解析的规则以及Command Line Parser Library
- 简单代码让WordPress 支持电子邮箱(Email)作为登录名
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法