1.1 我想在/data/oldboyedu目录下面创建一个oldboy.txt文件

[root@oldboyedu~]# cd /data/oldboyedu
-bash: cd:/data/oldboyedu: No such file or directory

1.为何出现这样的错误

答:没有/data目录或者没有/data/oldboyedu/目录

2.如何解决这个错误呢?

[root@oldboyedu-36-02~]# mkdir -p /data/oldboyedu
[root@oldboyedu-36-02~]# cd /data/oldboyedu
[root@oldboyedu-36-02oldboyedu]# touch oldboy.txt

1.2 向oldboy.txt加入内容"I love studyingLinux." (不少于2种方法)

法一:
[root@oldboyedu-36-02oldboyedu]# echo 'I love studying Linux.' >oldboy.txt
[root@oldboyedu-36-02oldboyedu]# cat oldboy.txt
I lovestudying Linux.
法二:
[root@oldboyedu-36-02oldboyedu]# cat >oldboy.txt
I lovestudying linux.
^C
[root@oldboyedu-36-02oldboyedu]# cat oldboy.txt
I lovestudying linux.
法三:
[root@oldboyedu-36-02oldboyedu]# vi oldboy.txt--a/i--esc--:wq
法四:
[root@oldboyedu-36-02~]# cat >>oldboy.txt< I lovestudying linux.
> EOF

1.3 把/data 目录复制到/tmp目录下

[root@oldboyedu-36-02oldboyedu]# cp -r /data /tmp/
[root@oldboyedu-36-02oldboyedu]# ls /tmp
9.txt  b.txt data  yum.log  z.txt
[root@oldboyedu-36-02oldboyedu]# cp -a /data /tmp/
cp:overwrite `/tmp/data/oldboyedu/oldboy.txt'? y
[root@oldboyedu-36-02oldboyedu]# ls /tmp/
9.txt  b.txt data  yum.log  z.txt

1.4 说说这些特殊符号含义:  >> >  2> 2>>   #(井号) .(点) ..(两个点)

>>:1>>,追加标准输出重定向,不清除内容,新加内容到最后一行;
>:1>,标准输出重定向,清除旧内容,加入新内容;
2>:错误输出重定向;
2>>:错误追加输出重定向;
#:1)注释;2)代表root用户;
.:./,当前目录;
..:../ ,当前目录的上级目录;


1.5 test.txt内容为:

trainning
fanbingbing
lidao

请给出输出test.txt文件内容时,不包含trainning字符串的命令。

创建环境:
法一:
[root@oldboyedu-36-02oldboyedu]# cat >>test.txt<training
>fanbingbing
> lidao
> eof
法二:
[root@oldboyedu-36-02oldboyedu]# echo "training
fanbingbing
lidao">test.txt
[root@oldboyedu-36-02oldboyedu]# cat test.txt
training
fanbingbing
lidao
不包含trainning字符串的命令
法一:
[root@oldboyedu-36-02oldboyedu]# sed -n '2,3p' test.txt
fanbingbing
lidao
法二:
[root@oldboyedu-36-02oldboyedu]# head -3 test.txt|tail -2
fanbingbing
lidao
法三:
[root@oldboyedu-36-02oldboyedu]# tail -3 test.txt|grep -v training
fanbingbing
lidao
法四:
[root@oldboyedu-36-02oldboyedu]# grep -v 'training' test.txt
fanbingbing
lidao
法五:
[root@oldboyedu-36-02oldboyedu]# awk 'NR==2,NR==3' test.txt
fanbingbing
lidao
[root@oldboyedu-36-02oldboyedu]# awk '{if(NR>=2&&NR<=3)print $0"\n"}'test.txt
fanbingbing
 
lidao
法六:
[root@oldboyedu-36-02~]# awk '{if(NR==2||NR==3) print $0"\n"}' test.txt
fanbingbing
 
lidao
注意:
[root@oldboyedu-36-02 ~]# awk'{if(NR>=2||NR<=3) print $0"\n"}' test.txt
training
 
fanbingbing
 
lidao

1.6 入职新公司,老大让你在服务器上限制rm命令,当用户输入rm 命令时候提示”rm command is not allowed touse.” 请问实现的步骤是?。

临时修改:
[root@oldboyedu-36-02~]# alias rm='echo "alias rm=rm command is not allowed to use"'
[root@oldboyedu-36-02~]# alias rm
aliasrm='echo "alias rm=rm command is not allowed to use"'
[root@oldboyedu-36-02~]# rm -f 1.txt
alias rm=rmcommand is not allowed to use -f 1.txt
永久生效:
1)alias rm='echo rm command is not allowed to use'(临时生效)
2)用vim将1)的内容写入到/etc/profile文件的最后一行
3)用source /etc/profile命令使文件永久生效
4)去/root/.bashrc下将alias rm='rm -i'注释掉即#‘alias rm='rm -i'’

1.7 取出文件ett.txt 的第30到40行的内容。

注:ett.txt由seq 20 120 >ett.txt创建

创建模拟环境:
[root@oldboyedu-36-02~]# seq 20 120 >ett.txt
法一:
[root@oldboyedu-36-02~]# head -40 ett.txt|tail -11
法二:
tail -72ett.txt|head -11
法三:
sed -n'30,40p' ett.txt
法四:
awk'NR==30,NR==40' ett.txt
awk'NR>=30&&NR<=40' ett.txt
法五:
awk'{if(NR>=30&&NR<=40) print $0"\n"}' ett.txt
注意:(取不出来)
[root@oldboyedu-36-02 ~]# awk'{if(NR==30||NR==40) print $0"\n"}' ett.txt
49
 
59

1.8 把test.txt文件中的trainning修改为oldboy.

法一:
[root@oldboyedu-36-02~]# sed -i 's#training#oldboy#g' test.txt
[root@oldboyedu-36-02~]# cat test.txt
oldboy
fanbingbing
lidao
法二:vi/vim test.txt --a/i--insert--esc--:wq

1.9 查找出/data目录下所有以.txt结尾的文件,并且把文件中的trainning修改为oldboy.

[root@oldboyedu-36-02~]# find /data/ -type f -name "*.txt" |xargs sed -i's#training#oldboy#g'
[root@oldboyedu-36-02~]# find /data/ -type f -name "*.txt" -exec sed -i's#training#oldboy#g' {} \;
[root@oldboyedu-36-02~]# sed -i 's#training#oldboy#g' `find /data/ -type f -name "*.txt"`
[root@oldboyedu-36-02~]# sed -i 's#training#oldboy#g' $(find /data/ -type f -name "*.txt")

1.10 查找/oldboy下

所有7天以前以log结尾的大于1M的文件复制到/tmp下。

生成环境:(所用命令:dd if=/dev/zero of=1.log bs=1M count=3;touch-m ;date -s ;find cp -t ;du -sh)
[root@oldboyedu36-01 data]# date -s 20170501
Mon May  1 00:00:00 CST 2017
[root@oldboyedu36-01 data]# dd if=/dev/zero of=1.log bs=1M count=3
3+0 records in
3+0 records out
3145728 bytes (3.1 MB) copied, 0.00374874 s, 839 MB/s
[root@oldboyedu36-01 data]# du -sh 1.log
3.0M    1.log
[root@oldboyedu36-01 data]# touch -m {1..6}.log
[root@oldboyedu36-01 data]# date -s 20170509
Tue May  9 00:00:00 CST 2017

解题方法
法一:
[root@oldboyedu36-01 data]# find ./ -type f -name "?.log"-mtime +7 -size +1M |xargs cp -t /tmp/
[root@oldboyedu36-01data]# ll -h /tmp/
total 3072
-rw-r--r--. 1root root 3.1M May  9 00:02 1.log
[root@oldboyedu36-01data]# du -sh /tmp/
3.1M    /tmp/
法二:
[root@oldboyedu36-01data]# find ./ -type f -name "?.log" -mtime +7 -size +1M |xargs -i cp{}  /tmp/
法三:
[root@oldboyedu36-01data]# find ./ -type f -name "?.log" -mtime +7 -size +1M -exec cp {} /tmp/ \;
法四:
[root@oldboyedu36-01data]# cp `find ./-type f -name "?.log" -mtime +7 -size +1M` /tmp/ ===反引号
法五:
[root@oldboyedu36-01data]# cp $(find ./ -type f -name "?.log" -mtime +7 -size +1M |xargs)/tmp/

1.11 请描述buffer和cache的区别(附加题)?

 

答:
buffer:把数据写入内存,这时写入数据的内存空间称为缓冲区,简称缓冲;
cache:从内存中读取数据,这时读取数据的内存空间称为缓存区,简称缓存;
 总结:写缓冲,读缓存。