標籤:測試題 linux 老男孩
1.1 我想在/data/oldboyedu目錄下面建立一個oldboy.txt檔案
[[email protected]~]# cd /data/oldboyedu-bash: cd:/data/oldboyedu: No such file or directory
1.為何出現這樣的錯誤
答:沒有/data目錄或者沒有/data/oldboyedu/目錄
2.如何解決這個錯誤呢?
[[email protected]~]# mkdir -p /data/oldboyedu[[email protected]~]# cd /data/oldboyedu[[email protected]]# touch oldboy.txt
1.2 向oldboy.txt加入內容"I love studyingLinux." (不少於2種方法)
法一:[[email protected]]# echo ‘I love studying Linux.‘ >oldboy.txt[[email protected]]# cat oldboy.txtI lovestudying Linux.法二:[[email protected]]# cat >oldboy.txtI lovestudying linux.^C[[email protected]]# cat oldboy.txtI lovestudying linux.法三:[[email protected]]# vi oldboy.txt--a/i--esc--:wq法四:[[email protected]~]# cat >>oldboy.txt<<EOF> I lovestudying linux.> EOF
1.3 把/data 目錄複寫到/tmp目錄下
[[email protected]]# cp -r /data /tmp/[[email protected]]# ls /tmp9.txt b.txt data yum.log z.txt[[email protected]]# cp -a /data /tmp/cp:overwrite `/tmp/data/oldboyedu/oldboy.txt‘? y[[email protected]]# 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內容為:
trainningfanbingbinglidao
請給出輸出test.txt檔案內容時,不包含trainning字串的命令。
建立環境:法一:[[email protected]]# cat >>test.txt<<eof>training>fanbingbing> lidao> eof法二:[[email protected]]# echo "trainingfanbingbinglidao">test.txt[[email protected]]# cat test.txttrainingfanbingbinglidao不包含trainning字串的命令法一:[[email protected]]# sed -n ‘2,3p‘ test.txtfanbingbinglidao法二:[[email protected]]# head -3 test.txt|tail -2fanbingbinglidao法三:[[email protected]]# tail -3 test.txt|grep -v trainingfanbingbinglidao法四:[[email protected]]# grep -v ‘training‘ test.txtfanbingbinglidao法五:[[email protected]]# awk ‘NR==2,NR==3‘ test.txtfanbingbinglidao[[email protected]]# awk ‘{if(NR>=2&&NR<=3)print $0"\n"}‘test.txtfanbingbing lidao法六:[[email protected]~]# awk ‘{if(NR==2||NR==3) print $0"\n"}‘ test.txtfanbingbing lidao注意:[[email protected] ~]# awk‘{if(NR>=2||NR<=3) print $0"\n"}‘ test.txttraining fanbingbing lidao1.6 入職新公司,老大讓你在伺服器上限制rm命令,當使用者輸入rm 命令時候提示”rm command is not allowed touse.” 請問實現的步驟是?。
臨時修改:[[email protected]~]# alias rm=‘echo "alias rm=rm command is not allowed to use"‘[[email protected]~]# alias rmaliasrm=‘echo "alias rm=rm command is not allowed to use"‘[[email protected]~]# rm -f 1.txtalias 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建立
建立類比環境:[[email protected]~]# seq 20 120 >ett.txt法一:[[email protected]~]# head -40 ett.txt|tail -11法二:tail -72ett.txt|head -11法三:sed -n‘30,40p‘ ett.txt法四:awk‘NR==30,NR==40‘ ett.txtawk‘NR>=30&&NR<=40‘ ett.txt法五:awk‘{if(NR>=30&&NR<=40) print $0"\n"}‘ ett.txt注意:(取不出來)[[email protected] ~]# awk‘{if(NR==30||NR==40) print $0"\n"}‘ ett.txt49 591.8 把test.txt檔案中的trainning修改為oldboy.
法一:[[email protected]~]# sed -i ‘s#training#oldboy#g‘ test.txt[[email protected]~]# cat test.txtoldboyfanbingbinglidao法二:vi/vim test.txt --a/i--insert--esc--:wq
1.9 尋找出/data目錄下所有以.txt結尾的檔案,並且把檔案中的trainning修改為oldboy.
[[email protected]~]# find /data/ -type f -name "*.txt" |xargs sed -i‘s#training#oldboy#g‘[[email protected]~]# find /data/ -type f -name "*.txt" -exec sed -i‘s#training#oldboy#g‘ {} \;[[email protected]~]# sed -i ‘s#training#oldboy#g‘ `find /data/ -type f -name "*.txt"`[[email protected]~]# sed -i ‘s#training#oldboy#g‘ $(find /data/ -type f -name "*.txt")1.10 尋找/oldboy下所有7天以前以log結尾的大於1M的檔案複製到/tmp下。
法一:find /oldboy/ -type f -name "*.log"-mtime +7 -size +1M |xargs -i cp {} /tmp/法二:find /oldboy -type f -name "*.txt" -mtime+7 -size +1M -exec cp {} /tmp/ \;法三:cp ` find /oldboy -type f -name "*.txt" -mtime +7 -size+1M ` /tmp/ ===反引號法四:cp $( find /oldboy -type f -name "*.txt" -mtime+7 -size +1M) /tmp/法五:find /oldboy -type f -name "*.txt" -mtime+7 -size +1M|xargs cp -t /tmp/1.11 請描述buffer和cache的區別(附加題)?
答:buffer:把資料寫入記憶體,這時寫入資料的記憶體空間稱為緩衝區,簡稱緩衝;cache:從記憶體中讀取資料,這時讀取資料的記憶體空間稱為緩衝區,簡稱緩衝; 總結:寫緩衝,讀緩衝。
老男孩linux營運第一次測試題