Linux Command usage

Source: Internet
Author: User
Linux Command Usage Note-general Linux technology-Linux programming and kernel information. The following is a detailed description. Today, someone in the group asked how to view the user group name of the local machine. There is a group command, but only the user group name of the running user can be viewed.
You can use cat/etc/group to view the information, but there is a little more information in it. You can try to overwrite the rest of the information, think about grep, use a regular expression, and read it for a while, I did not write it out. I asked in the irc of # ubuntu-cn, and the answer will be available. Answers from brother
Cat/etc/group | cut-d ":"-f1

After finding out, cut is quite powerful and useful for extracting information:
Us @ us-laptop :~ $ Cut -- help
Usage: cut [Option]... [file]...
Print the specified part from each file to the standard output device.

Parameters required for long options are also required when short options are used.
-B, -- bytes = the list only selects the specified bytes.
-C, -- characters = the list only selects the specified characters
-D, -- delimiter = delimiter specified <分界符> Place tabs as the region demarcation
-F, -- fields = the list only selects the specified fields and prints all
Rows that do not contain delimiters, unless
-S option is specified
-N (ignore)
-- Complement complements the placeholder of the selected byte, character, or field
-S, -- only-delimited does not print rows without delimiters
-- Output-delimiter = Specify the string <字符串> As output delimiters
Input delimiters are used by default.
-- Help: displays the help information and leaves
-- Version: displays the version information and leaves.
The cut-d ":"-f1 above
-D is used to specify the delimiter. The default Delimiter is TAB, and then-fN is used to specify the input field. Here, f1 is used to output the first field, that is, the user group name. Here N can have multiple fields, separated by commas. or use range. for example, 1-3.

Then you can use this command to view all the user names on the machine.
Cat/etc/shadow | cut-d ":"-f1
This shadow file contains information of the local user. One thing is that this file must be accessed with the root permission.

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.