Common linux commands (1) grep
Grep is used to find strings.
Case 1: Get the user's home directory
For example, if the user name is whuang, How can I obtain his home directory?
grep "^whuang:" /etc/passwd |awk -F : {'print $6'}
Case 2: Get the user id
grep "^whuang:" /etc/passwd |awk -F : {'print $3'}
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxjb2RlIGNsYXNzPQ = "hljs perl"> Case 3: Get the group id
grep "^whuang:" /etc/passwd |awk -F : {'print $4'}
Case 4: Get the group name of the specified user
grep "^whuang:" /etc/passwd |awk -F : {'print $4'}|xargs -i grep {} /etc/group|awk -F : {'print $1'}whuang
Case 5: Process for obtaining the specified port
netstat -anp |grep "^[a-z]\+[ ]\+0[ ]\+0[ ]\+[0-9\.]\+:80[ ]\+"|awk -F" " {'print $7'}|cut -d"/" -f1
Case 6
Grep 'like' test. c (in the file test. search for rows containing "like" in c) grep-n 'like' test. c (output row number) [root @ localhost awk-study] # grep-n 'like' test. c3: I like java hsf-txt
Note: When you use + to indicate multiple characters, you must add the escape character before +.