Share common linux commands on centos 7 and centos 7

Source: Internet
Author: User

Share common linux commands on centos 7 and centos 7

I. Preface

Linux is vast and sea-like, and the linux knowledge required for server deployment is not much. The following is a common command for deploying projects on centOS7 ECs for linux development, as a simple summary.

Ii. File Processing

1. Display

Ls (ls: list): Content in the current directory-file name

Cd folder (cd: change directory, the folder can be nested in multiple layers) to enter, cd ../(../can be nested in multiple layers, directly at the upper level .. press Enter): Return to the upper level

I.: can also represent the current directory,...: represents the parent directory of the current directory

Ⅱ cd ~ : Switch to the user's main directory (or press enter directly). Generally, it takes a lot of processing to access the file. If you get lost, use the most direct method.

Windows has a graphical interface. When you click a folder, you can see the content in it,

Linux uses cd to the corresponding directory, and then ls to display the content. The configuration of ls and cd is most frequently used.

① Ls-l (can be abbreviated as ll): + permission + number of files under the directory + owner of the file directory + User Group + date

② Ls-lh: + file size and Unit

③ Ls-lha: + hide a file

④ Ls-help: + instructions for use

-Help is a useful linux Command tool. When you forget the specific usage of the command, you can get an authoritative introduction immediately.

⑤ Ls folder name (multi-layer nesting): view the content in the specified folder

When you are clear about the file directory of the linux server, you can also use the tab key to automatically complete the check to check whether the memory is correct, which can greatly reduce the use of cd + ls.

⑥ Ctrl + l: ls displays too much information. You can use it to clear the interface. However, you can slide to view the previous information,

2. Edit

In ECs, you often need to modify the configuration information in the software and use the following knowledge:

Cat> file name: Enter the specified file and edit it. (If the file does not exist, the file will be created. This is similar to MongoDB)

After editing, press ctrl + d to exit the editing.

① Cat file name: view the File Content

② Cat file name | less: Only displays the content of a single screen. Flip the blank space key backward, flip forward B, and exit q,

③ Echo edit content> file name: Enter the specified folder

④ Vim file name: Modify the file content,

I ctrl + f flip back,

Ⅱ ctrl + B flip forward,

Ⅲ. The cursor key controls the cursor position,

IV I: Enter the editing mode. You can modify the content,

V. Exit editing with Esc,

VI: q! Do not save changes,

VII: wq! Save changes and exit

3. Delete

Rm file name (rm: remove): Delete the specified file. Then, you will be asked whether to delete the file. If yes, enter yes. If no, enter no, but the directory cannot be deleted.

Directory Creation Method

I. mkdir directory name (mkdir: make directory): Create a folder

Ⅱ mkdir-p upper-level directory name/lower-level directory name (parents): create multi-level folder

① Rm-r folder name (-r: recursive): deletes the specified directory.

② Rm-rf folder name (-f: force): No prompt is displayed when you delete the folder.

Generally, the above one is used for deletion.

③ Rm-rf folder name A/*: delete all contents under directory name A (except for files starting)

4. Copy

New cp file name (cp: copy): copy a file

① Cp-t folder name copied file name (-t: target directory): copy the file to the specified folder instead of the folder

② Cp-r: directory where the copied directory accepts files (-r: recursive recursion): copy the entire folder to the specified folder.

③ Cp-help: View command instructions.-help is common.

5. Mobile

Mv moved file name accept file folder name (mv: move): move the file to the specified directory

You can use this command to change the directory when you delete a file downloaded through yum on the ECS instance that is not in the desired directory.

① New name of the renamed music video file: Rename

This is an implication of music videos.

6. compression and decompression

① Compression: the file name (suffixed with .tar.gz) after the tar-zcvf is compressed, for example, tar-zcvf file2.tar.gz file1.txt

② Decompress: the name of the tar-xvf file to be decompressed [-C Directory], for example, tar-xvf file2.tar.gz-C file1

You can use the local windows system to search for the information you want online and transmit it to the linux ECs instance in the form of a compressed package. Then, use this command to decompress the package.

7. Search

Grep content file name to be searched-color (-color highlighted): grep 5-5 open file1.txt-color: Find the content in file1 and related information

This can be used to check whether the target process is enabled or whether the software is uninstalled completely.

Iii. User Permissions

1. pwd

(Print Working Directory): view the current location

① Ctrl c Exit the command being executed

2. User and user group CRUD

① Useradd Username: Add User

② Userdel User name: delete a user

③ Passwd User name: Add a password to the user name

④ Groups User name: view the user group

⑤ Groupadd user group name: New User Group Name

⑥ Usermod-g New User group username (-g: group): Specifies the user's main user group. Note that g is in lowercase.

7. usermod-aG user name new user group name (-a: append): add an additional user group for the specified user. You can add multiple additional users to the user by using this method.

⑧ Usermod-G New User group username (-G: group): Specifies the unique additional user group of the user. Note that G is in uppercase.

Differentiation:-g,-G

-G user group: Specifies the user group to which the user belongs.

-G user group, which specifies the additional group to which the user belongs.

3. User Permissions

① R (view, 4), w (write, 2), x (execute, 1). For example, 7 indicates that rwx operations can be performed. wx operations must have the r Foundation,

In this way, you can use numbers to determine permissions.

4. user operations

① Su user Name (su: switch user): switch user

② Chown username file name (chown: change owner): change the owner of the file

③ Chmod permission file name (chmod: change mode): change the File Permission

+ Add permissions.-Remove permissions.

4. Common commands for JDK, Tomcat, mysql, and Firewall

1. JDK

① View the local JDK Configuration

Java-version

Javac-version

Related information is displayed, indicating that the configuration is successful.

2. Tomcat

① Check whether Tomcat is enabled

Check Java-related processes to determine: ps-ef | grep java

Kill process: kill-9 process no.

② Enable and disable Tomcat

Go to the bin directory of Tomcat,

Enable:./startup. sh

Close:./shutdown. sh

3. mysql

① Log on to mysql: mysql-uroot-p

Enter the password.

② Enabling, disabling, status, and starting mysql

Start mysqld: systemctl start mysqld. service

Stop mysqld: systemctl stop mysqld. service

Restart mysqld: systemctl restart mysqld. service

Set boot start: systemctl enable mysqld. service

View the MySQL Server status: systemctl status mysqld. service

③ Uninstall mysql

Uninstall:

First: yum remove mysql-community-server mysql-community-libs mysql-community-common

It is basically clean. Check the remaining mysql-related packages: rpm-qa | grep-I mysql

Again: yum remove-y mysql57-community-release-el7-11.noarch (version information depends on the Information queried by the previous command)

4. Firewall

① Enable the firewall command

Systemctl start firewalld. service

② Disable firewall commands

Systemctl stop firewalld. service

③ Automatic start upon startup

Systemctl enable firewalld. service

④ Disable automatic start upon startup (ECS default)

Systemctl disable firewalld. service

⑤ View the Firewall Status

Systemctl status firewalld (details: Information about firewall settings, etc.) or firewall-cmd-state (concise: not running or running)

V. Summary

1. For more information about linux commands, see Chinese documents.

2. The ECS is still good in linux. It was very slow to load a page with a large amount of information. For those who use web files externally on the GUI in windows, it does not have any purpose and occupies server resources. In addition, we can also use a lot of graphic interface tools such as winSCP to help us build and deploy servers in linux.

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.