Summary of Common commands in Linux and summary of Common commands in linux

Source: Internet
Author: User

Summary of Common commands in Linux and summary of Common commands in linux

Command Format: Command-option parameters, such as ls-la/usr. When multiple options are available, they can be written together.
Ifconfig: view the IP address of the Current Machine
Service network restart: restart the network service
Service iptables status: view the Firewall status of the Current Machine
Hostname XX: view or modify the Host Name
Pwd: view the 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 file content (small files)
More file name: displays the file content (large files), uses spaces to flip the page, 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 number of rows before the file
Tail-number [file name]: view the number of rows after the file
Function of modifying file name in mv 1: mv [source file name] [new file name]
2. Move the 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: permission to change a file or directory.
Shape: chmod g + w filename
Shape: chmod 761 filename

Example: Create a new directory with the following new file and try to use a common user to delete the new file under the new directory.
1. Try to modify: Set the read and write permissions of the new file to 777 to delete the file.
2. Try to modify: Set the read and write permissions of the new directory to 777 to delete files.

File rwx permissions:
R: You can perform catch, more, and other read operations.
W: Modify the file content and perform other write operations, but this does not mean you can delete the file.
X: perform operations on the file.
Directory rwx permission:
R: A readable operation that can list the contents of a directory, such as the ls command.
W: Permission to create or delete files in a directory.
X: indicates that you can enter this directory (basically, all directories have the rx permission ).
Therefore, the permission to delete files is the write permission for the directory where your current file is located.

Command: chown
Syntax: chown user File
Description: used to change the file owner.
Example: chown newuser t1.sh
Useradd username Add User
Passwd username: Set the password for the user

Command: chgrp
Syntax: chgrp group file
Description: used to change the group to which the object belongs.
Example: chgrp adm t1.sh
View the default permissions of the system: umask-S (umask: view the permission mask value 022. Use 777-022 to obtain the real permissions)

Command: find
Syntax: find [search range path]-name [file name] (search by file name)
Find [search range path]-size [(+-) file size] (search by file size, greater than + less -)
Find [search range path]-user (file owner)
Find [Time query] [In days]
[In days] 1 ctime, atime, mtime
[In minutes] 2 cmin, amin, and mmin
.....
Description: searches for any file or directory (all)

Find [Time query] [In days]
Days: ctime, atime, mtime
Minutes: cmin, amin, and mmin
C: change indicates the meaning of changing the file attributes (such as owner, owner group, and permission change ).
A: access indicates the meaning of access (for example, viewed ).
M indicates the meaning of the modified content in modify.
Before the time, add:-within the time range, + outside the time range.


Find application connector:
-A (and meaning, logic and)
-O (or meaning, logic or)

Find: search by file type:
-Type
Where: f indicates a binary file, and l indicates a soft connection file d indicates a directory.

Find connection execution symbol:
Find...-exec [Execute Command] {}\;
Note: "{}" indicates the search result of the find command, and "\" indicates the escape character.
Find...-exec [Execute Command] {}\;
Find...-OK [Execute Command] {}\;
The difference between OK and exec is that OK has the meaning of asking for confirmation.
Find-inum [I node number] searches for files based on the I node. in linux, all files have a unique identifier for linux kernel to call. This is the I node.

Command: locate
Syntax: locate [file name]
Description: Search for files. Based on the internal index of the linux database (updatedb command, you can manually update the updatedb database, which is generally used with locate)
Note: The locate search speed is very fast, which is much faster than the find search speed. The reason is that locate looks for the index value of the file database built in linux, so the search speed is very fast, however, sometimes the newly created file cannot be found using the locate command because the index of the file is not immediately updated to the file database of the linux system.

Command: man
Syntax: man [command or configuration file],
Description: The HELP command is very useful. You can get the help documentation for the command and how to use it.

Command: whatis
Syntax: whatis [command]
Description: view the command description.

Command: -- help
Syntax: [command] -- help
Description: used to view the options of a command.

Command: gzip
Syntax: gzip [file name]
Description: The original file is not retained during compression, and the directory cannot be compressed.

Command: gunzip
Syntax: gunzip [compressed files]
Description: Decompress the file without retaining the source file.

Command: tar
Syntax: tar [zcvf] [zxvf] [package file name .tar.gz] [source file]
-C: generate a tar package file (required)
-Extract files generated by x (required)
-V: Show Details
-F: Specifies the compressed file name.
-Z package and compress
Description: The suffix .tar.gz generated by the package directory, or decompress the package.
Add "-C" to indicate the path to the file after decompression.
File command to view any file type

Command: zip
Syntax: zip option [-r] [compressed file name] [source file]
Description: The zip format is common for windows and linux. files and directories can be compressed. You need option-r to compress directories.

Command: unzip
Syntax: unzip [decompressed file]
Description: Decompress the package.
Add "-d" to the configuration to indicate the path to the file after decompression.

Ping
(Note: There are many reasons for ping failure to the peer network. You need to troubleshoot the problem step by step)
(1) ping the loopback address 127.0.0.1 to check whether the network protocol of the local machine is correct.
(2) ping the ip address of the Local Machine to check whether the network on the local machine is correct.
(3) Check the peer network settings, firewalls, plug-ins, and so on.
(4) If the packet loss rate is found, it may be caused by the network or network cable.
(5) ping the configuration option ping-c 6 192.168.80.100 (indicating that the IP address is disconnected after the ping is 6 times)
(6) ping the configuration option ping-s 60000 (max. 65507)

View Nic information: ifconfig
Shutdown: shutdown-h now
Restart: reboot
Ctrl + l clear screen.
Ctrl + c to exit the application.
Tab key to complete information.

Filter: grep. You can filter the specified content and output it.

MPs queue:
Send the output of one command to another as the input of another command. Pipeline can connect N commands.
Ls-l/etc | more (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 result of the preceding command)
Ls-l/etc | grep init (indicating to filter the output results of ls-l/etc and display the results as init)
Ls-l/etc | grep init | wc-l (the number of the last statistics is displayed)

Logic and (&&)
Such as ls & pwd (if the first command is successfully executed. The second command will be executed)
Logic or (|)
Such as ls | pwd (if the first command is successfully executed, the second command is not executed. If the First Command fails, the second command is executed)

Input/Output redirection:
Shell predefines three file descriptions (0, 1, 2) for each process)
0 (stdin) standard input 1 (stdout) standard output 2 (stderr) standard error output
Output redirection: displays the output result to a file (> indicates output redirection)

 

File Information Description:
Drwxr-xr-x. 2 root 6 Nov 5 2016 etc.
D: Start with d, indicating directory, indicating folder
-: Starts with-, indicating a normal binary file.
L: Start with l, indicating the soft connection file (link)
R: read Permission, w: write permission, and x: execute Permission
Files in Linux, such as drwxr-xr-x, can be viewed as three parts (rwx r-x): The file owner rwx (user) permissions, r-x (group) permissions of the group, and r-x (others) permissions of others


After entering the edit text, you must press a, I, or o to edit the text.
The operation order for exiting text editing is: Press ESC first, then press SHIFT +:, enter wq to save and exit, and enter q! Does not save and exits forcibly


Linux File description
1. File rwx
2. Hard connections
3. Owner
4. Group
5. File size (inaccurate)
6. File Creation or modification time
7. File Name

/Usr/software/JDK/glasis1.8.0 _ 131
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

CentOS 7.0 uses firewall as the firewall by default. Here we change it to iptables firewall.

1. Disable firewall:
Systemctl stop firewalld. service # stop firewall
Systemctl disable firewalld. service # disable firewall startup
Firewall-cmd -- state # view the default firewall Status (notrunning is displayed after the firewall is disabled, and running is displayed after the firewall is enabled)

2. iptables firewall (iptables has been installed and is configured below)
Vi/etc/sysconfig/iptables # edit the 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: Port 80 and port 8080 are used as examples. * ** It is generally added to the top or bottom of the line "-a input-p tcp-m state -- state NEW-m tcp -- dport 22-j ACCEPT, do not add it to the last line; otherwise, it will not take effect after the firewall is restarted.
Systemctlrestart iptables. service # restart the firewall to make the configuration take effect.
Systemctlenable iptables. service # Set firewall startup

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.