Home >Operation and Maintenance >Linux Operation and Maintenance >Summary of commonly used commands in Linux systems
Command format: command - option parameters, for example: ls -la /usr; when there are multiple options, they can be written together.
ifconfig: View the IP information of the current machine
service network restart: Restart the network service
service iptables status: View the current machine firewall status
hostname XX: View or modify the host name
pwd: View Full path of the current file
ls -l or ll or ls: View the contents of the current directory
cat File name: Indicates viewing the content of the file (small file)
more File name: Indicates viewing the content of the file (large file ), use spaces to turn pages, press Enter to display the next line, q (or ctrl+c) to exit
mkdir: Create a folder
mkdir -p d3/d4/d5: Recursively create a folder
touch : Create a file
head -number [file name]: View the first number of lines of the file
tail -number [file name]: View the last number of lines of the file
mv 1 Function to modify the file name: mv [ Source file name] [New file name]
2 Move file location: mv [Source file name] [New file location + New file name]
Command: chmod
Syntax: chmod [{ugo }{+-=}{rwx}] [File or directory]
chmod [mode=421] [File directory]
Description: Change the permissions of the file or directory
Form: chmod g+w filename
Form: chmod 761 filename
Problem example: Create a new directory with a new file below it. Try to use an ordinary user to delete the new file in the new directory.
1 Try to modify: Set the read and write permissions of the new file to 777, and delete the file
2 Try to modify: Set the read and write permissions of the new directory to 777, and delete the file
rwx permissions:
r: Can perform read operations such as catch and more.
w: Modify the content of the file and other write operations, but it does not mean that you can delete the file.
x: Perform operations on files.
rwx permissions of the directory:
r: Readable operation, you can list the contents of the directory, such as the ls command.
w: Indicates the permission to create or delete files in the directory.
x: Indicates that you can enter this directory (basically all directories will have rx permissions).
So: the permission to delete a file is to have the write permission of the directory where your current file is located.
Command: chown
Syntax: chown user file
Description: Change the owner of the file
Example: chown newuser t1.sh
useradd username Add user
passwd username is User set password
Command: chgrp
Syntax: chgrp group file
Description: Change the group to which the file belongs
Example: chgrp adm t1.sh
View system default permissions: umask -S (umask view permission mask value 022, use 777-022 to get the real permissions)
Command: find
Syntax: find [search range path] -name [file name] (search based on file name)
find [search range path] -size [(+-) file size] (search based on file size, greater than + and less than -)
find [search range path] -user (owner of the file)
find [time search] [in days]
[in days] 1 ctime, atime, mtime
[in minutes] 2 cmin, amin, mmin
. . . . .
Description: Find any file or directory (all)
find [Time search] [in days]
Days: ctime, atime, mtime
Minutes: cmin, amin, mmin
c means: change means changing file attributes (such as owner, group, permission change).
a means: access means that it has been accessed (such as viewed, etc.).
m means: modify means changing the content.
Add in front of the time: - means inside, + means outside
Find the applied connector:
-a (meaning and, logical AND)
-o (or means logical or)
find search: search based on file type:
-type
where: f represents a binary file, l represents a soft link file, d represents a directory
Find connection execution symbol:
find ... -exec [execution command] {} \;
Note: "{}" represents the result of the find command, and "\" represents the escape character
find ... -exec [Execute command] {} \;
find ... -ok [Execute command] {} \;
The difference between ok and exec is that ok means asking for confirmation.
find -inum [i node label] Find files based on i node. In the Linux system, all files have a unique identifier, which is convenient for the Linux kernel to call. This is the i node
command: locate
Syntax: locate [file name]
Description: Find files according to the index inside the Linux database (updatedb command, you can manually update the updatedb database, generally used in conjunction with locate)
Note: The search speed of locate Very fast, much faster than find. The reason is that locate searches for the index value of the file database built by the Linux system, so it is very fast. However, sometimes newly created files cannot be found using the locate command. The reason is that the file The index is not immediately updated to the Linux system file database.
Command: man
Syntax: man [command or configuration file],
Description: Help command, very useful, you can get help documentation for the command, how to use it, etc.
Command: whatis
Syntax: whatis [command]
Description: View the description of the command.
Command: --help
Syntax: [Command] --help
Description: View command option usage.
Command: gzip
Syntax: gzip [file name]
Description: The original file is not retained during compression, and only files can be compressed but not directories
Command: gunzip
Syntax: gunzip [compressed file]
Description: Decompress the file without retaining the source file
Command: tar
Syntax: tar [zcvf] [zxvf] [package file name .tar.gz] [Source file]
-c Generate tar package file (required)
-x Generate decompressed file (required)
-v Display detailed information
-f Specify Compressed file name
-z Pack and compress simultaneously
Description: The suffix name .tar.gz generated by the packaging directory, or decompression
Add -C in the final configuration to indicate the path where the file will be stored after decompression
The file command can view the type of any file
Command: zip
Syntax: zip option [-r] [Compressed file name] [Source file]
Description: The format of zip is windows and linux A common format that can compress files and directories. The option -r is required when compressing directories.
Command: unzip
Syntax: unzip [decompressed file]
Description: Decompress
Add -d in the final configuration to indicate the path where the file will be stored after decompression
ping
(Note: There are many reasons why ping cannot reach the other party's network, and you need to investigate in detail step by step)
(1) First, ping the loopback address 127.0.0.1 to check whether the network protocol of your own machine is correct
( 2) Ping the local IP again to see if your local network is correct
(3) Then check the other party’s network settings, firewall, plug-ins, etc.
(4) If you find that there are lost packets in the packet loss rate, It may be caused by the network or network cable
(5) Ping configuration option ping -c 6 192.168.80.100 (meaning it will be disconnected after pinging 6 times)
(6) Ping configuration option ping -s 60000 (maximum 65507)
View network card information: ifconfig
Shutdown: shutdown -h now
Restart: reboot
ctrl + l Clear the screen.
ctrl + c Exit the application.
Tab key, information completion.
Filtering: grep, you can filter the specified content and then output it.
Pipeline:
Transmit the output of one command to another command as the input of another command. Pipes can connect N commands.
ls -l /etc | more (indicates that the output of ls -l /etc is used as the input of the more command, that is, the content browsed by the more command is the output of the previous command)
ls -l /etc | grep init (indicates that the output results of ls -l /etc are filtered and displayed as the results of init)
ls -l /etc | grep init | wc -l (the last number of statistics displayed)
Logical AND (&&)
Form: ls && pwd (If the first command is executed successfully, the second command will be executed)
Logical OR (||)
Form: ls || pwd (If the first command is executed successfully, the second one will not be executed. If the first command fails, the second one will be executed)
Input and output redirection:
Shell is predefined for each process 3 file descriptors (0,1,2)
0 (stdin) standard input 1 (stdout) standard output 2 (stderr) standard error output
Output redirection: is to display the output results to a On the file (> indicates output redirection)
File information description:
drwxr-xr-x. 2 root root 6 Nov 5 2016 etc
d: Start with d, indicates directory, indicates folder
-: starts with -, indicates ordinary binary file
l: starts with l, indicates soft link file (link)
r: read permission, w: write write permissions, The permissions of r-x (group) and the permissions of others r-x (others)
After entering the text editing, you need to press a or i or o to edit the text
Exit the text editing operation The sequence is: first press the ESC key, then press SHIFT + :, enter wq to save and exit, enter q! to not save and force exit
Linux file description
1. File rwx
2, hard connection number
3, owner
4, group to which it belongs
5, file size (not precise)
6, file creation or modification time
7, The name of the file
export JAVA_HOME=/usr/software/JDK/jdk1.8.0_131
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
1. Close firewall:
systemctl stop firewalld.service #Stop firewall
systemctl disable firewalld.service #Disable firewall startup
firewall-cmd --state #View the default firewall status (displayed after closing) notrunning, running will be displayed after turning it on)
2. iptables firewall (iptables has been installed here, configure it below)
vi/etc/sysconfig/iptables #Edit firewall configuration file
# sampleconfiguration for iptables service
# you can edit thismanually or use system-config-firewall
# please do not askus to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT[0:0]
:OUTPUT ACCEPT[0:0]
-A INPUT -m state--state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -jACCEPT
-A INPUT -i lo -jACCEPT
-A INPUT -p tcp -mstate --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state -- state NEW -m tcp --dport 80 -jACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080-j ACCEPT
-A INPUT -j REJECT--reject- with icmp-host-prohibited
-A FORWARD -jREJECT --reject-with icmp-host-prohibited
COMMIT
:wq! #Save and exit
Note: 80 and 8080 are used here Take port as an example. The *** part is generally added above or below the "-A INPUT -p tcp -m state --state NEW -m tcp--dport 22 -j ACCEPT" line. Remember not to add it to the last line, otherwise the firewall will not work after restarting. Take effect.
systemctlrestart iptables.service #Finally restart the firewall to make the configuration take effect
systemctlenable iptables.service #Set the firewall to start at boot
The above is the detailed content of Summary of commonly used commands in Linux systems. For more information, please follow other related articles on the PHP Chinese website!