. NET Programmer Learning Linux (ii)

Source: Internet
Author: User

This point of knowledge: recursive command, WC command, document Editor VI simple use, text Common Operations Command, find query file command, grep matches the corresponding keywords in the text

Recursive command character

Recursion for the program ape is not the default, often used for cascading relationships, one layer to the last layer of a layer, in the Linux command, such as LS RM mv and so on can be recursive, only need to add-r in the back to the recursive operation

WC command to calculate the number of file lines, bytes

The WC command is used to print the number of lines of text, number of words, number of bytes, and so on.

[[email protected] etc]# WC krb5.conf-----> count the number of lines in the file byte number of words

The result is a 449 krb5.conf

[[email protected] etc]# wc-l krb5.conf------> Plus-L is the number of lines, plus-C is the number of bytes

You can use the WC to count the number of files in the directory.

[[email protected] etc]# ls | Wc–l-------> calculates the number of files in the current directory
216

-------------------------------Using WC statistics------------------------------------

[Email protected] ~]# Ls-r Directory2/directory3 | Less
Directory2/directory3:
De123
Er
ew
Ewfds
Qwes
Qyv
Tytr
[Email protected] ~]# Ls-r Directory2/directory3 | Wc-l
8

Using WC statistics, the current file directory is also counted.

Recursively replicating directories

[[email protected] ~]# cp-r directory2 cydirectory2----> Copy the Directory2 file into the Cydirectory2 (I always thought even Directory2 was included in it, It's just a file inside.)

Normal replication creates permissions based on the currently running user, and if you want to keep the permissions intact, you need to add –p, and the owner will not change.

Document Editor VI

VI N Many called the editor of God, to open a file and edit it, you only need to drive into the VI file1 you can go to the file for editing

VI has two states, the command state and the editing state, just enter the time is the command state.

From the command state into the editing state, I see the lower left into the insert is entered the editing state, and a a I I O s S can enter the editing state, but each command with its specific mode of operation, for me this beginner, remember one of them, and then slowly understand the rest It

When the edit state enters the command state, the ESC button is pressed to see that the lower-left insert disappears, then it enters the command-line state

There are several different ways to enter edit mode---------------------Select and command mode--------------------------------

A: Inserts a new character from the back of the cursor, and when inserted, the character that follows the insertion moves backwards with the new character.

A: Add a new character from the last point of the line where the cursor is located.

I: Inserts a new character from the front of the cursor, and when inserted, the character that follows the insertion moves backwards with the new character.

I: A new character is added before the first non-null character in the line where the cursor is located.

O: Add a blank line below the line where the cursor is located and enter the insert state.

O: Add a blank line above the line where the cursor is located and enter the insert state.

S: Deletes the character at which the cursor is located and enters the insertion state.

S: Deletes the line where the cursor is located and enters the insert state.

--------------------------------Delete Characters in command mode----------------------------------------------------

X: Delete the character of the current cursor

DD: Delete the current cursor positive line

----------------------------------restore--------------------------------------------at the command line

U: the equivalent of the normal window under the Ctrl +z Undo

Ctrl+r: equivalent to window ctry +y recovery

-------------------------------Replacement Word-----------------------------------------

R: Enter an alternate state, replace multiple characters until you press ESC to exit the replacement, and replace appears in the lower left

--------------------Save, Exit-------------------

: w----------> If it is an old file, save as current directory and press ENTER directly, and if Save as, add a new file name

There are all kinds of shortcuts.

: Q-----------> exit the current VI mode, if the change is not saved, you can use q! Force quit, do not save

: Wq---------> Save before exiting

--------------------------Search Text-------------------------

/: Enter the search mode, enter the characters that need to be searched, then the search succeeds will change color, click N to search the next, n is move up

?: Go to search mode, but go up

F: After clicking on the F and then pressing a character, move the cursor to the character entered by the nearest current cursor

Some commands that are manipulated in this article

Using the pipe command symbol | Can

more/less command

But if there is a lot of nested files inside a file, then if you run ls–r then the screen will constantly flashing, print out the information in the folder, we human must not see, so you can put its output into a container, this container for more or less, and more is not to go upside down, Can only be turned upside down, but less can be up or down, command: ls–r|less

If you did not place it in the container at the beginning, you can use CTRL + C to stop printing.

With Less-n, you can also output the number of rows

Tee Multi-Transfer

The dev file under the root directory is corresponding to the management of all hardware devices, such as mouse, printer, etc.

[email protected] ~]# Cat Install.log | Tee/dev/1p0---------> Using the Tee command, you can print the contents of the file and output the large printer device (assuming dev/1p0) for the printing device

PR formatted output

The PR command can handle the format of output produced by other commands

-< number of columns, divided into numbers

-W: The number of characters per line, the default is 72.

-L: The number of rows per page, default is 66.

-h < string;: using the specified string instead of the file name as the header

[email protected] ~]# Cat Install.log | Pr-2-H "AAAA" –l20-------> 2 column titled AAAA 20 lines per page

Head and tail output header/tail specified number of lines

Sometimes we only care about the head and tail of the text, then you can specify to print these headers and tails can use the command head or tail

[[email protected] ~]# tail-20 install.log----> Output Install.log file at the end of 20 lines

[[email protected] ~]# head-20 install.log----> Output install.log file header 20 lines

Save the content as another file,

[[email protected] ~]# head-20 install.log > NewFile----> Head 20 rows Save as NewFile file

[[email protected] ~]# tail-20 install.log >> newfile-----> Add tail 20 lines to the end of the NewFile file

Note that:> is redirected to the specified file, and if there is content in the file, the content inside will be overwritten,>> is added to the end of the file

Diff compare two different files

[Email protected] ~]# diff Install.log NewFile---> Comparison of these two files

------------------------------------the printed information--------------------------------------

1c1
< installing libgcc-4.4.7-16.el6.x86_64
---
> qqqqqqqqqqqqqqqqnstalling libgcc-4.4.7-16.el6.x86_64

--------------------------------------------------------------------------------------

1C1 indicates that the first line in the Install.log file has been modified with the first line of NewFile,

A, D, and C represent additions, deletions, and modifications, respectively

CMP-by-character comparison (not limited to text files)

The specific use of Baidu (I am lazy here do not test ...)

Find File

The composition of the Find command: How to search for the initial directory of the Find search (condition) [action performed]

Search Initial directory: The directory from which to start the search, if more than one directory can be separated by a space or use wildcards

-name with a name search, you can use wildcards for pattern manipulation, surrounded by double quotes

-iname ignoring case

-tpye Delete based on file type F: General file D: Directory file C: Character device file L: Symbolic link

-link< Quantity >: Search According to the number of file links

-size< number >KMG: According to the size of the file to filter, you need to write the unit

-user < Owner account name > Search according to the owner of the file.

These are commonly used in the search method, of course, there are many, you can search, with logical operators can produce more search conditions

Logic: If there are multiple conditions, use the \ (\) \) Escape character in the filter condition where

And and

-O stands for or

! Represents non-

To perform the operation:

–print output in the screen

-exec < command > \;: Execute < command, if you want to use the retrieved file name in the command, instead of the symbol "{}", the system will pass the retrieved file name to the command where "{}" is found. end fixed to \;

?    [[email protected] ~]# Find/-name "*.bak"-exec rm {} \; ---> Find the. bak suffix file and delete

[[email protected] ~]# Find/\ (-name "A *"-o-name "*a" \)-print---> contained or actions

grep looks for files that contain a keyword

grep < keywords > directory----> can be paired with regular

This week is mainly about the processing of some text, such as the use of VI, as well as some operations of the file.

. NET Programmer Learning Linux (ii)

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.