Linux system command masteric guide

zhaozj2021-02-16  83

Linux system command masterpiece guide author Shereyl Calish

Introduction to system commands for Linux beginners

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.

More information about super users

Many of the commands discussed here can be performed by conventional 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 command

From a technical speech, uname, diff, date, sort and uns should be considered as a file command, but because they are often used in system management of diagnostics and maintenance routines, they explain them more meaningful.

Uname

Uname provides regular system information. When the -a option is specified, all available information is displayed:

$ uname -a linux 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), 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 -a speted 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 ICHON ICHON IEXTEN Echo Echoe Echok-Echonl -noflsh -Xcase -Tostop-Echoprt Echock ROPE The second line and third lines show special characters and key sequences that will be called on 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 Uses 375 DEC 5 2002 FDISK.out -RW-R --r - 1 Bluher Uses 2447 DEC 28 20:15 ls.out -rw-r - r - 1 Bluher Users 590 Jan 4 21:24 Greps.out -RW-R - R - 1 Bluher Uses 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 sort command in the pipeline, and the -c option can also be used 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 Another 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 $ lrm 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 / JOHN 1363 Documents

By default, DUs are also recursively printed for each subdirectory. This operation can limit this operation 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/jj 573./documents/ian 682./documents 2420 ./jdevhromE/system 8350 ./jdevhom (ssystem9.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-blocks 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 1249680 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 629748 83 Linux / dev / dev / HDA9 1817 1940 937408 83 linux

Process monitoring

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 SQLPLUSPID 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 TID PID PPID C Stime Tty Time CMD Oracle 1633 1 0 13:58? 00: 00: 00: ORA_DBW0_ORA1 ORA_DBW0_ORA1 ORACLE 1637 1 0 13:58 00: 00: 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: ORA_RECO_ORA1 ORACLE 1645 1 0 13:58? 00: 00: 00 oracle 1647 1 0 13:58? 00: 01: 18 ora_qmn0_ora1 oracle 1649 1 0 13:58? 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 Bash Bluh 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 Bluher 4112 3945 0 21:28 PTS / 5 00:08:42 SQLPLUS ... Then you can use the following The command will terminate it:

$ KILL 4112

Regular users 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 11M 10456 s 1.9 2.3 0:01 kdeinit 1986 Bluher 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 Bluher 20 0 16964 163 0:03 kdeinit 1800 Bluher 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 ...

shut down

It seems that this discussion should be ended in a shutdown command. Like many of the commands discussed in this article and the previous article, there is usually a replacement method in the form of a GUI to close your system. However, when you need to be turned off manually, you can use the following command to close:

$ shutdown -h now

You can use the following command to manually restart the system:

$ shutdown -r now

Note that these two commands require a specified time. You can specify "now" or use -t option with time seconds.

We discussed a lot of content in these two articles, but we absolutely unable to cover all content possible with Linux. There is still a lot of orders we have not discussed, and the command option we have not seen is more. However, here we want you to find at least to start managing the minimum tool required to manage Linux systems.

Sheryl Calish

It is a special study of Linux, a special study of Linux. She is also the Fund Chairman of Central Florida Oracle Uses Group and the sales chairman of IOUG Linux Sig.

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

New Post(0)