• 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 的运行级别不同数字的含义?(附加题)

    1. 运行级别0-6

    0表示关机

    1表示单用户

    2 表示多用户但是没有NFS

    3 表示完整的多用户状态  命令行模式 命令模式

    4 没有使用

    5 图形化界面模式

    6 重启

    1. 如何查看运行级别

    runlevel命令

    1. 如何配置运行级别

    /etc/inittab文件

    1. 临时修改init命令

    init 5

    第十二题

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

    buffer:缓冲区,写buffer  数据写入到内存中的缓冲区

    cache:缓存区,读cache   从内存中的缓存区读取数据

  • 相关阅读:
    网站
    世上本无事,庸人自扰之
    mac系招聘BBS
    新浪微博语录帝摘录
    dwz jui
    cheap vps
    facebook的开发标准
    rails的一些插件
    租房宝
    在Z10上用3G
  • 原文地址:https://www.cnblogs.com/lyq863987322/p/7511649.html
Copyright © 2020-2023  润新知