LINUX2:VI, LS, CD, pwd, MkDir, RM, MV, CP, CAT, tail

Source: Internet
Author: User
Tags save file

Objective

Starting from this article, each article will write 10 Linux commands, the personal writing idea is:

1, the Common Linux command, those rare, not commonly used will not write

2, from the actual consideration, only lists the common usage and parameter options for each command, and is interested in understanding further usage can go online to inquire

Vi

A text editor in a Linux environment

VI basically can be divided into three operating states, namely, Command mode, insert mode, the bottom line command mode, the function of the function is differentiated as follows:

1. Command mode

Controls the movement of the screen cursor, the deletion of characters or cursors, the movement of a section and the insertion mode

2. Insert mode

Only in the Insert mode, you can do text data input, press ESC and so on to return to the command mode

3. Bottom line Command mode

Stores the file or leaves the editor, or sets the editing environment, such as searching for a string, listing line numbers, etc.

Note that after entering VI is in command mode, to switch to insert mode in order to enter text. In command mode, press "I", "a" or "O" to switch to insert mode. In insert mode, there are some commands:

I: INSERT, insert the text you entered from where the cursor is currently located

A: Add, start typing text from the next word where the cursor is currently located

o: Insert a new line and enter text from the beginning of the beginning

In the Insert mode, you can only keep typing, if you find the wrong word, you must first press ESC to switch back to command mode, then move the cursor backward, and finally delete the wrong characters. Remove some commands:

X: One character after each Click to delete the position of the cursor

#x: For example, 6x means 6 characters after the location of the delete cursor

DD: Delete cursor in the row

This is the command mode, in command mode, press ":", "/", "?" Can enter the bottom command mode, there are some commands in the bottom command mode:

: Set Nu: Line numbers are listed before each line of the article

/keyword: Search backwards for keywords, if not desired, press N to continue searching backwards

Keyword: Forward search keyword, if not desired, press N to continue searching forward

: w: Save File

Ls

To print a list of the current directory, you can specify a different directory

-A: Lists all files in the directory, including "." Hidden files at the beginning

-L: Lists file permissions, owner, size, and more, in addition to file names

-R: Reverse order

-T: Sorting by file modification time

-G: Similar to-l, but does not list owner

-H: Listed in easy-to-understand file format (e.g. 1K, 234M, 2G)

For example:

Ls-l t*: Lists file information for all filenames that begin with "T"

Cd

Switch Files directory to dirname

For example:

CD/: Enter the system root directory

CD AA/BB/CC: Jump to the specified directory, note here "AA" before "/", refers to jump from the current directory to the specified directory

CD ~: Enter system home Directory

Cd.. : Jump to the previous level

Pwd

View the full path to the current working directory

Mkdir

The directory used to create the specified name, requiring the user who created the directory to have write permissions in the current directory, and the specified directory name cannot be an existing directory in the current directory

-M: Set permissions when creating a directory

-P: If some paths do not exist in the path of creating a directory, you can set up multiple directories at once

For example:

mkdir test1: Create an empty directory Test1

Mkdir-p test1/test2: Create multiple directories recursively

MKDIR-M 777 Test: Grant 777 permissions to this directory when creating a directory Test3

Rm

Delete one or more files or directories in a directory that can delete a directory and all of its files and subdirectories. For linked files, just delete the link, the original file will remain unchanged

-F: Force delete without prompting

-r: Recursively delete directories and subdirectories listed in the parameters

-V: Show detailed steps

For example:

RM-RF *.log: Delete any. log files and do not ask the user

Mv

Can be used to move files or rename files, often used to back up files or directories

For example:

MV Log1.txt log.txt test3: Move Log1.txt, log2.txt to Test3 folder

MV Dir1 DIR2: If Dir2 does not exist, Dir1 is renamed to Dir2, and Dir2 is moved to Dir1 if DIR2 exists

MV *.. /: Move all Files under the current folder to the top level directory

MV Test3/*.txt TEST5: Move all. txt files under the test directory to the Test5 folder

Cp

Copy a file or directory

For example:

CP log.log TEST6: Copy the log.log into the TEST6 directory

Cat

There are three main features of cat:

1. Display the entire file at once

2. Create a file from the keyboard

3. Merge several files into one file

By the way, TAC this command, like cat, simply displays the contents of the file from the last line to the first line.

-E: Show "$" at the end of each line

-N: 1-based numbering for all lines of output

-S: Instead of a row of blank lines for two consecutive lines

-T: Show jump characters (tab) as "^i"

For example:

Cat-n log1.log log2.log: Enter the Log1.log into the Log2.log file after adding the line number, Log2.log must exist in the directory

Cat-n log1.log > Log.log: Enter the Log1.log with the line number into the Log.log file, Log.log does not exist in the directory

Tail

Used to display the content at the end of the specified file, and is processed as information input when no file is specified. Common View Log files

-F: Constantly read, cycle refresh, so you can see the latest file content

-Q: Do not display processing information

-V: Displays detailed processing information

Number of-c<;: Number of bytes displayed

-n< number of rows;: Number of rows displayed

For example:

Tail-n 5 Log1.log: Displays the contents of the last 5 rows of the Log1.log

Tail-f Log1.log: Cycle through the contents of Log1.log

LINUX2:VI, LS, CD, pwd, MkDir, RM, MV, CP, CAT, tail

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.