Linux Command [Article 1], linux Article 1

Source: Internet
Author: User

Linux Command [Article 1], linux Article 1

1. Create a directory/data

Memory: the abbreviation of make directorys is mkdir.

Command:

Practice process:

Summary:

Cd is followed by a relative or absolute path, indicating to enter the directory. If nothing is followed, it will enter the home directory of the current user.

Relative Path concept: starts from the current directory instead of/, for example, data/, mnt/oldboy.

Absolute path: the directory from/is called an absolute path, for example,/data/,/mnt/oldboy.

Cd command memory method: change directory.

Mkdir [-mp] [directory name] creating a directory

-M: this parameter is used to specify the permission to create a directory, but it is rarely used and will be processed using chmod.

For example, mkdir-m 777/tmp/test creates a directory with the permission of 777.

-P: this parameter is used to recursively create directories, a common parameter of mkdir.

2. Create an oldboy.txt file under/Data

Command:

Practice process:

Summary:

Touch ". Touch [file name] is a "touch" file. If the file does not exist, create a new file. If yes, change the access time of the file, such as atime.

Path separation differences:

Windows Directory separation D: \ PIC \ oldboy.

Linux directory separation/data /.

3rd, the content added to oldboy.txt is "I am studying linux ".

Method 1: General editing Method

Run vi oldboy.txt to enter the vi Editor (default command mode), click a or I to enter the editing mode, and enter the content I am studying linux, press the esc key on the keyboard to exit the editing mode (to the command mode), and finally press: wq to save and exit. Wq explains write quit.

Description:

Vi is a common editor in linux like Notepad. If you want more functions, you can use vim to replace vi. vi/vim has many internal command technical points, such as I is insert, the esc key switches to the command mode. In command mode, you can press the colon ":" To access command parameters, for example, wq and w are write, q is quit.

Vi Editor, equivalent to notepad, has the editing function, but is weak.

Vim copies the editor, which is equivalent to emeditor, editplus, and notepad ++.

Shortcut Key: TAB command and path completion.

Method 2: insert Common commands for single-line or multi-line text. The content is stored at the end of the file.

Practice process:

Description:

Echo is a common command used to print output content. It can be used with "> or>" to overwrite and Append content to a file. ">" Indicates redirection. All the previous data in the file is cleared. ">" append the content only at the end of the file, there is also a complicated and uncommon command like printf.

Special Character commands:

> Redirection clears all previous data in the file and adds

> Append redirection,

Method 3: scripts are commonly used. Multiple lines are appended and the content is placed at the end of the file.

Method 2 and method 3 are commonly used in command lines or scripts.

Method 2 is used for single-line text. Method 3 can be a multi-line file. If there are special characters in the text, such as $, you need to use \ escape.

Method 4:

Press ctrl + d or ctrl + c to finish editing twice. This method is a special editing method.

Summary:

Echo is a common command for Printing Output content. It can be used with ">" or ">" to overwrite or Append content to a file. Echo $ PATH prints the value of PATH.

Redirection: "data is transferred to other places ". After executing a command, the data that should have appeared on the screen is transmitted to other places. When executing the command, the command may read data through the file. After processing, then output the data to the screen.

> Or 1> output redirection: If you input the previous output to the following file, the original content of the file will be deleted.

>>> Or 1> append redirection: append the previously output object to the following file without deleting the original content of the file.

<Or <0-input redirection: Enter redirection is used to change the input of the command, followed by the specified input content, followed by the file name

<Or <0 append input redirection: Followed by a string, used to indicate "input end". You can also press ctrl + d to end the input.

2> error redirection: Enter the error information in the file behind the file to delete the original content of the file.

2> error append redirection: append the error information to the following file, without deleting the original content of the file.

Standard input (stdin): the code is 0. The data flow direction is from right to left using <or <.

Standard normal output (stdout): the code is 1, use> or>, and the data flow is from left to right.

Standard Error output (stderr): Code 2, Use 2> or 2>.

The direction of the arrow is the direction of the data flow.

Special Syntax:

4、copy the oldboy.txt file to/tmp

Command:

Summary:

Cp [-aifpru] [source file] [target file]

-A: equivalent to-pdr

-D: if the source file is a link file, copy the link file attribute instead of the file itself.

-F: force. If the target file already exists and cannot be enabled, remove the file and try again.

-I: If the target file already exists, you will be asked before overwriting.

-P: copy the file together with its attributes, instead of using the default attributes.

-R: recursion, used to copy directories.

-U: if the target file exists, the target file is copied only when it is earlier than the source file.

Tip: if there are multiple source files, the destination file is at the end and is a directory.

Important parameter apr of cp.

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.