Linux commands-system management commands

Source: Internet
Author: User

Linux commands-system management commands

I. Installation and logon commands

Login
1. Role
Login is used to log on to the system and has the permission to all users.
2. Format

Login [name] [-p] [-h host name]
3. Main Parameters
-P: notifies login to retain the current environment parameters. -H: used to transmit user names between remote logins.
If you choose to log on to Linux in command line mode, the first Linux Command is login :.
The general interface is as follows:
Manddrake Linux release 9.1 (Bamboo) for i586
Renrel 2.4.21-0.13mdk on i686/tty1
Localhost login: root
Password:
In the code above, the first line is the Linux release version number, the second line is the kernel version number and the virtual console we log on to. In the third line, we enter the login name, press Enter and Enter the account Password to log on to the system. For security reasons, the characters are not displayed on the screen when the account password is entered, and the cursor is not moved.
After logging on, you will see the following interface (taking the Super User as an example ):
[Root @ localhost root] #
Last login: Tue, Nov 18 10:00:55 on vc/1
The preceding figure shows the logon day, month, day, and time, and the virtual console used.
4. Application Skills
Linux is a real multi-user operating system that allows multiple users to log on simultaneously and allows one user to log on multiple times. This is because Linux, like many versions of Unix, provides access to the virtual console, allowing users to access the console at the same time (the system console is a monitor and keyboard directly connected to the system) log on multiple times. Each virtual console can be seen as an independent workstation, and can be switched between workstations. The switchover of the virtual console can be done by pressing the Alt key and a function key, typically using a F1-F6.
For example, after a user logs on, press the "Alt + F2" key and the user will see the "login:" prompt above, indicating that the user has seen the second virtual console. Then, press the "Alt + F1" key to return to the first virtual console. A newly installed Linux system allows you to use the Alt + F1 key to access the first six virtual consoles. What is most useful in the virtual console is that when a program error causes a system deadlock, you can switch to another virtual console to close the program.

 

Shutdown
1. Role
The shutdown command is used to shut down the computer and its permission is a Super User.
2. Format

shutdown [-h][-i][-k][-m][-t]
3. Important Parameters
 
-T: Tell the init program how long it will shut down before it changes to another running level. -K: it does not actually shut down, but only sends a warning signal to each worker. -H: power off after shutdown. -C: cancel current process cancels the currently executing Shutdown program. Therefore, this option certainly does not have a time parameter, but you can enter a message for explanation, and this information will be sent to each user. -F: Forces The fsck to restart the computer. -Time: set the time before shutdown. -M: Change the system to single-user mode. -I: The system information is displayed when the instance is shut down.
4. Command description
The shutdown command can safely shut down the system. It is very dangerous for some users to shut down the Linux system by directly disconnecting the power supply. Because Linux and Windows run many processes in the background, forced shutdown may lead to data loss in the process and make the system unstable, in some systems, hardware devices (hard disks) are damaged ). Use the shutdown command before shutting down the system. The system administrator will notify all logged-on users that the system is about to shut down and the login Command will be frozen. That is, new users cannot log on again.
My most commonly used shutdown command is as follows:

 

 

shutdown now -h

 

Reboot
1. Role
The reboot command is used to restart the computer. Its permission is assigned to the system administrator.
2. Format

reboot [-n] [-w] [-d] [-f] [-i]
3. Main Parameters
-N: Do not write the memory data back to the hard disk before restarting the instance. -W: The record is not written to the/var/log/wtmp file. -D: Do not write the record to the/var/log/wtmp file (the-n parameter contains-d ). -I: Stop all network-related devices before restarting.

 

Mount
1. Role
The mount command is used to load the file system. Its permission is granted to a Super User or a user allowed in/etc/fstab.
2. Format

mount -a [-fv] [-t vfstype] [-n] [-rw] [-F] device dir
3. Main Parameters
-H: displays the auxiliary information. -V: display information, usually used with-f for debugging. -A: Mount all file systems defined in/etc/fstab. -F: this command is usually used with-a, which generates a route for each mount action. It can speed up loading when the system needs to mount a large number of NFS file systems. -F: usually used for debugging. It causes mount to not execute the actual mounting action, but simulate the entire mounting process, which is usually used together with-v. -T vfstype: displays the type of the file system to be loaded. -N: In general, after mount is mounted, a piece of data will be written to the/etc/mtab. You can use this option to cancel this operation if the system does not have the file system to write data.
4. Application Skills
On Linux and Unix systems, all files are accessed as part of a large tree (with/as the root. To access files on a CD-ROM, You need to mount the CD-ROM device to a mount point in the file tree. If the release version is installed with an automatic mounting package, this step can be performed automatically. In Linux, if you want to use storage devices such as hard disks and optical drives, you must load them first. After the storage devices are mounted, you can use them as a directory for access. Mount a device and run the mount command. When using the mount command, you must first know the following three types of information: file system type of the object to be loaded, device name of the object to be loaded, and directory to which the device is to be loaded.
(1) recognizable file systems in Linux
◆ Windows 95/98 common FAT 32 File System: vfat;
◆ Win NT/2000 File System: ntfs;
◆ OS/2 File System: hpfs;
◆ Linux File Systems: ext2 and ext3;
◆ CD-ROM disc File System: iso9660.
Although vfat is a FAT 32 system, it is actually compatible with the file system type of FAT 16.
(2) determine the device name
In Linux, device names are usually stored in/dev. These device names are named in a regular way. You can use the "inference" method to find the device names. For example, the/dev/hda1 IDE Device, hd is Hard Disk, sd is SCSI Device, fd is Floppy Device (or Floppy Disk ?). A Indicates the first device. Generally, the IDE interface can be connected to four IDE devices (such as four hard disks ). Therefore, the methods to identify IDE Hard Disks are hda, hdb, hdc, and hdd. In hda1, "1" indicates the first hard disk partition of hda, hda2 indicates the second primary partition of hda, and the first logical partition starts from hda5. In addition, you can directly check the/var/log/messages file to find the device code identified by the system after the computer is started.
(3) Find the mount point
Before deciding to connect a device, check whether the computer has an empty/mnt Directory, which is used as a Mount Point directory. We recommend that you create several/mnt/cdrom,/mnt/floppy,/mnt/mo directories in/mnt as dedicated mount points for the directories. For example, if you want to mount the following five devices, the execution command may be as follows (assuming that all are Linux ext2 systems, and if it is Windows XX, change ext2 to vfat ):
Floppy Disk ==> mount-t ext2/dev/fd0/mnt/floppy
Cdrom ==> mount-t iso9660/dev/hdc/mnt/cdrom
SCSI cdrom ==> mount-t iso9660/dev/sdb/mnt/content Rom
SCSI cdr ==> mount-t iso9660/dev/sdc/mnt/scdr
However, most of the latest Linux releases (including Red Flag Linux, mid-soft Linux, and Mandrake Linux) can automatically mount the file system, except Red Hat Linux.

 

Umount
1. Role
The umount command is used to uninstall a file system. Its permission is granted to a Super User or a user allowed in/etc/fstab.
2. Format

unmount -a [-fFnrsvw] [-t vfstype] [-n] [-rw] [-F] device dir
3. Instructions for use
The umount command is the inverse operation of the mount command. Its Parameters and usage are the same as those of the mount command. After the Linux mounted CD-ROM, The CD-ROM is locked so that it cannot be popped up with the Eject button on the CD-ROM panel. However, if you no longer need a CD, use umount/cdrom to uninstall it if you have used/cdrom as a symbolic link. This command is successful only when no user is using the CD. This command includes a terminal window that uses the current working directory as the directory in the CD.

 

Mount is a command in Linux. It can be used to mount a partition as a "file" in Linux to an empty folder in Linux to connect the partition with the/mnt directory, therefore, accessing this folder is equivalent to accessing this partition. Currently, mount is not limited to Linux, but is widely used in Windows systems. It is used in virtual optical drive software, such as Clone CD, Daemon tool, and WinMount.
Notes
1. You must attach the CD and USB flash drives to the drive for mounting.
2. mount operations cannot be performed under the Mount directory, at least at the upper level
3. You cannot mount more than two file systems in the same directory.
4. the Linux reserved Mount directory is/mnt.
5. The unmount operation cannot be performed under the Mount directory.
6. The Mount directory must exist beforehand.
Attach a cd
# Mount-t iso9660/dev/cdrom/mnt/cdrom
Detach a cd
# Umount/mnt/cdrom or # umount/dev/cdrom or # cd; eject
Mount a USB flash drive
# Mount/dev/sdb1/mnt/usb
Mounting an iso Image
# Mount-t iso9660-o loop iso image file/mnt/cdrom

Exit

1. Role
The exit command is used to exit the child terminal system and has the permission to all users.
2. Format
Exit
3. Parameters
The exit command has no parameters. After running the command, exit the system and enter the logon interface.


Last
1. Role
The last command is used to display the logon status of recent users or terminals. Its permission is granted to all users. Run the last command to view the log of the program. The administrator can find out who has tried or attempted to connect to the system.
2. Format

1ast [-n] [-f file] [-t tty] [-h node] [-I-IP] [-1] [-y] [1D]
3. Main Parameters
-N: Number of output records. -F file: specifies that the file is used as the log file for query. -T tty: only the logon status on the specified virtual console is displayed. -H node: only the logon status on the specified node is displayed. -I IP: only the logon status on the specified IP address is displayed. -1: use an IP address to display the remote address. -Y: displays the year, month, and day of the record. -ID: the user name to be queried. -X: displays the system shutdown, user logon, and logout history.


 

2. system management commands

History

Use the history command to call up the list of commands used in history


If you want to execute the top command again, you can call up the history as follows :! 878

 

Use Ctrl + R to search for history
Ctrl + R is a frequently used shortcut key. This shortcut allows you to search for command history, which is useful when you want to execute a command repeatedly. After finding the command, you can usually press the Enter key to execute the command. If you want to adjust the command and then execute it, you can click the left or right arrow keys.

Repeat the previous command
You can run the previous command again in four ways:
Use the up arrow key and press enter to execute.
Press !! And press enter to execute.
Enter! -1 and press enter to execute.
Press Ctrl + P and press Enter.
Execute a specified command from the command history
In the following example, if you want to repeat 4th commands, You can execute them! 4:
Execute previous commands by specifying keywords
In the example below, enter! Ps and press Enter. The following command is executed to start with ps:

 

Ps

1. Role

Displays the status of the instantaneous process.

2. Use

 

ps [options] [--help] 

 

3. Parameters

 

 

-A: all processes are displayed, which has the same effect as-e.-a: displays all processes under the current terminal, including those of other users.-u: user-oriented process status. x: usually used with the parameter. More complete information can be listed.-e displays all processes, environment Variable-au show more detailed information-aux show all processes containing other users output format planning: l: Long, more detailed list of the PID information; j: job format-f: full format

 

Au (x) output format:

 


USER: Travel owner PID: pid % CPU: CPU usage % MEM: memory usage VSZ: Virtual Memory occupied RSS: Memory occupied TTY: the terminal's secondary device number (minor device number of tty) STAT: status of the trip: D: Non-interrupted static R: in progress S: static T: Paused Z: does not exist but cannot be eliminated for the moment W: There is not enough memory paging to be allocated <: high-priority trip N: low-priority trip L: memory is allocated by PAGE and locked in the memory (instant system or memory a I/O) START: stroke START TIME: execution TIME COMMAND: executed COMMAND

Example:

The specific commands are described as follows:
1) ps a shows all programs under the current terminal, including those of other users.

2) ps-A shows all programs.

3) when listing programs in ps c, the real command name of each program is displayed without the path, parameter or resident service identifier.

4) ps-e this parameter has the same effect as the specified "A" parameter.

5) when listing programs, ps e displays the environment variables used by each program.

6) ps f uses ASCII characters to display the tree structure and express the relationship between programs.

7) the ps-H tree structure is displayed, indicating the relationship between programs.

8) ps-N shows all programs, except the programs under the ps command terminal.

9) ps displays the program status in the program signal format.

10) when listing programs in ps, it includes interrupted subroutines.

11) ps-t <terminal number>

Specify the terminal number and list the status of the program that belongs to the terminal.

12) ps u

Display the program status in user-based format.

13) ps x

Show all programs, not distinguished by terminals.

The most common method is ps-aux. Then, a pipeline symbol is used to direct to grep to find a specific process and then operate on the specific process.

 

For example, process related to init naming is displayed.

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 will describe the information it provides.
Figure top command display

 

In, the first line indicates the current time, system start time, number of users logged on to the current system, and average load of the project.

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.

 

You need to monitor and control the processes in the system, and check the status, memory, and CPU usage.
(1) ps: displays the state of an instantaneous process, not dynamically consecutive;
(2) top: If you want to monitor the running time of a process, use the top command;
(3) kill is used to kill a process or send a signal to the process;

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-s 1

 

 

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. If you do not have the following name, you can install it using the following method:

 

 

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
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 4413: first find the firefox process ID, and then force kill
(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

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.