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:
# hostname
Description: Output a complete host name
- Syntax 2:
# hostname -f
FQDN (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:
# id
By default, the basic information about the user who runs the command is displayed - Syntax 2:
# id Specifies the user name
Displays 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
;PID
Process: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: Pressq
key
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 (sleepingS
Stands for sleep,R
Running);%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/yunweihenniux
The 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: Use
find
To search forhttpd.conf
find / -name httpd.conf
Copy the code
- Example: Search all files in the etc directory
conf
The suffix file
find /etc -name *.conf
Copy the code
- Case: Use
find
To search for/etc/sane.d/
All files in the directory
- Case: Use
find
To 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 installation
Apache
(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 PID
Grammar requires coordinationps
Used together) - Case: Need
kill
offApache
The process of
- with
kill
A 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)
Eth0
Represents a network card in Linux,eth0
Is its name.Lo
(loop
, local return network card, itsip
The address is usually127.0.0.1
) is also a network card name.
Note:inet addr
That’s the network cardip
Address.
11. Reboot instruction
- Effect: Restart the computer
- Grammar 1:
# reboot
restart - Syntax 2:
# reboot -w
Simulate a restart, but do not restart (only write shutdown and startup logs)
12. Shutdown command
- Function: Power off (with caution)
- Grammar 1:
# shutdown -h now
or# 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 to
shutdown
In 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:
# uname
Gets the type of the operating system - Syntax 2:
# uname -a
All: 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 outstate
The value in the (status) “column isLISTEN
(listening) connection;-p
: displays the process that initiates the connectionpid
And process name;
16. Man command
- Function:
manual
, manual (contains all command manuals in Linux, English) - Grammar:
# man command
Exit pressq
Key) - Example: Run the man command to query the usage of the cp command
man cp
Copy the code
Second, exercises
- How do I restart the Linux OPERATING system on the CLI?
reboot
Copy the code
- How can I quickly delete the content before and after the cursor on the COMMAND line interface?
Before:ctrl + u
After:ctrl + k
- How to delete
/tmp
Under allA
File at the beginning?
rm -f /tmp/A*
Copy the code
- Important system files need to be backed up, how to do
/etc/passwd
Backup to/tmp
Directory?
cp /etc/passwd /tmp/
Copy the code
- How do I view the last three users created by the system?
tail - 3 /etc/passwd
Copy the code
- 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
- How to create
/tmp/test.conf
File?
touch /tmp/test.conf
Copy the code
- How to open via Vim edit
/tmp/test.conf
?
vim /tmp/test.conf
Copy the code
- How to view
/etc/passwd
The first three lines and the last three lines?
head - 3 /etc/passwd
tail - 3 /etc/passwd
Copy the code
- How do I create a directory at once
/text/1/2/3/4
?
mkdir -p /text/1/2/3/4
Copy the code
- How to return to the current account home directory the fastest?
cd ~
Copy the code
or
cd
Copy the code
- How to view
/etc
Disk space occupied?
du -sh /etc
Copy the code
- How to delete
/tmp
All the files?
rm -rf /tmp/*
Copy the code
- Try to start the Apache service and check that it started successfully.
service httpd start
ps -ef|grep httpd
Copy the code
- Kill the Apache process using the learned command.
killall httpd
Copy the code