60 required commands for Linux (3)-system management

Source: Internet
Author: User
60 required commands for Linux (3)-system management

60 required commands for Linux: system management commands
System Management commands required for Linux
Author: Cao yuan, his posting date: 2004.10.18
For Linux systems, whether it is a central processor, memory, disk drive, keyboard, mouse, or user, it is a file. Linux system management commands are the core of its normal operation. After familiarizing yourself with common Linux File Processing commands, This section describes the commands for managing systems and users.

DF

1. Role
The DF command is used to check disk space usage of the file system. The permission is granted to all users.

2. Format
DF [Options]

3. Main Parameters
-S: the total number of data blocks occupied by each names parameter.
-A: recursively displays the number of data blocks occupied by each file in a specified directory and Its subdirectories. If neither-s nor-A is specified, only the disk blocks occupied by each directory and Its subdirectories in names are displayed.
-K: Used to list disk space usage in 1024 bytes.
-X: Skipping directories on different file systems is not counted.
-L: calculates the size of all files, and computes hard-linked files multiple times.
-I: displays inode information instead of block usage.
-H: print out the file system size in an understandable format, such as 136kb, 254 MB, and 21 GB.
-P: Use the POSIX output format.
-T: displays the file system type.

4. Description
The DF command is widely used to generate statistical data on file systems. It displays information about all file systems in the system, including total capacity, available free space, and current installation points.

When a super-level permission user uses the DF command, the capacity of a partition exceeds 100%. This is because the Linux system reserves 10% of the space for Super Users, which is independently controlled by the Super Users. That is to say, for a super user, the disk capacity he sees will be 110%. This arrangement is advantageous for system management. When the disk capacity is close to 100%, the system administrator can still work normally.

5. Application Instance
Linux supports many file systems, including JFS, reiserfs, ext, ext2, ext3, iso9660, XFS, Minx, vfat, and msdos. Run the DF-T command to view the disk space and obtain the file system information:

# DF-T
File System Type capacity available in use % mount point
// DEV/hda7 reiserfs 5.2g 1.6g 3.7g 30%/
/Dev/hda1 vfat 2.4g 1.6g 827 M 66%/Windows/C
/Dev/hda5 vfat 3.0g 1.7g 1.3G 57%/Windows/d
/Dev/hda9 vfat 3.0g 2.4g 566 M 82%/Windows/E
/Dev/hda10 NTFS 3.2g 573 m 2.6G 18%/Windows/F
/Dev/hda11 vfat 1.6g 1.5g 23 m 99%/Windows/g

In addition to the capacity and usage of the disk space, the file system type and mount point of the partition are also displayed at a glance.

Top

1. Role
The top command is used to display the processes in execution. The permission is granted to all users.

2. Format
Top [-] [d delay] [Q] [C] [s] [s] [I] [N]

3. Main Parameters
D: Specify the update interval, in seconds.
Q: there are no delayed updates. If a Super User exists, the top command is executed in the highest priority order.
C: displays the complete process path and name.
S: The accumulation mode, which accumulates the CPU time of the completed or disappearing sub-itinerary.
S: security mode.
I: no idle (idle) or useless (zombie) itinerary is displayed.
N: displays the number of updates. After the update is completed, the system will exit the top.

4. Description
The top command is a major command for Linux system management. It can obtain a lot of information. Here we use figure 1 to describe the information it provides.

Figure 1 display of top commands

In Figure 1, the items in the first line are the current time, system start time, number of users logged on to the current system, and average load. The second line shows all started processes, currently running, suspended and useless processes. The third line shows the current CPU usage, including the proportion occupied by the system, user usage, and idle ratio. The fourth line shows the usage of physical memory, including the total available memory, used memory, idle memory, and memory occupied by the buffer. The fifth line shows the swap partition usage, including the total swap partition, used, idle, and cache size. The sixth line displays the largest number of items. The detailed explanations are listed below.
PID (process ID): process ID.
User: the user name of the process owner.
PR: process priority.
Ni: the priority value of the process.
Virt: Virtual Memory occupied by the process.
Res: The physical memory occupied by the process.
SHR: the shared memory value used by the process.
S: Process status. s indicates sleep, r indicates running, Z indicates frozen, and N indicates that the priority of the process is negative.
% CPU: CPU usage occupied by the process.
% Mem: Percentage of physical memory and total memory occupied by the process.
Time +: The total CPU time occupied by the process after it is started.
Command: the name of the startup command that the process starts. If this line does not appear, the process has a complete command line.
Some interactive commands can be used to complete other parameter functions during the use of the top command. These commands are started by using the shortcut key.
<Space>: refresh immediately.
P: sort by CPU usage.
T: sort by time and accumulated time.
Q: exit the TOP command.
M: Switch to Display memory information.
T: process and CPU status information is displayed during switchover.
C: Switch the display command name and the complete command line.
M: sort by memory size.
W: Write the current settings ~ /. Toprc file. This is a recommended method for writing top configuration files.

As you can see, the top command is a powerful tool for monitoring the system, especially for system administrators. However, it consumes a lot of system resources.

5. Application Instance
The top command can be used to monitor the process of a specified user. By default, the process of all users is monitored. If you want to view the situation of a specified user, press the "U" key in the terminal and enter the user name, the system will switch to the process running interface of the specified user, as shown in figure 2.

Figure 2 use the top command to monitor a specified user

Free

1. Role
The free command is used to display memory usage. The permission is applied to all users.

2. Format
Free [-B |-k |-M] [-O] [-s delay] [-T] [-v]

3. Main Parameters
-B-K-M: memory usage is displayed in bytes (kb, MB.
-S delay: the number of seconds to display the memory usage.
-T: displays the total memory column.
-O: the buffer adjustment column is not displayed.

4. Application Instance
The free command is the main command used to view memory usage. Compared with the top command, it is easy to use and only occupies a small amount of system resources. The-S parameter allows you to use the free command to continuously monitor the number of inactive instances. This allows you to use it as a convenient real-time monitor.
# Free-B-S5

With this command, the slave node continuously reports memory usage (in bytes) and updates every 5 seconds.

Quota

1. Role
The quota command is used to display the disk usage and restrictions, and the super user with the permission is used.

2. Format
Quota [-G] [-u] [-V] [-p] user name group name

3. Parameters
-G: displays the disk usage restrictions of the user's group.
-U: displays the user's disk usage restrictions.
-V: displays the distribution of file systems with no space allocated.
-P: Display simplified information.

4. Application Instance
In enterprise applications, the disk quota is very important. Common users should learn to understand their own disk usage. To query your disk quota, run the following command (in the following example, the user account is cao133 ):

# Quota cao.pdf
Disk quotas for user caoloud (UID 502 ):
Filesystem blocks quota limit Grace files quota limit grace
/Dev/hda3 58 200000 400000 41 500 1000

The preceding shows the caojh account with the ID number 502, and the number of files is set to 500 ~ 1000, hard disk space limit set to MB ~ 400 mb. Once the disk quota is used up, you need to delete some junk files or request an additional quota from the system administrator.

At

1. Role
The at command is used to execute the specified command sequence at the specified time.

2. Format
At [-V] [-q x] [-F file] [-M] Time

3. Main Parameters
-V: Standard Error output is displayed.
-Q: Many queue outputs.
-F: reads a job from a file.
-M: after the job is executed, an email is sent to the user.
Time: Set the job execution time. The time format has strict requirements. It consists of the offset of the hour, minute, date, and time. The date format is mm. DD. YY, mm is minute, DD is date, and YY is year. The offset format is time + offset, in the unit of minutes, hours, and days.

4. Application Instance
# At-f Data 15: 30 + 2 days

The preceding command allows the system to execute the job specified in file data at two days later.

Lp

1. Role
LP is the command for printing files. The permission is granted to all users.

2. Format
Lp [-C] [-D] [-M] [-number] [-title] [-p]

3. Main Parameters
-C: copy the file before printing it.
-D: print the queue file.
-M: send an email to the user after printing.
-Number: number of printed copies.
-Title: print the title.
-P: set the priority for printing, up to 100.

4. Application Instance
(1) print multiple files using the LP command
# LP 2 3 4
Request ID is 11 (3 file (s ))

2, 3, and 4 are file names, and "Request ID is 11 (3 file (s)" indicates that these are 11th print commands, which are printed in sequence.

(2) set the print priority
# Lp-D LaserJet-P 90/etc/aliases

By adding "-P 90", the priority of the print job is set to 90. It will be printed before a print job with a higher priority than 90, including a job without a higher priority. The default priority is 50.

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 working principle of the kill command is to send 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. 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 how to install and log on to the command, we 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 the day of the week ). 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 jan1 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 result is shown in figure 3.

Figure 3 scheduled and scheduled system prompts

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 run the kill command, as shown in figure 4.

Figure 4 effect of kill command on top Terminals

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/sh
At> halt '-I-P
At> <EOT>
Job 6

At this time, the shell has actually entered the Linux system and compiled a simplest program: Halt-I-P. The text terminator in the shell above indicates to press the CTRL + d key combination to close the command and submit the task to exit the 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. This process is implemented by the kill command.
After modifying inetd. conf in VI or another Editor, run the following command:
# Ps-Ef | grep inetd

The code above indicates the process number (PID) for querying inetd. conf, which is assumed to be 1426, and then run the following command:
# Kkill-1426 inetd
In this way, the configuration file takes effect.

The system management commands described in this lecture are all important, especially the crontab and quota commands, which are difficult to use and require more exercises. In addition, pay attention to the "-9" parameter when using the kill command. It is best not to run some important programs during the exercise.

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.