The “#” in the following information indicates that the operation is performed as the root user

The article directories

  • 1. Hostname instruction
  • 2. Id instruction
  • 3. Whoami instruction
  • 4. Ps-ef instruction (key)
  • 5. Top instruction (key)
  • 6. The du-sh command
  • 7. Find instruction
  • 8. Service instruction (key)
  • 9. Kill command (key)
  • 10. Ifconfig instruction (emphasis)
  • 11. Reboot instruction
  • 12. Shutdown command
  • 13. Uptime command
  • 14. Uname command
  • The netstat -tnlp command
  • 16. Man command
  • Second, exercises

1. Hostname instruction

  • Action: Operation server host name (read, set)
  • Grammar 1:# hostnameDescription: Output a complete host name

  • Syntax 2:# hostname -fFQDN (fully qualified domain name) in the current host name

2. Id instruction

  • View basic information about a user (including user ID, user group ID, additional group ID…) , this directive defaults to the current user if no user is specified.
  • Grammar 1:# idBy default, the basic information about the user who runs the command is displayed
  • Syntax 2:# id Specifies the user nameDisplays basic information about a specified user



    Verify that the above information is correct?
  • Verify user information: through files/etc/passwd
  • Verify user group information: Pass the file/etc/group

3. Whoami instruction

  • Role: “Who am I?” This command is used in shell scripts to obtain the user name of the current operation for logging.
  • Grammar:# whoami

4. Ps-ef instruction (key)

  • Instructions: ps
  • Function: Displays server process information
  • Meaning:

    -e: equivalent to”-A“, listing all processes

    -f: Displays all columns (displays all fields)
  • Execution Result:



    Column meaning:
  • UID: User of the processid;
  • PIDProcess:id;
  • PPID: Id of the parent process of the process. If the parent process of a program cannot be found, the process of the program is called a zombie process.parent process ID);
  • C: CPU usage, in the form of percentage;
  • STIME: The start time of the process;
  • TTY: Terminal device, identification symbol of the device that initiates the process. If?“Indicates that the process is not initiated by a terminal device.
  • TIME: Execution time of the process;
  • CMD: Indicates the name of the process or its path.

Example :(command used 100%) filter out the desired process status in the ps result

ps -ef| grep "process name"Copy the code



Another example is to view the firefox process:

5. Top instruction (key)

  • Role: View the resource usage of server processes (100% used)
  • Grammar:

    Enter command:# top(Dynamic display)

    Exit command: Pressqkey

Output result



Table meaning:

  • PID: process ID;
  • USER: User corresponding to the process;
  • PR: Priority;
  • VIRT: virtual memory;
  • RES: Resident memory;
  • SHR: Shared memory;
  • Calculate the actual memory used by a process = resident memory (RES) – Shared memory (SHR)
  • S: Indicates the process status. Status (sleepingSStands for sleep,RRunning);
  • %CPU: indicates the CPU usage percentage.
  • %MEM: indicates the percentage of memory usage.
  • TIME+: Execution time;
  • COMMAND: The name or path of the process;

While running top, you can press a handy shortcut key:

  • M: represents the result as memory (MEM) in descending order from highest to lowest;
  • P: displays the results in descending order of CPU usage from highest to lowest.
  • 1: Can be used when the server has multiple cpus.1“Shortcut key to switch whether to display the details of each CPU;

6. The du-sh command

  • Function: View the true size of a directory
  • Syntax: # du-sh directory path
  • -s: summaries are only displayed. -h: summaries are displayed in a readable format
  • Case: Statistics/root/yunweihenniuxThe actual size of the directory

  • Case: Statistics/etc“Actual directory size

7. Find instruction

  • Function: Used to find files (its parameters have as many as 55)
  • Grammar:# find The value of the path range option
  • Options:

    name: Search by document name (fuzzy search supported)

    type: Searches by document type

    Document type:”-“Represents the file (replaced with f when using find),”d“For folder
  • Case: UsefindTo search forhttpd.conf
find / -name httpd.conf
Copy the code

  • Example: Search all files in the etc directoryconfThe suffix file
find /etc -name *.conf
Copy the code

  • Case: UsefindTo search for/etc/sane.d/All files in the directory

  • Case: UsefindTo search for/etc/All folders in the directory
find /etc -type d
Copy the code

8. Service instruction (key)

  • Purpose: Controls the start/stop/restart of some software services
  • Grammar:Start /stop/restart
  • For example, you need to start the local installationApache(web server software), its service namehttpd
service httpd start
Copy the code

  • To check whether the HTTPD service is started, run the ps command:

9. Kill command (key)

  • Action: Kill a process (when zombie processes are encountered or the process needs to be shut down for some reason)
  • Grammar:# kill process PIDGrammar requires coordinationpsUsed together)
  • Case: NeedkilloffApacheThe process of

  • withkillA similar but better command than kill to kill a process:killall
  • Grammar:# killall Process name

10. Ifconfig instruction (emphasis)

  • Function: Used to operate the nic related commands.
  • Simple syntax:# ifconfig(Obtain nic information)



    Eth0Represents a network card in Linux,eth0Is its name.Lo(loop, local return network card, itsipThe address is usually127.0.0.1) is also a network card name.



    Note:inet addrThat’s the network cardipAddress.

11. Reboot instruction

  • Effect: Restart the computer
  • Grammar 1:# rebootrestart
  • Syntax 2:# reboot -wSimulate a restart, but do not restart (only write shutdown and startup logs)

12. Shutdown command

  • Function: Power off (with caution)
  • Grammar 1:# shutdown -h nowor# shutdown -h 15:25
  • Example: Set the Shutdown time of the Linux system to 12:00

  • If you want to cancel the shutdown plan, you can do the following:

    For versions earlier than Centos 7.x:ctrl+c

    ② For versions later than Centos 7.x (included) :# shutdown -c
  • In addition toshutdownIn addition to shutdown, there are the following shutdown commands:
init 0
halt
poweroff
Copy the code

13. Uptime command

  • Function: Output the duration of the computer online (the time the computer has been running since startup)
  • Grammar:# uptime

14. Uname command

  • Function: Obtain information about computer operating system
  • Grammar 1:# unameGets the type of the operating system
  • Syntax 2:# uname -aAll: obtains all system information (type, host name, kernel version, release time, and open source plan)

The netstat -tnlp command

  • Function: View the network connection status
  • Grammar:# netstat -tnlp



    Options:
  • -t: indicates that only TCP connections are listed.
  • -n: converts an address from a letter combination to an IP address and a protocol to a port number.
  • -l: indicates filtering outstateThe value in the (status) “column isLISTEN(listening) connection;
  • -p: displays the process that initiates the connectionpidAnd process name;

16. Man command

  • Function:manual, manual (contains all command manuals in Linux, English)
  • Grammar:# man commandExit pressqKey)
  • Example: Run the man command to query the usage of the cp command
man cp
Copy the code

Second, exercises

  1. How do I restart the Linux OPERATING system on the CLI?
reboot
Copy the code
  1. How can I quickly delete the content before and after the cursor on the COMMAND line interface?

    Before:ctrl + uAfter:ctrl + k
  2. How to delete/tmpUnder allAFile at the beginning?
rm -f /tmp/A* 
Copy the code
  1. Important system files need to be backed up, how to do/etc/passwdBackup to/tmpDirectory?
cp /etc/passwd /tmp/
Copy the code
  1. How do I view the last three users created by the system?
tail - 3 /etc/passwd
Copy the code
  1. What command counts the number of accounts in the system?
wc -l /etc/passwd   
Copy the code

or

 cat /etc/passwd|wc -l
Copy the code
  1. How to create/tmp/test.confFile?
touch /tmp/test.conf
Copy the code
  1. How to open via Vim edit/tmp/test.conf?
vim /tmp/test.conf
Copy the code
  1. How to view/etc/passwdThe first three lines and the last three lines?
head - 3 /etc/passwd
tail - 3 /etc/passwd
Copy the code
  1. How do I create a directory at once/text/1/2/3/4?
mkdir -p /text/1/2/3/4
Copy the code
  1. How to return to the current account home directory the fastest?
cd ~		
Copy the code

or

cd
Copy the code
  1. How to view/etcDisk space occupied?
du -sh /etc
Copy the code
  1. How to delete/tmpAll the files?
rm -rf /tmp/*
Copy the code
  1. Try to start the Apache service and check that it started successfully.
service httpd start
ps -ef|grep httpd
Copy the code
  1. Kill the Apache process using the learned command.
killall httpd
Copy the code