Examples of written test questions for Linux operation and maintenance engineers

1. How to filter out all first-level directories in oldboy under the known current directory (excluding subdirectories, that is, they can only be first-level directories)

Method 1: find ./ -type d -maxdepth 1
Method 2: ls -F
Method 3: ls -l | grep ^d
Method 4: ls -F | grep /$
Method 5: ls -l | grep -v ^-
Method 6: tree -L 1
Method 7: Differentiate files and directories based on color
Method 8: ls -l | sed -n /^d/p

2. There are many files in a directory (there are many screens when viewing with ls). I want to view the recently updated files as quickly as possible. How to view them?

ls -lrt /etc #The bottom file is the latest updated file
Parameter Description:
-r, –reverse #Reverse sorting
-t #Sort by modification time

3. It is known that the access logs of the apache service are recorded on a daily basis in the local directory /app/logs of the server. Due to the tight disk space, it is now required to retain only the access logs of the last 7 days! How to solve it?

Method or configuration or processing command (tip: you can start from the apache service configuration, or you can start from the generated log)

1>. Function realization of the service itself
2>.Manual deletion
find ./ -mtime +7 -type f -name “*.log” -exec rm -f {} /; #Find logs from 7 days ago and delete them

4. How to print the line number and content of the configuration file nginx.conf?

Method 1: cat -n nginx.conf
Method 2: less -N nginx.conf
Method 3: grep -n . nginx.conf #The . (dot) number here represents any single character, and -n adds a line number to each filtered line.

5. How to quickly return to the last directory?

cd – #Environment variable OLDPWD always records the last position

6. When debugging system services, I hope to view the updates of the system log /var/log/messages in real time. How to do this?

Method 1: tail -f /var/log/messages
Method 2: tail -F /var/log/messages # Compared with -f, the function of multiple retries is that the file does not exist and will continue to try.

7. After installing the system ( CentOS /RHEL), if you want to enable network file sharing to serve NFS, what should you do if it only starts at level 3?

chkconfig –level 3 nfs off

8. How to check how many lines there are in the /etc/services file?

Method 1: Use the command wc directly
wc -l  /etc/services
Method 2: Add line numbers to the file content
cat -n  /etc/services | tail -1
Method 3: sed -n '$=' /etc/services
Method 4: grep -n $ /etc/services | tail -1

9. Please filter out the IP address in ifconfig?

方法1:ifconfig eth1|grep “inet add”|cut -d’:’ -f2|cut -d’ ‘ -f1
方法2:ifconfig eth1|grep “inet addr”|awk -F: ‘{print $2}’|awk ‘{print $1}’
Method 3: ifconfig eth1|awk -F '[ :]+' 'NR==2 {print $4}'
Procedure 4:ifconfig eth0|sed -n '2p'|sed 's#^.*addr:##g'|sed 's# Bc.*$##g'

10. How to take out the permissions in /etc/inittab and print them in the form of the number 644

Method 1: stat /etc/inittab |sed -n '4p'|awk -F "[(/]" '{print $2}'
Method 2: stat -c %a /etc/inittab
方法3:ll /etc/passwd |cut -c 1-9|tr rwx- 4210|awk -F “” ‘{print $1+$2+$3 $4+$5+$6 $7+$8+$9}’

11. Advertising links are embedded in the files in the /tools directory. How to remove them?

Remove product placement:

sed -i ‘/<p class=”chromeframe”>You are using an outdated browser. Please <a href=”https:www.google.com//chrome//” rel=”external nofollow” target=”_blank”>upgrade your browser<//a> and try again.<//p>///d’ kaka

12. Print out the contents of the kaka file except for blank lines.

Method 1: grep -v “^$” kaka
Method 2: sed '/^$/d' kaka

13. Print the date 3 days ago in the format: 2016-05-06

方法1:date “+%F” -d “3 days ago”
Method 2: date “+%F” -d “-3 day”

Guess you like

Origin blog.csdn.net/yaxuan88521/article/details/133499608