Linux Common system work commands

Source: Internet
Author: User
Tags bz2 echo command memory usage terminates

1. Echo command

The echo command is used in the terminal output string or variable after the value is extracted, in the format "echo [string | $ variable]".

For example, the command to output the specified string "linuxprobe.com" to the terminal screen is:

[Email protected] ~]# echo linuxprobe.com

The command displays the following information on the terminal screen:

Linuxprobe.com

Below, we use the $ variable to extract the value of the variable shell and output it to the screen:

[Email protected] ~]# echo $SHELL/bin/bash
2. Date command

The date command is used to display and set the time or date of the system in the format "date [options] [+ Specified format]".

Simply enter a parameter that begins with a "+" in the powerful date command to output the system's time or date in the specified format, so that the command of the backup data can be combined with the time information that is output from the specified format when you work on a daily basis. For example, the packaged files are automatically packaged in the "year-month-day" format to "backup-2017-9-1.tar.gz", the user only need to look at the file name to be able to understand the backup time of each file. The parameter formats and functions that are common in the date command are shown in table 1.

Table 1 parameters and functions in the date command

Parameters

Role

%t

Jump Grid [Tab key]

%H

Hours (00~23)

%I

Hours (00~12)

%M

Minutes (00~59)

%s

Seconds (00~59)

%j

The first day of the year


The date command to view the current system time in the default format is as follows:

[[email protected] ~]# Datesat  4 22:25:46 EDT 2018

The date command to view the current system time in the format "year-month-day hours: minutes: Seconds" is as follows:

[Email protected] ~]# date "+%y-%m-%d%h:%m:%s" 2018-08-04 22:28:50[[email protected] ~]# date "+%y-%m-%d%i:%m:%s" 20 18-08-04 10:29:11

The date command to set the current time of the system to August 5, 2018 10:30 is as follows:

[Email protected] ~]# date-s "20180805 10:30:00" Sun  5 10:30:00 EDT 2018

Use the date command again and view the current system time in the default format, as follows:

[[email protected] ~]# Datesun  5 10:30:09 EDT 2018

The parameter%j in the date command can be used to see today is the day ordinal of the year. This parameter is a good way to distinguish between the old and the new of the backup time, that is, the larger the number, the closer the current time. The way the parameter is used and the results shown are as follows.

[[Email protected] ~]# Date "+%j" 217
3. Reboot command

The reboot command is used to restart the system in the form of reboot.

Since restarting the computer involves the management of the hardware resources, it is only possible to restart with the root administrator by default, with the following commands:

[email protected] ~]# reboot
4. Poweroff command

The Poweroff command is used to shut down the system in the form of Poweroff.

This command is the same as the reboot command, which involves the administrative rights of the hardware resource, so the computer can be turned off by default only by the root administrator, with the following commands:

[Email protected] ~]# Poweroff
5. wget command

The wget command is used to download the network file in the terminal in the format "wget [parameters]", as shown in table 2 for the parameters of the wget command and the role of the parameters.

Table 2 parameters and functions of the wget command

Parameters

Role

-B

Background Download mode

-P

Download to the specified directory

-T

Maximum number of attempts

-C

Breakpoint Continuation

-P

Download all the resources in the page, including pictures, videos, etc.

-R

Recursive download

Try using the wget command to download the latest Python3.7 document, the full path of this file is https://docs.python.org/3/archives/ python-3.7.0-docs-pdf-letter.tar.bz2, the download effect after executing the command is as follows:

[[Email protected] ~]#wget https://docs.python.org/3/archives/python-3.7.0-docs-pdf-letter.tar.bz2--2018-08-05 07:51:25--https://docs.python.org/3/archives/python-3.7.0-docs-pdf-letter.tar.bz2Resolving docs.python.org (docs.python.org) ...151.101.72.223, 2a04:4e42:36::223Connecting to docs.python.org (docs.python.org)|151.101.72.223|:443... connected. HTTP request sent, awaiting response ...200oklength:13984044 (13M) [application/octet-Stream] Saving to: ' Python-3.7.0-docs-pdf-letter.tar.bz2 '100%[======================================>] 13,984,044 864kb/sinch17s2018-08-05 07:51:43 (804 kb/s)-' python-3.7.0-docs-pdf-letter.tar.bz2 ' saved [13984044/13984044][[email protected] ~]# 

Next, we use the wget command to recursively download all the page data and files in the https://docs.python.org Web site, which are automatically saved to the directory named docs.python.org under the current path after the download is complete. The command to perform the operation is Wget-r-P https://docs.python.org, which results in the following execution.

[[Email protected] ~]#wget-r-P https://docs.python.org--2018-08-05 08:00:01--https://docs.python.org/Resolving docs.python.org (docs.python.org) ...151.101.72.223, 2a04:4e42:36::223Connecting to docs.python.org (docs.python.org)|151.101.72.223|:443... connected. HTTP request sent, awaiting response ...60WMoved Temporarilylocation:https:docs.python.org/3/[following]--2018-08-05 08:00:02--https://docs.python.org/3/reusing existing connection to docs.python.org:443. HTTP request sent, awaiting response ...200oklength:9875 (9.6K) [text/HTML] Saving to: ' Docs.python.org/index.html '100%[======================================>] 9,875--.-k/sinch0.001s2018-08-05 08:00:02 (17.0 MB/s)-' docs.python.org/index.html ' saved [9875/9875]loading robots.txt; Please ignore errors.--2018-08-05 08:00:02--https://docs.python.org/robots.txtreusing Existing connection to docs.python.org:443. HTTP request sent, awaiting response ...200oklength:129 [text/Plain] Saving to: ' Docs.python.org/robots.txt '100%[======================================>] 129--.-k/sinch0s2018-08-05 08:00:02 (13.0 MB/s)-' docs.python.org/robots.txt ' saved [129/129]
.................... Omit the download process ......... .....
6. PS command

The PS command is used to view the status of the process in the system, in the format "PS [parameters]".

It is estimated that the reader will be stunned at the first execution of this command-how can you see so many output values? In fact, we usually use the PS command with the pipe-character technology to crawl the PID number corresponding to a given service process. The common parameters and functions of the PS command are shown in table 3.

Table 3 The parameters and functions of the PS command

Parameters

Role

-A

Show all processes (including other users ' processes)

-U

User and other details

-X

Show process without control terminal

Linux systems run many processes at all times and can optimize the performance of the system if they can be managed properly. In the Linux system, there are 5 common process states, namely, run, interrupt, non-interruptible, zombie and stop, the respective meanings are as follows.

    • R (Run): The process is running or waiting in the running queue.
    • S (Interrupt): The process is in hibernation and is out of the state when a condition is formed or when a signal is received.
    • D (non-interruptible): The process does not respond to system asynchronous signals and cannot be interrupted even with the kill command.
    • Z (Zombie): The process has terminated, but the process descriptor persists until the parent process calls the WAIT4 () system function to release the process.
    • T (stop): The process stops running after it receives a stop signal.

When the PS aux command is executed, you will typically see the process status shown in table 7, table 4 shows only partial output values, and the normal output values do not include Chinese annotations.

Table 4 Process Status

USER

PID

%cpu

%MEM

VSZ

RSS

TTY

STAT

START

time

COMMAND

Process Owner

process ID number

operator occupancy

Memory usage

Virtual memory usage (in kilobytes)

The fixed amount of storage (in kilobytes)

process

status

started

time

actual use of
CPU time

Command name and parameter

root

1

0.0

0.4

53684

7628

?

ss

07:22

0:02

/usr/lib/systemd/systemd

Root

2

0.0

0.0

0

0

?

S

07:22

0:00

[Kthreadd]

Root

3

0.0

0.0

0

0

?

S

07:22

0:00

[ksoftirqd/0]

Root

5

0.0

0.0

0

0

?

s<

07:22

0:00

[KWORKER/0:0H]

Root

7

0.0

0.0

0

0

?

S

07:22

0:00

[migration/0]

.................. Omit part of the output information ...... .....

Note: As mentioned earlier, in the Linux system command parameters have a short format, long and long format can not be merged between the long format and the short form can not be merged, but the short format and the short form may be merged, after merging only one-(minus) can be retained. In addition, the PS command allows the parameter to be added without a minus sign (-), so it can be directly written as PS aux.

7. Top command

The top command is used to dynamically monitor information such as process activity and system load, in the form of top.

The top command is quite powerful and is able to view the system operation status dynamically, fully viewing it as an "enhanced version of Windows Task Manager" in Linux. The top command runs on interface 1 as shown:

Figure 1 running interface of the top command

In Figure 1, the top command performs the statistical information of the top 5 behavior system as a whole, which represents the following meanings.

    • Line 1th: System time, run time, number of login terminals, system load (three values are 1 minutes, 5 minutes, 15 minutes of average, the smaller the value means the lower the load).
    • Line 2nd: Total number of processes, number of processes running, number of processes in sleep, number of processes stopped, number of dead processes.
    • Line 3rd: Percentage of resources consumed by the user, percentage of resources consumed by the system kernel, percentage of process resources that have changed priority, percentage of idle resources, etc.
    • Line 4th: Total physical memory, memory usage, memory idle, amount of memory as the kernel cache.
    • Line 5th: Total amount of virtual memory, virtual memory usage, amount of virtual memory idle, amount of memory that has been loaded in advance.

Note: The data in line 3rd is CPU data and is displayed in percent format, such as "54.0 ID", which means that 54% of CPU processor resources are idle.

8. Pidof command

The PIDOF command is used to query the PID value of a specified service process in the format "pidof [parameter] [service name]".

Process number values (PID) are unique for each process, so different processes can be distinguished by PID. For example, you can use the following command to query the PID of a native sshd service program:

[Email protected] ~]# pidof sshd1657
9. Kill command

The KILL command terminates a service process for a specified PID in the format "kill [parameter] [process PID]".

Next, we use the KILL command to terminate the process represented by the PID that was queried by the Pidof command, as shown in the following command. The effect of this operation is equivalent to forcing the SSHD service to stop.

[[email protected] ~]# kill 1657
10. Killall command

The killall command terminates all processes for a service of a specified name in the format: "killall [parameter] [service name]".

Typically, a service program for complex software has multiple processes that work together to provide services to the user, and if it is cumbersome to end these processes one at a time, you can use the Killall command to bulk end all the processes that a service program has. The following is an example of the HTTPD service program, to end all of its processes. Because the RHEL7 system does not install the HTTPD service program by default, so we only need to look at the operation process and output results, and so on after learning the relevant content to practice.

[Email protected] ~]# pidof httpd13581 13580 13579 13578 13577 13576[[email protected] ~]# killall httpd[[Email P Rotected] ~]# pidof httpd   

Note: If we want to stop it immediately after executing a command in the system terminal, you can press CTRL + C key combination at the same time (one of the more common shortcuts in the production environment), which will immediately terminate the process of the command. Alternatively, if some commands continue to output information on the screen at execution time, affecting the input of subsequent commands, you can add the last & symbol at the end of the command, so that the command goes into the system background to execute.

Linux Common system work commands

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.