Summary of Linux commands used in recent projects

Source: Internet
Author: User

Summary: Recently, many Linux commands have been used to deploy and release projects in the production environment. These commands are summarized and recorded.

Linux Command summary:

First, make several statements:

(1). These commands are run on Redhat Linux and may not work on ibm aix;

(2). I will not introduce all the commands, and I will not introduce all the parameters for each command. I will only introduce what I use and is commonly used;

(3). the introduction is not sequential. I just want to review and summarize the commands used in the recent period;

(4) I used the root user to log on to the Linux system and created a pantp directory under the root directory.Black and white textAll operations are performed in this directory;

(5). (1) and (2) under the command indicate several common forms of the command;

 

. Ls--- Display files in the current directory

There are two common types:

(1). ls

Displays the pantp files in the current directory.

(2). ls-alt

Displays the detailed list of all pantp files (including hidden files starting with.) in the current directory, sorted by Time

.Hostname

(1) hostname

View computer name

(2) hostname-I

View the IP address of a computer

.Whoami

View Current Login User

.CP

Copy a file or directory

(1) copy an object

(2) copy the Directory

.SCP

Remote copying of files or directories (copying files or directories from one host to another) I have installed a Linux System in the virtual machine. I can't do this, just write the syntax, here, the copy from the local machine to the remote host is listed, and the other copy from the remote host to the local machine is not listed;

(1) copy an object

Switch to the directory where the file to be copied on the local machine is located (you can also write the absolute path or the relative path as needed)

SCP local file name: username for remote host login @ Remote Host IP Address: directory of the remote host

Here is an actual example:

(2) copy the Directory

Switch to the upper layer of the directory to be copied on the local machine (you can also write the absolute path or the relative path as needed)

SCP-r local directory name: username for remote host login @ Remote Host IP Address: remote host directory

.MV

Move files or directories, similar to cutting in windows;

(1) Move a file

Move the old.txt file to the dir1 directory

(2) Move the Directory

Move the directory dir3 to the directory dir1

(3) rename a file

Name old.txt new.txt

. Vi

Command mode, edit mode, and baseline Mode

Command mode:

Press ESC to switch to the command line mode, which is commonly used to delete

X deletes the character of the current cursor

Dd deletes the current row where the cursor is located.

Edit mode:

Press a, I, and O to enter the editing mode.

A. the cursor moves one position backward and inserts it after the current cursor.

I insert before the current cursor. The character where the current cursor is located will move behind

O Insert after changing a row

Follow these steps to insert the pantp characters in the preceding three methods:

The procedure is as follows:

1. open the file VI new.txt.

2. Place the cursor on the second character of the first line, press the letter A, and then enter pantp

3. Press ESC to switch to the Command Line Mode

4. Place the cursor at the second character in the second line, press the letter I, and enter pantp

5. Press ESC to switch to the command line mode.

6. Place the cursor on the second character in the third line, press the letter O, and then enter pantp

7. Press ESC to switch to the Command Line Mode

8. Input: WQ to save and exit

The content of the original file is as follows:

After editing, the file content is as follows:

Exit and save

(1) switch to the Command Line Mode

(2) Q: Do not save the disk and exit vi

: WQ: Save and exit vi

: Q! Force exit VI if no disk is saved

. More

The split-screen display file is valid only when the file size exceeds a certain length. After the length is exceeded, the percentage information is displayed. Otherwise, the effect of this command is similar to that of cat;

More file name

. Cat

Displays all the content of a file and all the content of the file at a time;

Cat file name

. Tail

Display the latest File Content

(1). Tail-F file name

Dynamically displays the increasing content of a file;

(2). Tail-1000f file name

Dynamically displays the content of the last 1000 lines of the file growth;

. History

(1). History

Show all History commands

(2). History 2

Display the last two Commands

. Chmod

Change the file mode X (execution), w (write), R (read)

The red part contains a total of 10 characters,

The first character indicates whether the file is a directory, D indicates a directory, and-indicates a file.

The second, third, and fourth characters indicate the root user's read, write, and execute permissions of the current file;

The fifth, sixth, and seventh characters indicate the root user's permission to read, write, and execute the current file group;

The 80 or 90 characters indicate the read, write, and execute permissions of users in other groups of the current file;

(1). chmod g + X file name

Add W permissions to the group to which the current file belongs to sed.txt;

 

(2). chmod 777 file name

Add W permissions to the group to which the current file belongs to sed.txt. CP. This type is represented by binary. If this permission is granted, 1 is written, 0 is written, and the total number is calculated;

Before change:

110 100 100 -----> 6 4 4

Change:

110 110 100 -----> 6 6 4

. Chown

Modify the user and group of the table file or directory. (Linux installed on my VM has only one root user and one root group. First, create a test group, and create a test user under the group, and the password is also test; operations for new users and groups are not described here, and there are very few such operations as a developer)

(1) chown username file name/directory

Change the owner of a file or directory

Change the user of directory dir1 from root to test.

(2) Change dir1 group from root to test

. Crontab

Crontab is used for users to execute at a fixed time or interval.ProgramUse;

For the following crontab command demonstration, I create an execution script in the pantp directory, crontab. Sh

(1). Create a scheduled task

I will execute the crontab.shscript every other minute, and output the file to the log.txt under the pantpvideo.

To make this effect obvious, I made a change to the crontab. Sh file. The modified file is:

First, we will introduce the format of the Process Table in crontab.

The time table format is as follows:
F1 F2 F3 F4 F5 Program

F1 indicates minute (0-59), F2 indicates hour (0-23), F3 indicates the Day (1-31) of a month ), f4 indicates the month (1-12), F5 indicates the day of the week (0-6 0 indicates Sunday ). Program indicates the program to be executed.
When F1 is *, the program is executed every minute. When F2 is *, the program is executed every hour, and so on.
When F1 is a-B, it indicates that execution is performed from the minute a to the minute B. When F2 is a-B, it indicates that execution is performed from the hour a to the hour B, and so on
When F1 is */N, it indicates execution is performed every n minutes. If F2 is */N, it indicates execution is performed every n hours, and so on.
When F1 is a, B, c ,... a, B, C ,... execute in minutes. F2 is a, B, c ,... a, B, c... execute in hours, and so on;

Enter crontab-E and enter the following parts. After the input is complete, press: WQ to exit;

(2). View custom tasks

 

You can view the running result in mongolog.txt:

(3) Delete a custom task

-R: Delete the crontab file of the current user.

This command is used with caution. This will delete all the custom tasks of the current user. We can directly enter crontab-E and delete unnecessary tasks;

. Sed

Use scripts to process text files

Replace ABC in sed.txtand sed.txt. CP with pantp.

Before executing the SED command:

(1) Method 1: sed-E's/ABC/pantp/'a.txt

-E indicates that the command is executed as a command line; parameter S indicates that the replacement operation is executed and the execution result is displayed;

Note::In this case, only the execution result is displayed, but the file has not changed.;

(2) Case 2: sed-I's/ABC/pantp/'a.txt

Parameter-I indicates that the file is directly modified without output,The file itself has changed;

. SSH

(1) log on to a machine. The current user is logged on by default.

(2) Use a specified user to log on to a machine:

. Ps

(1). PS-ef

Through the above command, I usually check whether a process exists. Sometimes I need to kill the process according to the process. In this case, I use the kill-3 process number in combination with the kill command, use this command to generate a core file.

(2). PS-Aux

The aux options will also be used together, but I will not summarize them here if they are not commonly used.

. Rm

Delete a file or directory;

Rm-RF file name or directory name

. Tar

(1) package directory A as a.tar

Tar-CVF a.tar

(2) decompress the tar package and decompress the.tar package.

Tar-xvf a.tar

. Jar

(1) package directory A into A. Jar

Jar-cvf a. jar

(2) decompress the package and extract a. Jar

Jar-xvf A. Jar

(3) view the file list in the jar package

Jar-tvf A. Jar

. Grep

Only two common options are described. The C statistic I ignores the case sensitivity.

Queries the number of characters in a file, and counts the number of lines that appear,If the characters to be searched appear more than once in a row, only statistics are collected once;

Grep-C character file name

. Find

Commonly used:

(1) view files and directories under a directory

Find System

(2) matching the required file by file name

Find path-name matching options

. WC

-L number of output lines of the current file

-C: number of bytes of the current file output

-W: number of words in the current file output

(1) WC file name

(2) Use with other commands, such as CAT

. Clear

Clear the screen;

. Pwd

View the current directory;

. Su

. Switch to the specified user

Su-tyjk

. Switch to the root user

Su

. Logout/exit

Exit the current session box;

ShutdownThis command is generally not used in actual production environments to verify the problem;

Shutdown: shutdown now

Restart: shutdown-R now

Reboot

 

Add 2012/09/11

Top

The top command is the resource manager in the Linux system. It can display the current CPU, memory usage, and remaining amount.

 

Uname

Uname-A: view the Linux System Version

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.