Linux Section Common Command Learning (ii)

Source: Internet
Author: User
Tags character classes stdin disk usage

The 1.WC:WC command is a statistical tool used primarily to display the number of rows, words, and bytes that a file contains. The WC command is the abbreviation for Word count.

Command format: WC [option parameter] [file]

Option parameters:

-C Statistics byte number

-L count rows

-M count characters, this flag cannot be used with the-C flag

-W count words, a word is defined as a string separated by a blank, a jump, or a newline character

-L PRINT the longest line length

2.grep:grep is a powerful command to find matching text in a file, to accept regular expressions and wildcards, and to generate output in a variety of formats with multiple grep command options. grep works in such a way that it searches for a string template in one or more files. If the template includes spaces, it must be referenced, and all strings after the template are treated as filenames. The results of the search are sent to standard output without affecting the contents of the original file. grep can be used for Shell scripting, because grep describes the status of the search by returning a status value, or 0 if the template search succeeds, or 1 if the search is unsuccessful, or 2 if the searched file does not exist. We can use these return values to do some automated text processing work.

Command format: grep [option parameter] pattern [file]

Option parameters:

-C calculates the number of ' search string ' (or pattern) found

-I ignores case differences, so case is considered the same

-N Output line number

-V Invert selection to print mismatched rows

-R Recursive Search

--color=auto will find the keyword part plus color display (add at the end of the command)

Regular expressions and grep commands

A regular expression is a notation notation that is used to recognize text patterns. To some extent, they are similar to shell wildcards that match file and pathname names, but they are larger in size. Many command-line tools and most programming languages support regular expressions to help solve text manipulation problems.

The regular expression metacharacters consist of the following characters:

^ $ . [ ] { } - ? * + ( ) | \

The 3.cut:cut command is a small tool that splits text by column, and it can specify delimiters that separate each column. If a row of data contains multiple fields (multiple columns), you now want to extract one or more of the columns, which is the cut command.

Command format: Cut [option parameter] [filename]

Option parameters:

-B split in bytes

-C is split in characters

-D Custom delimiter, tab by default

-F Custom Fields

--complement extracts entire lines of text, except those specified by the-C or-f option

The 4.paste:aste command functions just as opposed to cut. Instead of extracting text columns from a file, it adds one or more text columns to the file. It reads multiple files and then consolidates the fields in each file into a single text stream, which is entered into the standard output

Command parameters: Paste [option parameter] [filename]

Option parameters:

-S merges each file into rows instead of by line

-D Custom delimiter, tab by default

The 5.TR:TR command is often used to change characters. We can think of it as a character-based find and replace operation. A word changer is a process of converting a character from one letter to another. TR replaces, reduces, and/or removes characters from standard input and writes the results to standard output. TR can only pass stdin (standard input) and cannot accept input through command-line arguments. TR is an abbreviation for translate (conversion).

Command format:

TR [option parameter] SET1 SET2 maps input characters from stdin from SET1 to SET2 and writes their output to stdout (standard output). SET1 and SET2 are character classes or character sets. If the length of the two character sets is unequal, then SET2 repeats its last character until the length is the same as SET1. If the length of the SET2 is greater than SET1, then the part of the character that exceeds SET1 in SET2 is ignored.

Option parameters:

-D Deletes the contents of the matching SET1 and does not replace them

Example 1. Replace the uppercase letters in the input characters with a lowercase letter

  Echo ' This is shiyanlou! ' | Tr ' A-Z ' A-Z

Example 2. Delete the number in the input character

  Echo ' This 123 is s1hiy5anlou! ' | tr -d '0-9 '

6.sort: When dealing with a text file, the sorting is always avoided, because sorting (sort) can play a small role in text processing tasks. The sort command can help us sort the text files and stdin. Typically, it combines other commands to generate the required output.

Command format: Sort [option parameter] [file]

Option parameters:

-N is sorted based on the length of the string, and this option allows sorting by numeric values instead of alphabetic values

-K Specify sort key

-B By default, the entire row is sorted, starting with the first character in each line. This option causes the sort program to ignore spaces at the beginning of each line, starting with the first non-whitespace character

-m merges multiple input files only

-R is sorted in reverse order, and results are in descending, not ascending

-T custom delimiter, tab by default

The 7.uniq:uniq command is often used in conjunction with the sort command. Uniq accepts a sequence of data from a standard input or a single file name parameter, and removes any duplicate rows from the data list by default. Uniq can only be used for sequential data entry, so Uniq either uses a pipeline or takes an ordered file as input and is always used in combination with the sort command in this way. The Uniq command is a unique abbreviation.

Command format: uniq [option parameter] [file]

Option parameters:

-C precede each line with a prefix number that indicates the number of occurrences of the corresponding line item

-D output Duplicate rows only

-U only displays unique rows

-D Displays all duplicate rows

-F Comparison Skip top n columns

-I is not case-sensitive when comparing

-S Skip top n characters when comparing

-W does not control the content after the nth character of each line

The 8.join:join command, similar to paste, adds a column to the file, but it uses a unique method to do it. A join operation is usually associated with a relational database, and a desired result is obtained by combining data from multiple tables with common key domains in a relational database. This join command performs the same operation, combining data from multiple files that are based on shared critical domains. In layman's terms, it is the same row that is specified in the two files, that is, the corresponding row is stitched together in one row according to a column in the two file.

Command format: Join [option parameter] [file 1] [File 2]

Option parameters:

-j field equals -1 FIELD-2 field,-j Specify a field as the matching field

-1 field matches the Field field in File1

-2 field matches the Field field in File2

-T custom delimiter, tab by default

9.common: It is often helpful to compare the contents of a text file. This is especially important for system administrators and software developers. A system administrator might, for example, need to compare an existing configuration file with a previous version to diagnose a system error. Similarly, a programmer often needs to see the changes to the program. The Comm command compares the two files that have been sorted by line. The display results include 3 columns: The 1th column is the row found only in the first file, the 2nd column is the row found only in the second file, and the 3rd column is a common line of two files.

Note that the Comm command, like the join, Uniq command, can only be used for data that has already been sequenced

Command format: Comm [option parameter] file 1 file 2

-1 does not output file 1-specific lines

-2 does not output file 2-specific lines

-3 does not output two files in common rows

The function of the DF command in 10.df:linux is used to check the disk space usage of the Linux server's file system. You can use this command to get information about how much space the hard disk is taking up, and how much space is left. The DF command is the abbreviation for disk free.

Command format: DF [option parameter] [file]

Option parameters:

-A All File system list

-h easy to read mode display

-I display inode information

-T File system type

-t< file system type > show only disk information for selected file systems

-x< file System type > does not display disk information for the selected file system

The 11.du:linux du command also looks at the use of space, but unlike the DF command, the Linux du command is a view of the space used by the file and directory disks. The du command is the abbreviation for disk usage.

Command parameters: du [option parameter] [file]

Option parameters:

-a displays the size of individual files in the directory.

-B in bytes when the directory or file size is displayed.

-C Displays the sum of all directories or files in addition to the size of individual directories or files.

-K is output in kilobytes (1024bytes).

-M is output in megabytes.

-S displays totals only, listing the last plus total values only.

-h in K,m,g to improve readability of information

The 12.time:time command is often used to measure the run time of a command, including the actual time of use, the user state usage time (the process spent in user mode), the time of the kernel state (the process spent in Kernel mode). Actual time: The command line starts execution to the end of the run time. User state usage Time: The user CPU time spent by the command to complete, that is, the command executes the sum of time in the user state. Kernel state usage Time: The system CPU time that the command takes to complete, that is, the command executes the sum of time in the kernel mentality. Where user CPU time and system CPU time are the sum of CPU time, that is, the total amount of time the command consumes CPU execution. The actual time is greater than the CPU time, because Linux is a multitasking operating system, often when executing a command, the system also handles other tasks

Command format: Time command

Linux Section Common Command Learning (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.