Shell interview questions have been summarized. let's take a look at it. there are 12 excellent shell command classic interview questions.
Shell interview questions are summarized. let's take a look.
1. text analysis
Retrieve the number of times the shell appears in the password
Result of the first method:
4/bin/bash
1/bin/sync
1/sbin/halt
31/sbin/nologin
1/sbin/shutdown
Result of Method 2:
/Bin/sync 1
/Bin/bash 1
/Sbin/nologin 30
/Sbin/halt 1
/Sbin/shutdown 1
2. file sorting
Employee ID and name are recorded in the employee file
Employee.txt:
100 Jason Smith
200 John Doe
300 Sanjay Gupta
400 Ashok Sharma
Bonus file records employee ID and salary
Bonus.txt:
100 $5,000
200 $500
300 $3,000
400 $1,250
Merge the two files and output them as follows:
Processing result:
400 ashok sharma $1,250
100 jason smith $5,000
200 john doe $500
300 sanjay gupta $3,000
3. print the swap partition size of the local machine
Processing result:
Swap: 1024 M
4. user cleanup
Clear all users except the current login user
Processing result:
23:00:17 up, 1 user, load average: 0.02, 0.05, 0.02
User tty from login @ IDLE JCPU PCPU WHAT
Root pts/1 192.168.1.100 0.00 s 10.75 s 0.00 s w
Only yourself is left on the machine :)
5. How long have the root user logged on today?
Processing result:
Root logon today: 0.06 hour
6. print the current sshd port and process id
Processing result:
Sshd Port & amp; pid: 22 5412
7. output the time used to create 20000 directories on the local machine
Processing result:
Real 0m3. 367 s
User 0m0. 066 s
Sys 0m1. 925 s
8. print the number of executable files that can be used by the root user.
Processing result:
Root's bins: 2306
9. write a shell script to transfer files larger than 10 kb in the current directory to the/tmp Directory #/bin/sh # Programm:
# Using for move currently directory to/tmp for FileName in 'ls l | awk '$5> 10240 {print $9} ''do
Mv $ FileName/tmp done ls al/tmp echo "Done! "
10. write a shell script to get the network address of the local machine.
For example, if the local IP address is 192.168.100.2/255.255.255.0, then its network address is 192.168.100.1/255.255.255.0 Method 1 :#! /Bin/bash
# This script print ip and network
File = "/etc/sysconfig/networkscripts/ifcfgeth0" if [f $ file] then
IP = 'grep "IPADDR" $ file | awk F "=" '{print $2}' MASK = 'grep "NETMASK" $ file | awk F "= "'{ print $2} ''echo "$ IP/$ MASK" exit 1 fi
11. use Shell programming to determine whether a file is a character device file. if it is copied to the/dev directory.
Reference Program :#! /Bin/sh FILENAME =
Echo "Input file name:" read FILENAME if [c "$ FILENAME"] then
Cp $ FILENAME/dev fi
12. design a shell program, add a new group named class1, and add 30 users to the group. The Username format is stdxx, where xx ranges from 01 to 30.
Reference answer :#! /Bin/sh I = 1
Groupadd class1 while [$ I le 30] do
If [$ I le 9] then USERNAME = stu0 $ {I} else
USERNAME = stu $ {I} fi
Useradd $ USERNAME mkdir/home/$ USERNAME
Chown R $ USERNAME/home/$ USERNAME chgrp R class1/home/$ USERNAME I =$ ($ I + 1) done