Linux system command masteric guide (primary)

xiaoxiao2021-03-06  86

In the Linux File Command Promotion Guide, we discussed the basic information required to take advantage of the most basic and most common Linux file commands. In this article, I will discuss the LINUX system command. We learned in the previous article that everything is regarded as a file in the Linux / UNIX world, including the system management command. For organizations, we discuss file commands in the first part of this series and will provide the most useful system diagnostics and maintenance commands in this article. For file commands, we discussed some fairly simple and intuitive management commands. Only the functions of other more complex commands are described in order to know these commands and their purposes when you need to use. This article does not involve detailed discussions on the basic principles behind each command, but we will discuss the most basic and most useful commands, which are used to monitor and manage printer services, file systems, disks, and processes. Many of the commands on superusers can be performed by regular users in their own files and processes. However, some commands, such as fdisk, need ROOT permissions to run. For your system integrity, it is recommended that you avoid logging in directly to the system directly. Instead, it is usually more suitable for regular user login, then executes the SUX command from X WINDOW to run the system management function. (SUX provides you with the X Window environment and root permissions.) When you log in with a root user, you will always know that you are in this state because your prompt is changed to "#". Super users can use sudo, selectively assign those permissions that are usually reserved for root users or other special users to a different regular user. The root user can define the actual and valid user and group identification NOD and GID to match the expected user's identity. This expected user can be (but not necessarily) users who are allowed to run the command. In other words, the super user can allow other users to perform a command, but it can also determine that any result files generated by the process should belong to the root user or any other user specified by the super user. SUDO permission is allocated, only users need to verify using their own password without requiring a root user password. General Commands From Technical, Uname, Diff, Date, Sort and UNIQ should be as file commands, but they explain them more meaningful because they are often used for system management of diagnostics and maintenance routines. Uname Uname provides regular system information. When specified -A option, display all available information: $ uname -alinux linux 2.4.18-4GB # 1 WED Mar 27 13:57:05 UTC 2002 I686 Unknown Here we see regular system information from left to right. Each information has its own option (in the parentheses below), it can be displayed separately: the operating system name is Linux (-s). This network node name is Linux (-N). The operating system release is 4.5.18-4GB (-R). Operating system version is # 1 WED Mar 27 13:57:05 UTC 2002 (-V). The machine type is I686 (-M). The processor type (-P) here is unknown. Similarly, Stty displays information about your terminal settings: $ stty -aspeed 38400 baud; rows 40; columns 103; line = 0; INTR = ^ C; quit = ^ /; ERASE = ^ ?; kill = ^ u; EOF = ^ D; EOL =

EOL2 =

; START = ^ Q;

STOP = ^ S; SUSP = ^ z; rPRNT = ^ r; werase = ^ W; LNEXT = ^ V; flush = ^ o; min = 1; time = 0; -parenb -Parodd CS8 -Hupcl -cstopb Cread-Clocal -CRTSCTS -IGNBRK -BRKINT -IGNPAR -PARMRK -INPCK

-iSTRIP -INLCR -IGNCR ICRNL IXON -IXOFF -IUCLC-IXANY -IMAXBEL

Opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel NL0 CR0 TAB0 BS0 VT0 FF0

Isig Icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

The second row and third lines show special characters and key sequences that will be called at the command line. For example, "^ z" is CNTRL-Z transmits a terminal rest in this system. Exit symbols are "^ /", cntrl- / send, and we can change it to "^ X", as shown below:

$ stty quit ^ x

In this case, you actually enter ^ symbols instead of the CNTRL key. This change only works in the current window. In order to make this change permanently take effect, you need to enter this statement in your .bashrc file.

DIFF and DATE. As the name suggests, DIFF compares two files. It returns those rows that lead to different files and returns some meaningless outputs about how to make the files.

$ DIFF TEST.out Test2.out

0A1

> Another test.

Here we were told here that the "Another Test." Is needed to add to Test.out to make it similar to Test2.out. The first character "0" is the line number to edit in Test.out; "a" indicates that the line should be added to Test.out to match the first row of Test2.out. If we need to change Test.out, the second character can be "c", and if we need to delete some content from Test.out, the second character is "D".

You may want to make a file similar to another file to provide a patch for some code. DIFF is often used as an analysis tool for verifying programs or scripts, such as whether the output of the SED script is expected.

The Date command can be used to display or set the date. If the user has a superuser authority, he or she can set the date by providing a digital string in the following command:

$ Date 0101010004

This command sets the date to 2004 (04) on January 1 (0101) (0100).

However, any user can display the date with the desired format. Note that a plus " " is required before the format sequence. If there is no expected output of this command, try to include it in single quotes:

$ DATE '% h% m% s'

204748

You can include space in the sequence, then you need to use double quotes:

$ DATE "% h% m% s"

20 47 51

There are more than 30 different format sequences listed on the date of the date, which can be combined as needed to get your last output format.

Date's output can also be used in scripts, such as: $ DATE -D '2 day'

Thu Jan 29 19:02:02 Est 2004

The -d option indicates that Date shows the time described in the string thereafter. In the above example, we asked to show the date from now on (January 27, 2004). We can also ask for three days ago, and its command is:

$ DATE -D '-3 day'

Sun jan 25 20:56:59 Est 2004

Another example of a Date is an additional string to which the additional string is output, providing a convenient method for generating a unique file name.

$ ls -l | cat> $ (DATE LS_% D% B% Y% H% M.out)

$ ls ls _ *. OUT

LS_04FEB041633.out

Here, we transfer the output of a long file list to CAT, which transfer our output to a file called LS_04FEB041609.out. Note We use a variable for the file name, indicated by the US dollar symbol "$". The "LS_" and ".out" are added to the date, the format is the day (% D) in the month, the local month name abbreviation (% B), the last two digits (% y), hour (% H) and minutes (% m) to produce this file name.

Sort and UNIQ. You can operate from the line from the pipe or the file specified from the command line. Unless otherwise specified, SORT operates on the first column of multiple columns. By default, digital columns are sorted in alphabetical columns unless the -n option is used.

The SORT column can be specified in two different formats. If you use the -k option, the position of the column starts from 1. You can also use the POS1 format, from the first column numbered numbered numbers. The following two commands produce the same output:

$ ls -l * .out | sort 5 -7

$ ls -l * .out | sort -k 6,8

-rw-r - r - 1 Bluher Users 375 DEC 5 2002 fdisk.out

-rw-r - r - 1 Bluher Uses 2447 DEC 28 20:15 ls.out

-rw-r - r - 1 Bluher Uses 590 Jan 4 21:24 Greps.out

-rw-r - r - 1 Bluher Users 78 Jan 4 21:25 SGREP.out

...

By default, the column separator of the sort command is a space and tab. You can specify additional separators using the -t SEP option, where SEP is the separator you specify. The default order of sort is from the highest to the highest, and the sequence can be reversed by the -R option.

SORT can be used in many different tasks. For example, it can be used to sort file output, or sort the output of the DU as we can see below. When using the -m option, sort merges the file and does not sort them. However, if you want to sort them, you should sort them before the file merge.

SORT is often used with the UNIQ command, deletes exactly the same line from the sorted file. The UNIQ command often follows the number of sort commands in the pipeline, and can also use the -c option to calculate the number of times the number of rows, or using the -d option, only the exact same line:

$ sort -m test.out test2_sort.out | uniq -c

1 annother test.

1 Testing Testing

2 this is a test. Here we merge two files Test.out and Test2_Sort.out. Then we use the -c option to transfer the output to UNIQ, so the last result is a list of alphabetical order, exactly the same row is deleted, and has a report on the frequency of each line.

Printer control

In most cases, the use of the printer command is relatively clear. Send the job to the printer by specifying the file name after the LPR command. If the file name is not provided, the standard input is assumed. Using the LPQ command, you can get a status report on the job sent to the printer. When you specify a job number, LPRM removes the job from the row printer background print queue.

$ lpr grep2.out

$ LPQ

Printer: lp @ Linux 'LPDFILTER DRV = UPP METHOD = Auto Color = YES'

Queue: 1 Printable Job

Server: PID 1929 ACTIVE

UNSPOOLER: PID 1930 ACTIVE

Status: Waiting for Subserver To EXIT AT 21: 24: 14.637

Rank Owner / ID Class Job Files Size Time

Active Bluher @ Linux 928 A 928 Grep2.out 779 21:24:14

Done Bluher A 877 (stdin) 117258 13:09:53

$ lprm 928

Printer LP @ Linux:

Checking perms 'cfa928linux.local'

Dequeued 'cfa928linux.local'

Here, after we send the job to the printer, we queries its status. LPQ shows us that the number 877 has been completed, and the job we just sent is 928. We use the command LPRM 928 to remove the active job from the queue.

Disk information

Whether you are maintaining your own system or supporting companies with many users, monitoring disk space is one of the more important responsibilities of system administrators. DU, DF and FDISK commands provide different views of available disk space.

The du command provides an assessment of file space usage for each directory. By default, the measured unit is the number of blocks, and the size of the block is typically determined when you install your system.

In the following example, the system is installed using a 1024-byte block. If there is no specified directory, the DU starts to calculate the current directory. -h option provides the size of the size of the easy-to-read form:

$ du -h documents

105K Documents / JJ

573k Documents / John

682k Documents

You can change the output using the -a option, which indicates the number of blocks of DU display files and directories. Options - BLOCK-SIZE = SIZE indicates that the DU displays the output by the number of blocks specified by SIZE.

$ du --block-size = 512 Documents

209 Documents / JJ

1146 Documents / John

1363 Documents

By default, DUs are also recursively printed for each subdirectory. This action can be restricted by using the max-defth = n option, where n is equal to the maximum number of reported:

$ du --max-depth = 2.

$ du --max-depth = 2 | sort -n

4 .xemacs

4./public_html

105./documents/jj573./documents/ian

682./documents

2420./jdevhome/system

8350 ./jdevhome/system9.0.3.1035

13483 ./jdevhome/mywork

24252 ./jdevhome

...

The DU reports the space usage of the directory and subdirectories, and the DF reports the disk space usage of the installed file system:

$ DF

FileSystem 1K-block Used Available Use% MOUNTED ON

/ DEV / HDA6 4195632 1983656 2211976 48% /

/ DEV / HDA5 14607 3778 10075 28% / boot

/ DEV / HDA9 937372 494028 443344 53% / Home

/ DEV / HDA8 6297248 3876880 2420368 62% / OPT

SHMFS 256220 0 256220 0% / DEV / SHM

Here, DF reports the status of five file systems. Similar to DU, DF uses the -H option to provide human readable output:

$ DF -H

FileSystem size used avail use% mounted ON

/ DEV / HDA6 4.0G 1.9G 2.1G 48% /

/ DEV / HDA5 14M 3.7M 9.8M 28% / boot

/ DEV / HDA9 915M 476M 440M 52% / Home

/ DEV / HDA8 6.0G 3.7G 2.3G 62% / OPT

SHMFS 250M 0 250M 0% / dev / shm

The DF command also allows you to specify the size of the block with the -block-size = size option.

The fdisk command is a partition table operation command for Linux. Unlike DU and DF, this command cannot be run when there is no root user permission. If the -l option is specified, it can only be used for the purpose of the report. It provides a complete view of your entire partition table, not just the extended Linux partition you have seen by DF:

# fdisk -l

Disk / dev / hda: 240 Heads, 63 Sectors, 1940 Cylinders

Units = cylinders of 15120 * 512 BYTES

Device Boot Start End Blocks ID SYSTEM

/ DEV / HDA1 1 286 2162128 C Win95 FAT32 (LBA)

/ dev / hda2 * 288 1940 12496680 5 extended

/ DEV / HDA5 288 289 15088 83 Linux

/ DEV / HDA6 290 844 4195768 83 linux

/ DEV / HDA7 845 983 1050808 82 Linux SWAP

/ DEV / HDA8 984 1816 6297448 83 linux

/ DEV / HDA9 1817 1940 937408 83 Linux process surveillance

In a busy multi-user system, the process monitoring is also an important responsibility for the Linux system administrator. In this regard, PS and TOP are two most useful commands.

The PS command provides a snapshot of the current running process.

Active lesson

The following is the simplest form of PS:

$ PS

PID TTY TIME CMD

3884 PTS / 1 00:00:00 Bash

3955 PTS / 2 00:00:00 More

3956 PTS / 5 00:00:05 Sqlplus

PID is the identification number of the process. TTY is the terminal console belonging to the process. The Time column is the total CPU time used by the process. The CMD column lists the command line being executed. Use the PS with the -ef option to return a complete list of all the processes of all users in the system. If you transfer the results of this PS command to GREP, the result is easier to view. E.g:

$ PS-EF | GREP ORACLE

Uid PID PPID C Stime Tty Time CMD

Oracle 1633 1 0 13:58? 00: 00: 00 ora_pmon_ora1

Oracle 1635 1 0 13:58? 00: 00:00 ORA_DBW0_ORA1

Oracle 1637 1 0 13:58? 00: 00: 01 ORA_LGWR_ORA1

Oracle 1639 1 0 13:58? 00: 00: 02 ORA_CKPT_ORA1

Oracle 1641 1 0 13:58? 00: 00: 02 Ora_SMON_ORA1

Oracle 1643 1 0 13:58? 00: 00:00 ORA_RECO_ORA1

Oracle 1645 1 0 13:58? 00: 00:00 ORA_CJQ0_ORA1

Oracle 1647 1 0 13:58? 00: 01: 18 ora_qmn0_ora1

Oracle 1649 1 0 13:58? 00: 00:00 ORA_S000_ORA1

Oracle 1651 1 0 13:58? 00: 00:00 ORA_D000_ORA1

Note that when you transfer the PS output to the grep command, the column header is not normally displayed when the PS command itself is used. For convenience of explanation, the title is above the output to clearly display its contact. Although the UID is typically an identifier of an index type, the user name is specified under the first column, and it is marked as a UID. PPID is the identification number of the parent process. For Oracle processes, the identification number here is 1 - it is the ID of the init process (parent process for all processes) because Oracle installed in this system is started as part of the login process. The column labeled CPU is used by the CPU to calculate the factor of performing priority. Stime refers to the startup time of the process. Question marks indicate that these processes are not part of any TTY because they are started by the system. The following is another example of the PS command with certain different options. Note that many columns are the same as columns when performing PS with -ef options:

$ PS AUX

User PID% CPU% MEM VSZ RSS TTY Stat Start Time Command

Bluh 4024 0.0 0.2 2240 1116 PTS / 1 S 20:59 0:00 Su Bluher

Bluh 4025 0.0 0.3 2856 1668 PTS / 1 S 20:59 0:00 Bashbluh 4051 0.0 0.2 2488 1504 PTS / 1 R 21:01 0:00 PS AUX

Bluh 4052 0.0 0.1 1636 600 PTS / 1 s 21:01 0:00 Grep Bluher

In addition to providing important diagnostic information, the PS command is often used to find the PID of the out-of-control process. For example, one of your users enters a Cartesian join in the SQL * Plus session. You can do the following PS command to find its PID:

$ PS-EF | GREP Bluher

...

Blure 4068 4064 0 21:14 PTS / 6 00:00:00 Less

Blure 4112 3945 0 21:28 PTS / 5 00:08:42 SQLPLUS

...

You can then terminate it using the following command: $ KILL 4112 General User You can see all system processes, but they can only terminate their own processes. PS only provides you with a snapshot of the current process. To view the most active process instantly, you can use top. TOP provides process information in real time. It also has an interactive state, allowing the user to enter commands, such as the back of 5 or 10, etc. The result is that TOP displays 5 or 10 most active processes. Top continues to run until you press "Q" to exit TOP. The following is part of the TOP display:

8:14 PM Up 51 Min, 7 Uses, Load average: 0.02, 0.03, 0.05

96 Processes: 87 Sleeping, 2 Running, 0 Zombie, 7 stopped

CPU States: 6.4% User, 3.5% System, 0.0% Nice, 89.9% iDLE

MEM: 512440K AV, 392288K USED, 120152K Free, 0K Shrd, 55668k BUFF

Swap: 1050800K AV, 0K USED, 1050800K Free 236128k Cached

PID User Pri Ni Size Rss Share Stat% CPU% MEM TIME Command

1289 Root 18 0 78008 11M 1796 R 3.7 2.2 0:49 x

1965 Bluher 20 0 12244 11m 10456 s 1.9 2.3 0:01 kdeinit

1986 Blure 18 0 996 996 768 R 1.5 0.1 0:00 TOP

1803 Bluher 20 0 16960 16M 13508 s 0.9 3.3 0:03 kdeinit

1804 Blure 20 0 16964 16M 13508 S 0.9 3.3 0:03 kdeinit

1800 Blure 19 0 12260 11M 10076 S 0.1 2.3 0:04 kdeinit

1 root 20 0 220 220 188 S 0.0 0.0 0:04 init

...

转载请注明原文地址:https://www.9cbs.com/read-106131.html

New Post(0)