Linux Shell learns to find UID less than 500 users

Source: Internet
Author: User

Recently I have been learning Linux, always feel a lot of learning, but learn and can use a lot of flexibility. Today, when studying VSFTPD, you need to add a built-in user (typically a user with a UID of less than 500) to the/etc/vsftpd/ftpusers or/etc/vsftpd/user_list. So, I have an idea, how can I get a list of users with a UID less than 500?

According to their own logic and ideas, wrote a script, as follows:

Write a script that identifies the user with a UID less than 500 in the/etc/passwd file and displays its user name.

---------------------------------------------------------------------------

#!/bin/bash
#
Sed ' s//--/g '/etc/passwd >/TMP/PASSWD
For i in ' cat/tmp/passwd '; Do
Touch/tmp/tmp.txt && echo $i >/tmp/tmp.txt
Sysid= ' Cat/tmp/tmp.txt | Cut-d:-F 3 '
If [$SYSID-lt 500]; Then
Sysname= ' Cat/tmp/tmp.txt | Cut-d:-F 1 '
Echo $SYSNAME
Rm-f/tmp/tmp.txt
Else
Continue
Fi
Done
Rm-f/tmp/tmp.txt
Rm-f/tmp/passwd

-----------------------------------------------------------------------------

After several modifications and debugging, it is found that the above functions can be achieved. Always feel this script is very poor, online must have a simpler wording, so on-line search, do not search do not know, a search scare jump. The original only need one line can be done:

cat/etc/passwd | Awk-f: ' $3<500 ' | Cut-f 1-d:

Through the above, summarized as follows:

1, do not mean to do a good job. Currently know is only fur, there are many things need to learn, need to improve.

2. The function of awk is really powerful, so we should study it well.

3, books, Web or video learning materials, read it is not important to understand, it is important to summarize in a timely manner, digestion and absorption.

4, only in this, record their own Linux learning path, always alert themselves.

This article is from the "My It Technology blog" blog, so be sure to keep this source http://pancho.blog.51cto.com/1587402/1544602

Linux Shell learns to find UID less than 500 users

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.