Get the App
SLTechnology News&Howtos  ›  Servers  › 

The method of using regular expressions for user Management in centos7

Shulou Source: shulou.com Published: 2022-06-03 05:38:19 09月22日 Update

1. Display / etc directory, starting with a non-letter, followed by a letter and other files or directories of any length and any character

[root@centos7 etc] # touch _ di234

[root@centos7 etc] # ls / etc/ | grep ^ [^ a-zA-Z] [a-zA-Z]. *

1sdf23

_ di234

[root@centos7 etc] #

2. Copy all files or directories that begin with p and end with non-numbers under the / etc directory to the / tmp/mytest1 directory.

[root@centos7 ~] # ls / etc/ | grep ^ p.* [^ 0-9] $

Pam.d

Passwd

Passwd-

Pbm2ppa.conf

Pinforc

Pki

Plymouth

Pm

Pnm2ppa.conf

3. Convert the contents of the / etc/issue file to uppercase and save to the / tmp/issue.out file

[root@centos7 ~] # cat / etc/issue | tr'amurz 'Amurz' > / tmp/mytest1

[root@centos7 ~] # cat / tmp/mytest1

\ s

KERNEL\ R ON AN\ M

[root@centos7 ~] #

4. Summarize and describe how to use user and group management commands and complete the following exercises:

(1) create a group distro with a GID of 2019

[root@centos7 ~] # groupadd-g 2019 distro

[root@centos7 ~] # cat / etc/group | grep distro

Distro:x:2019:

[root@centos7 ~] #

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

[root@centos7] # useradd-u 1005-g distro mandriva

[root@centos7 ~] # id mandriva

Uid=1005 (mandriva) gid=2019 (distro) groups=2019 (distro)

[root@centos7 ~] #

(3) create user mageia, whose ID number is 1100 and home directory is / homenux

[root@centos7] # useradd-u 1100-d / homenux mageia

[root@centos7 ~] # id mageia

Uid=1100 (mageia) gid=1100 (mageia) groups=1100 (mageia)

[root@centos7 ~] #

(4) add a password to the user mageia, the password is mageedu, and set the user password to expire after 7 days.

[root@centos7 ~] # echo mageedu | passwd-x 7-- stdin mageia

[root@centos7 ~] # cat / etc/shadow | grep mageia

Mageia:!!:18320:0:7:7:::

(5) delete mandriva, but keep its home directory

[root@centos7 ~] # userdel mandriva

[root@centos7] # ls-d / home/mandriva/

/ home/mandriva/

[root@centos7 ~] #

(6) create user slackware, whose ID number is 2002, basic group is distro, and additional group peguin

[root@centos7 ~] # groupadd peguin

[root@centos7] # useradd-u 2002-g distro-G peguin slackware

[root@centos7 ~] # id slackware

Uid=2002 (slackware) gid=2019 (distro) groups=2019 (distro), 2020 (peguin)

(7) modify the default shell of slackware to / bin/tcsh

[root@centos7] # usermod-s / bin/tcsh slackware

[root@centos7 ~] # grep slackware / etc/passwd

Slackware:x:2002:2019::/home/slackware:/bin/tcsh

[root@centos7 ~] #

(8) add additional group admins for user slackware

[root@centos7 ~] # groupadd admins

[root@centos7 ~] # usermod-G admins slackware

[root@centos7 ~] # id slackware

Uid=2002 (slackware) gid=2019 (distro) groups=2019 (distro), 2021 (admins)

[root@centos7 ~] #

Tags: User directory file password letter beginning attachment method management usage content command uppercase diva character number length home regular expression Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Docker MariaDB Redmi macOS