First, remove the number of occurrences of the shell in the/etc/passwd file: Here is a partial content of a/etc/passwd file. The topic asks to take out the shell and counts the number, the shell refers to the back/bin/bash,/sbin/nologin and so on, as follows/bin/bash appears 12 times,/sbin/nologin appears 3 times. hyn:x:525:500::/home/hyn:/bin/bash ljlxx:x:526:500::/home/ljlxx:/bin/bash lzj:x : 527:500::/home/lzj:/bin/bash wfly:x:528:500::/home/wfly:/bin/bash squid:x:23:23::/var/ Spool/squid:/sbin/nologin wyj:x:529:500::/home/wyj:/bin/bash qemu:x:107:107:qemu user:/:/ Sbin/nologin radvd:x:75:75:radvd User:/:/sbin/nologin dungbee:x:530:500::/home/dungbee:/ Bin/bash mysql:x:27:27:mysql Server:/var/lib/mysql:/bin/bash scidb:x:531:531::/home/scidb :/bin/bash postgres:x:532:532::/home/postgres:/bin/bash crane:x:533:533::/home/crane:/ Bin/bash test:x:534:534::/home/test:/bin/bash hguser:x:535:535::/home/hguser:/bin/bash Reference Answer: cat/etc/passwd|awk-f: ' {print $7} ' |sort|uniq-c parsing: UsingAwk splits the content by a colon, printing out the 7th column after the split, which is the shell's column. Then call the sort command to sort and use uniq-c to count the occurrences of each shell. second, document collation problem: Employee document records the work number and name employee.txt: 100 Jason Smith 200 John Doe 300 Sanjay Gupta 400 Ashok sharmabonus file record number and payroll bonus.txt: $5,000 200 300 $3,000 400 $1,250 requires the merging of two files and outputting the following processing results: 400 Ashok Sharma $1,250 100 Jason Smith $5,000 200 John Doe $500 300 Sanjay Gupta $3,000 Reference answer: Paste Employee.txt bonus.txt | awk ' {print $1,$2,$3,$5} ' |tr ' [: Upper:] ' [: Lower:] ' |sort-k 2 parse: Here are several commands, including paste,awk,tr and sort. The Paste command is used to merge the peer data of multiple files, such as the above two files employee and bonus call paste after merging into the three Jason Smith 100 $5,000 200 John Doe 200 300 Sanjay Gupta 300 $3,000 & nbsp; 400 Ashok Sharma 400 $1,2The paste command can use-D to specify which symbols to join when merging. For example, paste-d: Employee bonus turns out to be similar to the smith:100 $5,000 of Jason. The default merge symbol is the tab symbol. Awk is used to extract the remaining 4 columns except for the tab symbol. The TR command converts all uppercase characters in a string to lowercase characters. The sort command sorts the characters. Sort-k 2 means sorting by the 2nd field of the file, where the second field is the name, so it is sorted by name in ascending order. If you want to sort in descending order, use Sort-k 2r. printing native Swap partition size problem: Print native swap partition size, output as follows swap:1024m reference answer: top-n 1|grep swap|sed ' s/k.*//' |awk ' {print $1,$2/ "M"} ' parse: The top command shows system resource usage, and-N 1 means only 1 calls. grep swap selects the row in which the swap is located. After the grep command executes, the result may be as follows: swap:16779884k total, 0k used, 16779884k free, The 3268200k Cached sed command is used for some regular matching of strings, where substitution parameters are used, and the 1th K and subsequent characters are replaced with blanks. Thus, after SED executes, the result is: swap:16779884 awk command output, divide the second parameter by 1000. , user cleanup problem: Clears all users except the current logged-on user. Reference answer: kill $ (who-u|grep-v ' whoami ' |awk ' {print $6} ' |sort-u) Parse: who-u shows all current users. Grep-v Select all users other than the currently logged-on user. awk prints the user process ID. Sort-u will delete the same row. Finally, terminate with the KILL command.
Classic Shell face question finishing