Linux基礎測試--11道題

來源:互聯網
上載者:User

標籤:沒有   lease   拷貝   http   tail   tail命令   編輯   grep命令   退出   

000、建立一個目錄/data

 1 mkdir /data 

 

001、在/data 下面建立一個檔案oldboy.txt

 1 touch /data/oldboy.txt 

 

002、為oldboy.txt 增加內容為“I am studying linux.”

 1 vi /data/oldboy.txt #點按i鍵進入編輯模式 2 I am studying linux.  #點按ESC鍵退出編輯模式 3 ~                                                                                                                                                    4 ~                                                                                                                                                    5 ~                                                                                                                                                 
:wq

 

003、把oldboy.txt 檔案拷貝到/tmp 下

cp /data/oldboy.txt /tmp

 

004、把/data 目錄移動到/root 下

cp /data/oldboy.txt /tmp

 

005、進入/root 目錄下的data 目錄,刪除oldboy.txt檔案

cd /root/data
find -type f -name ‘oldboy.txt‘|xargs rm

 

006、接上題,退出到上一級目錄,刪除data 目錄

cd ..\rm -r  /root/data

 

007、已知檔案test.txt 內容為: 

1 test2 liyao3 oldboy

請給出輸出test.txt檔案內容時,不包括oldboy字串的命令

建立測試環境

1 [[email protected] /]# touch /data/test.txt2 [[email protected] /]# cd /data3 [[email protected] data]# vi test.txt               #建立環境4 [[email protected] data]# cat test.txt        #查看測試檔案5 test6 liyao7 oldboy

1、head命令       

1 [[email protected] data]# head -2 /data/test.txt2 test3 liyao

2、grep命令

1 [[email protected] data]# grep -v ‘oldboy‘ /data/test.txt2 test3 liyao

3、sed命令

1 [[email protected] data]# sed ‘/oldboy/d‘ /data/test.txt2 test3 liyao

 

008、請用一條命令完成建立目錄/oldboy/test,即建立/oldboy 目錄以及/oldboy/test目錄

 1、笨拙的寫法

mkdir /oldboy /oldboy/test

2、優雅地寫法

mkdir -p /oldboy/test

 

009、已知/tmp 下已經存在 test.txt 檔案,如何執行命令才能把/mnt/test.txt 拷貝到/tmp 下覆蓋掉 /tmp/test.txt,而讓系統不提示是否覆蓋(root 許可權下)。

  直接使用cp -f,失敗。

[[email protected] /]# cp /mnt/test.txt /tmpcp: overwrite `/tmp/test.txt‘? 

 1、首先想到即使使用cp -f 也會提示是否覆蓋,然後想到Linux別名機制:

1 [[email protected] /]# alias 2 alias cp=‘cp -i‘3 alias l.=‘ls -d .* --color=auto‘4 alias ll=‘ls -l --color=auto‘5 alias ls=‘ls --color=auto‘6 alias mv=‘mv -i‘7 alias rm=‘echo Please use more secure command‘8 alias which=‘alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde‘

可以看到Linux執行cp命令時候預設參數是-i,修改預設參數為-f(危險,僅作題用):

1 [[email protected] /]# touch /mnt/test.txt2 [[email protected] /]# cp /mnt/test.txt /tmp3 [[email protected] /]# 

可以看到,沒有提示直接覆蓋。

2、使用\

1 [[email protected] /]# \cp /mnt/test.txt /tmp2 [[email protected] /]# 

 

010、只查看 ett.txt 檔案(共 100 行)內第 20 到第 30 行的內容

  建立測試環境:

  1 [[email protected] /]# seq 100 >ett.txt  2 [[email protected] /]# cat ett.txt  3 1  4 2  5 3  6 4  7 5          #太長省略

1、使用head 、 tail命令

 1 [[email protected] /]# head -30 /ett.txt | tail -11 2 20 3 21 4 22 5 23 6 24 7 25 8 26 9 2710 2811 2912 30

2、使用sed命令

 1 [[email protected] /]# sed -n ‘20,30p‘ ett.txt 2 20 3 21 4 22 5 23 6 24 7 25 8 26 9 2710 2811 2912 30

 

 

#說明:以上代碼參考學習《老男孩教育36期預習視頻》

#https://linux.cn/

#https://linux.cn/article-2713-1.html

 

Linux基礎測試--11道題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.