Some linux scripts/management commands frequently used in pen/Interview

Source: Internet
Author: User
Awk # the processing of fields is sed, and grep cannot be implemented. Awk-F, NR1, NR2 {print $1 $2} file, print the first row to the second row, with & lsquo;, & rsquo; as the separator, the first row, the value of the two fields. Print can be changed to printf, but the latter does not output line breaks. NR:

Awk # the processing of fields is sed, and grep cannot be implemented.

Awk-F, NR = 1, NR = 2 {print $1 $2} file, print the first row to the second row, use ',' as the separator, first in each row, the value of the two fields.

Print can be changed to printf, but the latter does not output line breaks. NR: number of records read, NF: number of fields in the current record.

Awk/main/file or awk/sun/{print} filename # displays the lines in the file that contain main.

Sed # Replace s, delete d, insert I (a), modify c, truncate Display: sed-n 2,6 p file

# Echo "a B c a" | sed s/a/d/g. check whether there is any g difference.

# Sed-n 2, 3 p file: only display Row 2 and 3. remove-n and use sed to display each row from the source file to the screen by default. -N is used to overwrite this operation.

# Sed/main/d file # Delete the row containing main from the file. Sed 1, 3, d file, delete the first three rows.

# Sed 1i shit file, sed 1a shit file. The former is inserted in row I, and the latter is inserted after row I.

Tr # delete empty rows: tr-s [""] <file, lowercase to uppercase: tr ["a-z"] ["A-Z"] <file, delete the character 'A': tr-d ["a"] <file

Grep

Sort # sort-t: + 1-2 B (-r inverted output) (-u output unique rows),-t: represents: as the separator, + 1,-2: specify the field as the key, starting from 0.

Find

# Find path-name filename;

# Find path-type x;

-Type x: search for objects of the x type. x is one of the following characters:

Block B device files

C character device file

D directory file

P named pipe (FIFO)

F common file

L symbolic links)

S socket file

-Xtype x and-type are basically the same, but only the symbolic link file is searched.

# Find./code-type f-exec ls-il {};

# The exec option is followed by the command or script to be executed, followed by a pair of {}, a space and a semicolon.

# When the "-exec" option of the "find" command is used to process matched files, the "find" command passes all matching files to exec for execution. However, some systems have limits on the length of commands that can be passed to exec, so that an overflow error will occur after the find command runs for several minutes. The error message is usually "the parameter column is too long" or "parameter column overflow ". This is the use of the xargs command, especially used with the find command.

The find command passes the matching file to the xargs command, while the xargs command only obtains part of the file, not all, at a time, unlike the-exec option. In this way, it can first process the first part of the obtained files, then the next batch, and continue like this.

# Find./code-type f-print | xargs file

Wc # wc-lcw filename, l: number of statistical lines, c: number of statistical bytes, w: number of statistical words

Uniq # Operations on adjacent rows;-d only displays duplicate rows;-u only displays non-duplicate rows; because it can only process adjacent rows, it is generally used with sort.

Cut # extract data from a text file or text stream.

Cut-f 1-2-d: filename # number starting from 1

-D: used as the separator. the default delimiter is tab.

-B,-c,-f: byte, character, Field filed.

1-2, indicating the range. n: only N items; N-: from N to the end of the row; N-M: N to M (including M);-M: from item 1 to item M;-: all items;

Cat/tac # the order of cat and tac display is the opposite.

Tee # cmd1 | tee file1. .. N | cmd2. the output of Command 1 is sent to tee. the output of tee is sent to file1. .. N and serves as the input of Command 2.

Tail/head # head-3 file and tail-3 file. the first three rows and the last three rows are displayed.

Eval # eval cmd [; cmd]: run the command as a parameter.

Expr # expr args, for example, a = 'expr $ B + 1'

Let # let express-list, for example, let "a = B + c"

Xargs # output the input to the command after xargs as the parameter of that command.

Regular expression

Colrm # removes the selected columns from the file. Colrm [start row number <结束行数编号> ]. Colrm 2 5 <filename

Rev # returns the reverse string order.

[Sword @ localhost ~] $ Temp =/home/sword

[Sword @ localhost ~] $ Basename $ temp

Sword

[Sword @ localhost ~] $ Dirname $ temp

/Home

[Sword @ localhost ~] $ Basename/home/sword. c. c

Sword

Ls

Related Article

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.