Document management practices
1. Display the /etc directory, starting with a non-letter, followed by a letter and other files or directories of any length and any character
ls /etc/* | grep ^[0-9][^0-9]
2. Copy all files or directories starting with p and ending with non-digits in the /etc directory to the /tmp/mytest1 directory
# 创建/tmp/mytest1目录
mkdir /tmp/mytest1
# 第一种方法,使用元字符非数字结尾的文件或目录
cp -r /etc/p*[^0-9] /tmp/mytest1
# 第二种方法,使用字符类匹配非数字结尾的文件或目录
cp -r /etc/p*[^[:digit:]] /tmp/mytest1
3. Convert the content in the /etc/issue file to uppercase and save it to the /tmp/issout.out file
# 第一种方法,使用输入重定向读取文件
tr [a-z] [A-Z] < /etc/issue > /tmp/issue.out
# 第二种方法,使用cat命令和管道读取文件
cat /etc/issue | tr [a-z] [A-Z] > /tmp/issue.out
User management practices
1. Summarize the usage of user and user group management commands and complete the exercises:
User management commands
command | usage |
---|---|
useradd | Create user |
usermod | User attribute modification |
userdel | delete users |
id | View user UID, GID, user group information |
his | Switch users or execute commands as other users |
passwd | Set the user's password and password parameters |
chage | Modify user password parameters |
chsh | Modify the user's default shell, equivalent to usermod -s |
chfn | Edit user's personal information |
finger | View user's personal information |
User group management commands
command | usage |
---|---|
groupadd | Create user group |
groupmod | Modify the attributes of a user group |
groupdel | Delete user group |
gpasswd | Modify group password, add or delete members of additional groups |
newgrp | Temporarily switch the main group |
groupmems | Change and view group members |
groups | View user group relationship |
(1) Create a group distro, its GID is 2019;
groupadd -g 2019 distro
(2) Create user mandriva, whose ID number is 1005; the basic group is distro;
useradd -u 1005 -g distro mandriva
(3) Create user mageia with ID number 1100 and home directory /home/linux;
useradd -u 1100 -d /home/linux mageia
(4) Add a password for user mageia, the password is mageedu, and set the user password to expire after 7 days;
echo mageedu | passwd --stdin mageia
chage -d 7 mageia
(5), delete mandriva, but keep its home directory;
userdel mandriva
(6) Create user slackware, whose ID number is 2002, the basic group is distro, and the additional group peguin;
useradd -u 2002 -g distro -G peguin slackware
(7), modify the default shell of slackware to /bin/tcsh;
# 第一种方法
usermod -s /bin/tcsh slackware
# 第二种方法
chsh -s /bin/tcsh slackware
(8), add additional group admin for user slackware;
usermod -aG admin slackware