Practice of linux File and User Management

  • 2021-07-22 12:19:39
  • OfStack

1. Display files or directories that start with non-letters and are followed by 1 letter and other arbitrary characters of any length under the/etc directory.

[root@centos7 etc]# ls -d /etc/[^[:alpha:]][:alpha:]*

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

[root@centos7 etc]# mkdir /tmp/mytest1 & & cp -a /etc/[p]*[^[:digit:]] /tmp/mytest1/
[root@centos7 etc] # ls/tmp/mytest1/# View results
pam.d passwd- pinforc plymouth pnm2ppa.conf postfix prelink.conf.d profile protocols purple
passwd pbm2ppa.conf pki pm popt.d ppp printcap profile.d pulse python

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

[root@centos7 etc]# tr 'a-z' 'A-Z' < /etc/issue > /tmp/issue.out
[root@centos7 etc] # cat/tmp/issue.out View
\S
KERNEL \R ON AN \M

4. Summarize and describe the use of user and group management class commands and complete the following exercise:

(1) Create a group distro, whose GID is 2019;

[root@centos7 etc]# groupadd distro -g 2019
[root @ centos7 etc] # getent group distro # Verify GID for distro
distro:x:2019:

(2) Create a user mandriva whose ID number is 1005; The basic group was distro;

[root@centos7 etc]# useradd mandriva -u 1005 -g distro
[root @ centos7 etc] # id mandriva # Verify UID number and base group for mandriva
uid=1005(mandriva) gid=2019(distro) groups=2019(distro)

(3) Create a user mageia with an ID number of 1100 and a home directory of/home/Linux;

[root@centos7 etc]# useradd mageia -u 1100 -d /home/linux
[root @ centos7 etc] # getent passwd mageia # Verification Results
mageia:x:1100:1100::/home/linux:/bin/bash

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

[root@centos7 etc]# echo "mageedu" | passwd mageia --stdin -x 7
[root @ centos7 etc] # getent shadow mageia # Verification Results
mageia:!!:18308:0:7:7:::

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

[root@centos7 etc]# userdel mandriva
[root@centos7 etc] # ls/home/# Verification results mandriva directory still exists
diyoujia linux mandriva slackware test

(6) Create a user slackware, whose ID number is 2002, the basic group is distro, and the additional group is peguin;

[root@centos7 etc]# useradd slackware -u 2002 -g distro -G peguin
[root @ centos7 etc] # id slackware # Verification Results
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)

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

[root@centos7 etc]# chsh slackware -s /bin/tcsh
[root @ centos7 etc] # getent passwd slackware # Verification Results
slackware:x:2002:2019::/home/slackware:/bin/tcsh

(8) Adding an additional group admins for the user slackware;

[root@centos7 etc]# usermod slackware -aG admins
[root @ centos7 etc] # id slackware # Verification Results
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)

The above is all the relevant knowledge points introduced this time. Thank you for your study. I hope the contents sorted out by this site can help you.


Related articles: