We all know that users can be created using useraddxxxx and passwd xxx can be used to create passwords for users. What should we do if we want to create a lot of them in batch ?? Next, let's take a look at an instance and create users in batches. This will save the Administrator a lot of time. Now let's take a look at all users. Now only one steven is custom, as shown in figure
As shown in, it is used to create accounts in batches. Let's take a look.
In the first line, we use the for statement, and the value of num is the number from 1 to 10. User = user $ num is obviously also a value assignment, user = user1, user2, user3... User10Useradd $ user is easy to understand. useradd is used to add users. $ user is equivalent to user1, user2, and user3... User10, the execution result should be useradd user1, useradd user2, useradd user3... Useradd user10Echo password | passwd-stdin $ user. This line is divided into two parts. Let's take a look at the results before and after the pipeline operator. The results are as follows:
As a result, echo xxxx prints the corresponding characters on the screen. As we all know, passwd xxx adds a password to the user, pass the preceding characters to the back of the pipeline as the password, so that you can understand it. Let's take a look at the execution results!
10 users have been successfully created. How can we delete them in batches? For example, we just need to change useradd to userdel. If we confirm that the user does not need it, you can also add rm-rf/home/$ user to delete the user's home directory.
When we look at it again, the user has no more
User1 and user2 in the home directory are gone.
Perfect success