1.一個(gè)目錄中有很多文件(ls -l 查看時(shí)好多屏),想用一條命令最快速度查看到最近更新的文件。如何看?
ls -rtl
2.在配置 apache 服務(wù)時(shí) 執(zhí)行了./configure --prefix=/application/apache2.2.17 來(lái)編譯 apche,在 make install 完成后,希望用戶訪問 apache 路徑更簡(jiǎn)單,需要給/application/apache2.2.17目錄做一個(gè)軟鏈接/application/apache,使得內(nèi)部開發(fā)或管理人員通過(guò)/application/apache 就可以訪問到 apache 的安裝目錄/application/apache2.2.17 下的內(nèi)容,請(qǐng)你給出實(shí)現(xiàn)的命令。
ln –s /application/apache2.2.17 /application/apache
3.已知 Nginx 服務(wù)的訪問日志按天記錄在服務(wù)器本地目錄/app/logs 下,由于磁盤空間緊張,現(xiàn)在要求只能保留最近 7 天的訪問日志!請(qǐng)問如何解決? 請(qǐng)給解決辦法或配置或處理命令。
00 00 * * * /usr/bin/find /app/logs -type f -mtime +7 |xargs rm -f &>/dev/null 或 >/dev/null 2>&1
00 00 * * * /usr/bin/find /app/logs -type f -mtime +7 –exec rm –f{} \; &> /dev/null 或 >/dev/null 2>&1
00 00 * * * rm -f $(find /app/logs -type f -mtime +7) &> /dev/null或 >/dev/null 2>&1
4.調(diào)試系統(tǒng)服務(wù)時(shí),希望能實(shí)時(shí)查看/var/log/messages 系統(tǒng)日志的更新,如何做?
tail –f /var/log/messages
tail –F
tailf /var/log/messages
三者區(qū)別:https://blog.csdn.net/qq_15037231/article/details/78404261?
5.打印輕量級(jí) web 服務(wù)的配置文件 nginx.conf 內(nèi)容的行號(hào)及內(nèi)容,該如何做?
cat –n nignx.conf
grep –n ‘.’ nginx.conf
awk ‘{print NR,$0}’ nginx.conf
vim :set nused ‘=’ nginx.confless –N nginx.conf
6.已知如下命令及結(jié)果:
[cms@test ~]$ echo "I am student,my qqcms is 31333741">>test.txt
現(xiàn)在需要從文件中過(guò)濾出“student”和“31333741”字符串,請(qǐng)給出命令。
grep –Eo ‘student|31333741’ test.txt
egrep –o ‘student|31333741’ test.txt
sed –r ‘s#am (.*),.*is (.*)#\1\2#g’ test.txt
awk –F ‘[ ,]’ ‘{print $3,$NF}’test.txt
7.問題:請(qǐng)問在一個(gè)命令上加什么參數(shù)可以實(shí)現(xiàn)下面命令的內(nèi)容在同一行輸出。
echo –n “hell world”;
8.如何快速查到 ifconfig 命令的全路徑(假如你不知道其路徑),請(qǐng)給出命令。
which ifconfig
whereis ifconfig
9.查找/tmp/目錄下所有文件,并把文件中的 www.baidu.com字符串替換成www.jd.com
find /tmp/ -type f |xargs sed‘s#www.baidu.com#www.jd.com#g‘
10.過(guò)濾出/etc/services 文件包含 3306 或 1521 兩數(shù)據(jù)庫(kù)端口的行的內(nèi)容。
grep -E ‘3306|1521’ /etc/services
egrep ‘3306|1521’ /etc/services
sed –nr ‘/3306|1521/p’ /etc/services
awk ‘/3306|1521/’ /etc/services
11.請(qǐng)將 ifconfig eth0 和 ip add 結(jié)果中的 eth0 網(wǎng)卡對(duì)應(yīng) ip 地址取出。
[root@oldboyedu ~]# ifconfig eth0eth0: flags=4163mtu 1500 inet 10.0.0.201 netmask 255.255.255.0 broadcast 10.0.0.255 inet6 fe80::9fdb:66ba:dc7f:3fe5 prefixlen 64 scopeid 0x20
[root@oldboyedu ~]# ip addr: eth0:mtu 1500 qdisc pfifo_fast state UP group default qlen 10 link/ether 00:0c:29:2a:ca:54 brd ff:ff:ff:ff:ff:ff inet 10.0.0.201/24 brd 10.0.0.255 scope global noprefixroute eth0
ifconfig eth0|sed -rn 's#.*t (.*) net.*#\1#gp'
ifconfig eth0|awk -F'[ :]+' 'NR==2{print $3}'
ip addr|awk -F'[ /]+' 'NR==9{print $3}'
12.如何賦予 first.txt 文件如下權(quán)限、用戶、用戶組屬性。-w--rw-rwx. 1 oldboy sa 24 Mar 13 11:46 oldboy.txtchmod 267 oldboy.txtchmod u=w g=rw o=rwx oldboy.txtchown oldboy.sa oldboy.txt
chown oldboy:sa oldboy.txt
chage sa oldboy.txt
13.某系統(tǒng)管理員需每天做一定的重復(fù)工作,請(qǐng)按照下列要求,編寫一個(gè)解決方案,請(qǐng)按步驟寫清楚每一步操作:(1)在下午 4:50 刪除/abc 目錄下的全部子目錄和全部文件。(2)每逢星期一下午五點(diǎn)將/data 目錄下的所有目錄和文件歸檔并壓縮為以當(dāng)天日期命名的tar.gz 結(jié)尾打包文件。
(1) 50 16 * * * /bin/rm –rf /abc/* >/dev/null 2>&1 腳本:
vim shanchu.sh
/bin/rm –rf /abc/*或#!/bin/sh cd /abc&& rm –rf ./*
50 16 * * * /bin/sh shanchu.sh >/dev/null 2>&1
(2) 00 17 * * 1 /bin/tar zcf ./$(date +\%F).tar.gz >/dev/null 2>&1
14.如何取得/etc/hosts 文件的權(quán)限對(duì)應(yīng)的數(shù)字內(nèi)容,如-rw-r--r-- 為 644,要求使用命令取得644 這樣的數(shù)字(不低于 2 種方法)。
stat /etc/hosts -c %a
stat /etc/hosts|awk -F'[0/]' 'NR==4{print $2}'
stat /etc/hosts|sed -nr 's#.*\(0(.*)/-.*#\1#gp'
16. 企業(yè)故障案例 :作為運(yùn)維工程師,你在工作中遇到的一個(gè)實(shí)際問題,情況是:一個(gè) lnmp 的服務(wù)器,站點(diǎn)目錄下所有的文件均被植入了如下內(nèi)容:(可用 A 代替此行內(nèi)容解答)包括圖片文件也被植入了,當(dāng)用戶網(wǎng)站打開時(shí)就會(huì)調(diào)用這個(gè)地址,顯示一個(gè)廣告,請(qǐng)問你如何解決。
第一步:備份
第二步:grep ‘A’ *find / -type f |xargs sed ‘s#A##g’
定位到文件內(nèi)容后,將其替換掉,確認(rèn)無(wú)誤再加-i 參數(shù)總結(jié)報(bào)告并查找故障原因,進(jìn)行針對(duì)性防護(hù)
17.請(qǐng)輸出當(dāng)前日期和時(shí)間、3 天前的日期、未來(lái) 10 天的日期。
date
date –d “-3 day” +%F
date –d “+10 day”
18.寫出 10 個(gè)以上 Linux 命令行中特殊字符及對(duì)應(yīng)含義。
1. 請(qǐng)說(shuō)出軟鏈接和硬鏈接的區(qū)別。硬鏈接不占用 inode 軟連接占用一個(gè) inode硬鏈接不可以跨文件系統(tǒng)創(chuàng)建,軟鏈接不影響刪除源文件對(duì)硬鏈接無(wú)影響,但是軟鏈接會(huì)失效硬鏈接不可以給目錄創(chuàng)建,軟連接行
2.描述 ls -lhi 輸出中,每一列的意義。
33631870 -rw-r--r--. 1 root root 21 Oct 6 2020 oldboy.txtinode 號(hào) 文件類型權(quán)限 selinux 標(biāo)識(shí)符等2. 什么是 PATH 環(huán)境變量,它有什么作用?PATH 是命令的搜索路徑