Basic knowledge of Linux three

Source: Internet
Author: User
Tags echo command stdin

1. List the user name of all logged-in users on the current system, note: The same user logged in multiple times, only once.

Who | cut-d '-f1 | uniq

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/86/38/wKiom1e5FVrCryZ0AAAiDIMbPKs527.jpg-wh_500x0-wm_3 -wmp_4-s_2131308817.jpg "title=" 1.jpg "alt=" Wkiom1e5fvrcryz0aaaidimbpks527.jpg-wh_50 "/>

2. Remove the information about the user who last logged in to the current system.

Last | tail-3 |head-1

If a login user name appears, you can use the ID command to see more details.

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/86/38/wKiom1e5FgHgqKL-AABTf_RNzuc174.jpg-wh_500x0-wm_3 -wmp_4-s_2569242334.jpg "title=" 1.jpg "alt=" Wkiom1e5fghgqkl-aabtf_rnzuc174.jpg-wh_50 "/>


3. Remove the shell that is the user's default shell on the current system.

cut-d:-f7/etc/passwd | uniq-c | sort-n | tail-1

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/86/38/wKioL1e5F6jhpOYKAAA-pCvG7uM489.jpg-wh_500x0-wm_3 -wmp_4-s_2777993383.jpg "title=" 1.jpg "alt=" Wkiol1e5f6jhpoykaaa-pcvg7um489.jpg-wh_50 "/>


4, the third field in the/etc/passwd the value of the largest 10 users of the information is changed to uppercase and saved to the/tmp/maxusers.txt file.

sort-n-K 3-t ': '/etc/passwd | tail-n | tr [A-z] [a-z] >/tmp/maxusers.txt

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/86/38/wKioL1e5GbPwxRKTAAJHJTLatFs071.jpg-wh_500x0-wm_3 -wmp_4-s_3067460216.jpg "title=" 1.jpg "alt=" Wkiol1e5gbpwxrktaajhjtlatfs071.jpg-wh_50 "/>


5, take out the IP address of the current host, hint: The result of ifconfig command is sliced.

Ifco nfig | grep ' inet ' | grep-o ' [0-9]\+.* ' | cut-d '-f1 | grep ^1

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/86/38/wKiom1e5IqWD8kJhAABRsnVw6sI740.jpg-wh_500x0-wm_3 -wmp_4-s_2751011357.jpg "title=" 1.jpg "alt=" Wkiom1e5iqwd8kjhaabrsnvw6si740.jpg-wh_50 "/>


6. List the file names of all files ending with. conf in/etc directory and convert their names to uppercase and save them to the/tmp/etc.conf file.

ls/etc | grep ". conf$" | tr ' A-Z ' A-Z ' >/tmp/etc.conf

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/86/39/wKiom1e5JBPB_qDZAAE2pCnrix0855.jpg-wh_500x0-wm_3 -wmp_4-s_2784735318.jpg "title=" 1.jpg "alt=" Wkiom1e5jbpb_qdzaae2pcnrix0855.jpg-wh_50 "/>


7. Displays the total number of sub-directories or files in the/var directory.

ls-l/var | grep "^[d|-]" | wc-l

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/86/39/wKioL1e5Ja6DFcJOAAApnfyvgws793.jpg-wh_500x0-wm_3 -wmp_4-s_4104222600.jpg "title=" 1.jpg "alt=" Wkiol1e5ja6dfcjoaaapnfyvgws793.jpg-wh_50 "/>


8. Remove the names of the 10 groups with the smallest number of the third field in the/etc/group file.

sort-n-T ":"-K 3/etc/group | Head-n 10 | cut-d:-f1

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/86/39/wKioL1e5J7OhKqLmAABhmDZw5dA511.jpg-wh_500x0-wm_3 -wmp_4-s_2526325230.jpg "title=" 1.jpg "alt=" Wkiol1e5j7ohkqlmaabhmdzw5da511.jpg-wh_50 "/>


9, the contents of the/etc/fstab and/etc/issue files are merged into the same content and saved to the/tmp/etc.test file.

cat/etc/fstab/etc/issue >>/tmp/etc.test

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/86/39/wKioL1e5KQGAhH-8AANDyypN1w0219.jpg-wh_500x0-wm_3 -wmp_4-s_1236835706.jpg "title=" 1.jpg "alt=" Wkiol1e5kqgahh-8aandyypn1w0219.jpg-wh_50 "/>


10. Summarize the methods used to describe the user and group management commands and complete the following exercises:

(1), create group distro, its GID is 2016;

groupadd-g distro

(2), create user Mandriva, whose ID number is 1005; basic group is distro;

useradd-u 1005-g distro Mandriva

(3), create user Mageia, whose ID number is 1100, home directory is/home/linux;

useradd-u 1100-d/home/linux Mageia

(4), to the user mageia add password, password for mageedu;

echo "magedu" | passwd--stdin Mageia

(5), delete Mandriva, but retain their home directory;

Userdel Mandriva

(6), create user Slackware, its ID number is 2002, the basic group is distro, additional group Peguin;

Groupadd Peguin

Useradd-u 2002-g distro-g Peguin Slackware

(7), modify the Slackware default shell for/BIN/TCSH;

usermod-s/bin/tcsh slackware

(8), add additional Group admins for user Slackware;

groupadd Admins

Usermod-ag Admins Slackware

(9), add password for Slackware, and require the minimum password age of 3 days, the maximum is 180 days, warning for 3 days;

echo "magedu" | passwd--stdin Slackware

usermod-m 3-m 180-w 3 Slackware

(10), add user OpenStack, whose ID number is 3003, the basic group is clouds, the additional group is Peguin and Nova;

groupadd clouds groupadd Nova

useradd-u 3003 openstack-g clouds

Usermod-ag Nova,peguin OpenStack

(11), add the system user MySQL, request its shell for/sbin/nologin;

useradd-s/sbin/nologin MySQL

(12), use the echo command, non-interactive add a password for OpenStack.

echo "magedu" | passwd--stdin OpenStack


* User-related commands: Useradd, Usermod, Userdel, and more, please use man to help find

* Group-related commands: Groupadd, Groupmod, Groupdel, and more, please use man help to find

This article is from "Bo Zi in the Water" blog, declined to reprint!

Basic knowledge of Linux three

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.