System management commands required for Linux (2)

Source: Internet
Author: User
Useradd1. the useradd command is used to create a user account and create a user's initial directory. The permission is a Super User. 2. format: useradd [-dhome] [-sshell] [-ccomment] [-m [-ktemplate] [-finactive] [-eexpire] [-ppasswd] [-r] name3. parameters Useradd

1. Role
The useradd command is used to create a user account and create a user's starting Directory. The permission is a Super User.

2. Format
Useradd [-d home] [-s shell] [-c comment] [-m [-k template] [-f inactive] [-e expire] [-p passwd] [-r] name

3. main parameters
-C: add the remarks text. the remarks text is saved in the remarks column of passwd.
-D: specify the start directory when the user logs on.
-D: change the default value.
-E: specifies the validity period of the account, which is permanently valid by default.
-F: specifies the number of days after the password expires.
-G: specifies the group to which the user belongs.
-G: specify the additional group to which the user belongs.
-M: automatically creates a user's logon directory.
-M: do not automatically create a user's logon directory.
-N: cancel the creation of a group named by the user name.
-R: create a system account.
-S: specifies the shell used after the user logs on.
-U: specifies the user ID.

4. description
Useradd can be used to create a user account. it is the same as the adduser command. After the account is created, use passwd to set the account password. The account created using the useradd command is actually saved in the/etc/passwd text file.

5. application instance
Create a new user account and set the ID:
# Useradd caow.u 544

It should be noted that when setting the ID value, try to be greater than 500 to avoid conflict. After Linux is installed, some special users are created. Generally, the value between 0 and 499 is left to System accounts such as bin and mail.

Groupadd

1. Role
The groupadd command is used to add a new group to the system.

2. Format
Groupadd [-g gid] [-o] [-r] [-f] groupname

3. main parameters
-G gid: specifies the group ID.
-O: The group ID is allowed. it does not need to be unique.
-R: ID of the group to be added, which is lower than the 499 system account.
-F: When you join an existing group, the development program exits.

4. application instance
Create a new group and set the group ID to the system:
# Groupadd-g 344 cquota

In this case, a group ID (GID) of 344 is generated in the/etc/passwd file.

Kill

1. Role
The kill command is used to stop a process.

2. Format
Kill [-s signal |-p] [-a] pid...
Kill-l [signal]

3. parameters
-S: specifies the sent signal.
-P: analog transmission signal.
-L: name list of the specified signal.
Pid: ID of the process to be aborted.
Signal: indicates the Signal.

4. description
Process is a very important concept in Linux. Linux is a multi-task operating system that often runs multiple processes at the same time. We don't care about how these processes are allocated, or how the kernel manages the allocation of time slices. we care about how to control these processes so that they can serve users well.

The Linux operating system includes three different types of processes, each of which has its own characteristics and attributes. An interactive process is a process started by a Shell. Interactive processes can run either on the foreground or on the background. The batch processing process is a process sequence that is not associated with the terminal. Processes started when the Linux system is started when the monitoring process (also known as the system daemon process) is running in the background. For example, httpd is a monitoring process of the famous Apache server.

The kill command works by sending a system operation signal and the process ID of a program to the Linux kernel. then, the system kernel can operate the process specified by the process ID number. For example, in the top command, we can see that the system runs many processes, sometimes we need to use kill to stop some processes to improve system resources. When explaining the installation and login commands, I mentioned that the role of multiple virtual consoles in the system is to switch to other virtual consoles to close the program when a program error causes a system deadlock. In this case, the command is kill, because kill can be directly called by most internal Shell commands.

5. application instance
(1) force stop (often used to kill) a process with the process ID 324:
# Kill-9 324

(2) remove the deadlock in Linux
In Linux, a program crashes and is in a deadlock state. In this case, you do not need to restart the computer. you only need to stop (or close) the problematic program. When kill is on the X-Window interface, the main program (except the crashed program) is generally started normally. Open a terminal and stop the problematic program there. For example, if the Mozilla browser program is locked, you can use the kill command to stop all programs that contain the Mozolla browser. First, use the top command to investigate the PID of the program, and then use the kill command to stop the program:
# Kill-SIGKILL XXX
XXX indicates the process ID of the program with the Mozolla browser.

(3) use commands to recycle memory
We know that memory is very important to the system. memory recovery can improve system resources. The kill command can be used to abort programs that are out of track or do not have the corresponding programs for a long time. For example, if you use the top command to find a useless (Zombie) process, you can use the following command:
# Kill-9 XXX
XXX is a useless process ID.

Run the following command:
# Free
The available memory capacity is increased.

(4) killall command
In Linux, a killall command is also provided to directly use the process name instead of the process ID number. for example:
# Killall-HUP inetd

Crontab

1. Role
You can use the crontab command to modify the crontab configuration file. then, the configuration is executed by the cron utility at an appropriate time. This command has the permission of all users.

2. Format
Crontab [-u user] file
Crontab [-u user] {-l |-r |-e}

3. main parameters
-E: run the text editor to set the time table. The text editor is vi.
-R: delete the current time table.
-L: list the current time table.

The format of the crontab file is m h d m d cmd ". M indicates the minute (0 ~ 59), H indicates the hour (0 ~ 23), D represents the day (1 ~ 31), m represents the month (1 ~ 12), d indicates the day in a week (0 ~ 6, 0 is Sunday ). Cmd indicates the program to run. it is sent to sh for execution. the Shell contains only three environment variables: USER, HOME, and SHELL.

4. description
Compared with the at command, the crontab command is suitable for tasks with a fixed cycle.

5. application instance
Set a scheduled and scheduled system prompt:
[Cao @ www cao] # crontab-e
The system opens a vi editor.

If you enter the following content: 35 17 ** 5 wall "Tomorrow is Saturday I will go CS", then save the disk and exit. At this time, a cao file will be generated in the/var/spool/cron/Directory. the content is as follows:

      
       # DO NOT EDIT THIS FILE - edit the master and reinstall.# (/tmp/crontab.2707 installed on Thu Jan  1 22:01:51 2004)# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)35 17 * * 5 wall "Tomorrow is Saturday I will play CS "
      


In this way, a terminal will pop up at every Friday to remind you to play CS on Saturday! The displayed result is shown in.


A scheduled and regular system prompt

Hands-on exercises

1. use kill and top commands to observe system performance changes.

Start a terminal to run the top command, and then start a terminal to use the kill command, as shown in.


Observe the influence of the kill command on the top terminal

In this case, use the kill Command described above to abort some programs:
# Kill SIGKILL XXX

Then let's look at the changes in the top command terminal, including memory capacity, CPU usage, and system load. Note: Some processes cannot be aborted, but you can try it when learning Linux commands to see how the system responds.

2. use the at and halt commands for timed shutdown
First, set the shutdown time to. enter the following code:

      
       #at 17:35 warning: commands will be executed using (in order) a) $SHELL b) login shell c) /bin/shat>halt `-i -pat> 
       
        job 6 at 2004-01-01 17:35
       
      


In this case, you have actually entered the Shell of the Linux system and compiled the simplest program: halt-I-p. The text ending symbol in the Shell above Press Ctrl + D to close the command and submit the task to exit Shell. "Job 6 at" indicates that the system accepts 6th at commands and runs the command at: stop all network-related devices, shut down the system, and turn off the power.

3. use the crontab command to perform daily scheduled virus scanning
We have introduced a simple crontab command operation. here we will look at some more important operations.

(1) create a file and set the file name. assume it is a caoproject:
# Crontab-e

(2) the file content is as follows:
05 09 *** antivir
After editing with vi, save the disk and exit. Antivir is a software that detects and removes Linux viruses. it must be installed in the system first.

(3) use the crontab command to add it to the task list:
# Crontab caoproject
In this way, all users in the system will automatically scan the virus at 09:05 every day.

4. use kill to make the modified configuration file take effect immediately
Windows users generally know that after an important configuration file is modified, the computer must be restarted to make the modification take effect. Because of the modular design, Linux can set Services in real time as needed. Here we will take the network service inetd as an example to introduce some operation skills.

Inetd is a monitoring daemon that monitors connection requirements with Internet service processes (such as rlogin, telnet, ftp, and rsh) and extends the required service processes. By default, the daemon monitored by inetd is listed in the/etc/inetd. conf file. Edit/etc/inetd. conf file, which can change the options for inetd to start the server daemon, and then drive inetd to send a signal to the current inetd process with SIGHUP (signal 1), so that inetd can re-read the file
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.