Linux operations for the second time

Source: Internet
Author: User
Tags echo command stdin


A. Lists the user names of all logged-in users on the current system (only once with the user logged on multiple times).

The title does not indicate whether the username is allowed to be sorted, so it can be written as:

# who | Cut-d '-f1 | Sort-u

Second, remove the shell that is the user's default shell on the current system.

Count the number of shells in the default shell that appear in the/etc/passwd file and then remove

# CAT/ETC/PASSWD | Cut-d:-f7 | Uniq-c |sort-nr | Head-n 1

Three, the/etc/passwd in the third field of the value of the largest number of the following 10 users of the information is all rewritten to uppercase and saved to the/tmp/maxusers.txt file

# CAT/ETC/PASSWD | Sort-nr-t:-k3 | Head-n 10 | Tr ' A-Z ' A-Z

>/tmp/maxusers.txt

Four, take out the current host IP address, hint: the results of the ifconfig command is sliced

First Take out the line of the IP address and then slice it.

#ifconfig | grep ' inet[[:space:]].* ' | Cut-d '-f10 | Head-n 1

V. Display the total number of subdirectories or files in the/var directory

# tree-l 1/var |tail-n 1

Take out the names of the 10 groups with the smallest number in the third field in the/etc/group file

# Cat/etc/group | sort-n-T:-k3 | head-n | cut-d ': '-f1

Vii. Merge the contents of the/etc/fstab and/etc/issue files into the same content and save to the/tmp/etc.test file

# cat/etc/issue >>/tmp/etc.test | Cat/etc/fstab >>/tmp/etc.test

Viii. summarize how to use the user and group management commands and complete the following exercises:

(1) Create group Distro, whose GID is

Create Group command: Groupadd

usage: groupadd [options] ... groupname

parameter:-G GID, indicating the group number that indicates the creation of the group;

# groupadd-g Distro

(2) Create user Mandriva, whose ID number is 1005; Basic Group is distro

Create user command: Useradd

usage: useradd [options] ... username

parameter:-u UID, which indicates the ID number of the user who created it;

-G GID, represents a basic group that indicates the creation of a user, which can be a group number or group name;

# useradd-g Distro-u 1005 Mandriva

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

same use command: Useradd

Parameters:-d/path_to_homedir, specify a specific path for the user's home directory;

# useradd-u 1100-d/home/linux Mageia

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

Add or modify User password command: passwd

usage: passwd [options] Username

parameter:--stdin: Receive user password from standard input;

The user name (Mageia) is typically directly followed by the passwd command and then manually entered two times to enable the

User's password login authentication, but here can also be from the standard input one time to set a password:

# echo "Mageedu" | Passwd--stdin Mageia

(5) Delete Mandriva, but keep its home directory;

Delete user command: Userdel

usage: userdel [option] ... username

parameter:-r: Delete the user home directory, do not add the parameter is not deleted by default;

# Userdel Mandriva

(6) Create user Slackware, whose ID number is 2002, Basic Group is distro, additional group Peguin;

same use command: Useradd

parameter:-u UID: Specify user ID;

- g GID: specify user base groups;

- G group1[,group2,...]: Specify user-attached groups;

# useradd-u 2002-g distro-g Peguinslackware

(7) Modify the default shell of Slackware for/BIN/TCSH;

Modify User Properties command: Usermod

usage: usermod [option] username

parameter:-s shell, modify the user's default shell;

# usermod-s/bin/tcsh Slackware

(8) Add additional Group admins for user Slackware;

same use command: Usermod

Parameters:-G group1[,group2,...]: Specify a new additional group for the user, with the "-a" parameter representation

Add a new additional group to the user, the original additional group will not be overwritten;

# usermod-a-G admins Slackware

(9) to add a password for Slackware, and require the minimum password age of 3 days, the maximum is 180 days, the police

The 3-day report;

Set User password properties using the command: Chage

usage: chage [option] ... username

parameter:-M: Indicates the minimum number of days to use for the set password;

-M: indicates the maximum number of days to use for the set password;

-W: indicates how many days before the password expires alert message;

# chage-m 3-m 180-w 3 Slackware

(10) Add user OpenStack, whose ID number is 3003, basic group is clouds, additional group is Peguin

and Nova;

Add user use command: Useradd, similar to (6) minor questions;

# useradd-u 3003-g Clouds-gpeguin,nova OpenStack

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

Use command: Useradd

parameter:-r: Indicates that the system user is added;

- s SHELL: indicates the default shell for creating the user;

# useradd-s/sbin/nologin-r MySQL

(12) using the Echo command, non-interactive add password for OpenStack;

Use command: passwd, similar to (4) minor questions;

# echo "Open" | Passwd--stdin OpenStack

IX, Replication/etc/skel directory is/home/tuser1, requires/home/tuser1 and its internal files belong to the group and other users have no access rights

# cp-arf/etc/skel/*/home/tuser1

# Chmod-r 600/home/tuser1

Ten, display the/proc/meminfo file in uppercase or lowercase s start line, in two ways;

First: Matches the line that begins with the beginning of a lower-case or uppercase S anchor;

# Cat/proc/meminfo | grep ' ^[s,s].* '

The second way: matches the first letter of the word is lowercase or uppercase s start line;

# Cat/proc/meminfo | grep ' \b[s,s].* '

XI. Displays the user whose default shell is non-/sbin/nologin in the/etc/passwd file;

# cat/etc/passwd | grep-v '. *nologin$ ' | cut-d ': '-f1

12. Display the default shell as/bin/bash user in/etc/passwd file;

# cat/etc/passwd | grep '. *bash$ ' | cut-d ': '-f1

13. Find out one or two digits in the/etc/passwd file;

# cat/etc/passwd | grep ' \b[0-9]\{1,2\}\b '

14, the display/etc/rc.d/rc.sysinit file with the beginning of #, followed by at least one white space character, and then have at least one non-whitespace character line;

# cat/etc/rc.d/rc.sysinit |grep ' ^#[[:space:]]\+[^[:space:]]\+ '

A line that ends with ' LISTEN ', followed by or followed by a blank character in the execution of the Netstat-tan command;

# Netstat-tan | grep '. *listen\b '

16, add user Bash,testbash,basher,nologin (this one user's shell is/sbin/nologin), and then find the current system on its user name and the default shell of the same user information;

Idea: Take the line with the name of the beginning of the line and the end of the bash name, and then anchor the key word at the end of the row.

# Useradd Bash

# Useradd Testbash

# Useradd Basher

# useradd-s/sbin/nologin Nologin

# CAT/ETC/PASSWD | grep ' \ (^[a-z][^:]\+\). *\1$ '


This article is from the "Linux High-end training" blog, please be sure to keep this source http://hhclab.blog.51cto.com/6743827/1885243

Linux operations for the second time

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.