Linux Basic Instructions

Source: Internet
Author: User
Tags diff diff patch string find

1, Linux commonly used to find commands

Under Linux you will often use the two find command grep and find. Where the grep command is commonly used as a file containing a string, and find is often used to find files that match the file name.

grep command

In fact, the grep command is a very powerful Linux search tool, here is simple to do a simple string matching find the relevant introduction, Daniel do not spray ah, easy to read to their own later.

grep to find the string find the path to find the list of files (separated by spaces) parameter//grep find the format of the string

Common parameters:-R Recursive Lookup

-N Displays matching file line numbers

Eg:grep "Request_irq". *-rn//Find the file containing the string Request_irq in all the files in the current directory, and//give the number of lines where the file string is located.

Find command

Find Find directory lookup criteria [ operation ]

The Find command starts a recursive query under find criteria under Find a directory, and according to the action instructions, the operation is optional and is added as needed.

Note: The find condition can be a compound condition that is concatenated with the logical operator And,or,not

Common parameters:-name "string"//file name matching

& nbsp;         -type x        //The file type found is X (b-Block device file, C-Character device files, s->socket links                             //file, p pipeline file, D catalog file)

eg:fi Nd-name "*demo*"-a-user "BJWL"//In all Files of "BJWL" This user find                                                    //a file with the word "demo", where-a is and, similarly or                                The               //option is rendered by the-O

Eg:find! -name use of the "*demo*"//not option

eg:find.-name "*so.*"//Find the file name in the current directory contains "so." The words of the document, wherein the "." Represents when                   //Beforethe catalogue can be omitted, the personal suggestion write better, feel with clear point.

Eg:find-name "*so.*"-exec shell command {parameters of Shell command} \;

Execute the "shell command" command parameter for the found file in the {} command with "\;" End.

Pipeline Command |

You can actually execute multiple commands.

Eg:ls RPM | grep bind//Find a package whose name is bind

2. Common VI Editor commands

In the command mode of VI

NDD//delete the row and the following n rows of the cursor

NYY//Copy cursor row and the following n line to the Clipboard

P//Paste

Number//Show line numbers

NG//Jump to Nth row

/string (? string) to find string string forward (after)

%S/STRING1/STRING2//Replace the string2 in the entire file with string1

3. Compression and Decompression commands

Tar parameter options destination file (. tar.gz or. tar.bz2) [directory] [-c]

Parameter description:

C Creating a compressed file

X extracting (extracting) compressed files

Z Compress in gzip mode (solution)

J Compress in bzip2 mode (solution)

V in the display process

f means file, followed by a filename

The above combination parameter is the parameter option, only when the file is compressed to use the [directory] to indicate the directory to be compressed, at the time of decompression is not, can be decompressed with the-C path to specify which directory to extract, can have V, also can not V

Eg:tar CZF demo.tar.bz2 Demo//Compression

Eg:tar XZF demo.tar.bz2//Decompression

4. Patch Command

The patch file is the difference between "modified file" and "Original file".

Since the Linux kernel package can be directly from the online swing, if you want to publish your kernel files only need to modify the custom kernel and standard kernel files to generate a patch file (*.diff), this file is very small, easy to publish use, Customers only need to download the standard kernel and our diff patch and then patch it to use our custom kernel. So the patch file is very useful when used in the actual product.

patch file Generation :

Diff parameter source file directory after customizing the file directory > patch. diff

Parameter description:

-U//represents some of the same rows in the output context of the comparison results, which facilitates manual positioning.

-r//Represents a recursive comparison of files under subdirectories.

-N//The nonexistent file is treated as an empty file.

-w//Ignore whitespace comparison

-b//Ignore blank rows comparison

Note: The above parameters personally feel that no one is redundant, all strongly recommended, when generating the patch file can be added directly on all parameters using-URNWB

EG:DIFF-URNWB linux-2.6.22.6 LINUX-2.6.22.6_OK > Linux-2.6.22.6_ok.diff

Patch Command

PATCH-PN < patch files needed for patching (*.diff)

Parameter description:

-P//First the patch file indicates the file path to be modified,-pn means ignoring the nth slash in the patch file path before the directory,//To find the source file

Eg:patch-p1. /Linux-2.6.22.6_ok.diff

The above command indicates that the patch is in the current directory at the top level of the directory, and then ignore the patch file in the directory before the first slash of the directory, to find the source file. Is the patch last hit the location is: need to patch the directory with the patch file indicated by the source file lookup path combination of a directory, when let first have to undergo-PN modification.

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.