Common linux commands

Source: Internet
Author: User
Tags uppercase character
Common linux commands-general Linux technology-Linux technology and application information. For more information, see the following section. Tr [-ds] SET1
Parameter description:
-D: Delete the SET1 string.
-S: replace repeated characters!

Example:
[Root @ test/root] # last | tr' [a-z] ''[A-Z] '<= replace lowercase with uppercase
[Root @ test/root] # cat/etc/passwd | tr-d: <==! : This symbol is missing in/etc/passwd!
[Root @ test/root] # cat/home/test/dostxt | tr-d' \ R'> dostxt-noM <= mark the suffix of the DOS file ^ M remove!

Note:
In fact, this command can also be written in "regular notation! Because it is also replaced by regular notation! In the preceding example, you can use [] to set a string of characters! It is also often used to replace the weird symbol in the file! For example, in the third example above, you can remove the ^ M line symbol left behind by the DOS file! This is quite useful! I believe this is the most troublesome thing to handle in Linux and Windows systems! That is, under DOS, the ^ M line break symbol will be automatically added at the end of each line! At this time, we can use this tr to remove ^ M! ^ M can be replaced by \ r

Grep
 
Syntax:
[Root @ test/root] # grep [-acinv] 'search for the string' filename
Parameter description:
-A: searches binary files for data using text files.
-C: calculates the number of times the 'search string' is found.
-I: Case sensitivity is ignored, so the case sensitivity is the same.
-N: returns the row number by the way.
-V: reverse selection, that is, the line without the 'search string' content is displayed!

Example:
[Root @ test/root] # grep 'root'/var/log/secure
Show the line with root in the/var/log/secure file.
[Root @ test/root] # grep-v 'root'/var/log/secure
If this row does not have root, the data will be displayed on the screen!
[Root @ test/root] # last | grep root
If this row has root, the data will be displayed on the screen!
[Root @ test/root] # grep [A-Z] ANPATH/etc/man. config
In the/etc/man. config file, all include:
[Any uppercase character] The line following ANPATH is displayed!
For example, AANPATH, BANPATH... ZANPATH, etc!

Note:
Grep is a common command. The most important function is to compare string data. It must be noted that "when grep searches for a string in a file, the data is retrieved in the unit of "whole row! 』 That is to say, if there are 10 rows in a file, two of which have the strings you are searching for, the two rows will be displayed on the screen, and the others will be discarded! In addition to searching archives, grep is often applied to input/output data processing. For example, a common pipeline command (pipe) can often be traced to it! From the above example, we can find that the first two examples are the content of the file, and whether the result shown by-v is "opposite !』, The third example is the pipe function for data processing!

Example 1: Find the file containing the know character and list the row number:
[Root @ test/root] # grep-n 'know' regexp.txt
3: * I don't know how to do this *
Grep compares the know string with a row. Note that the case sensitivity is different!
When the row does not contain the know string, grep will discard the row and not display it. However, to the third row, know appears, so the third line will be displayed!

Example 2: find out that the file contains the * character and list the row number:
[Root @ test/root] # grep-n' \ * 'regexp.txt
3: * I don't know how to do this *

Please pay special attention to the fact that there are quite a few "special characters" in the regular notation, and when you want to cancel the attributes of these special characters, the existence of the Backslash "\" is particularly important! In this example, you may find that the same result can be obtained using grep-n '*' regexp.txt. However, good habits need to be developed. Here, remove the attribute of * this special character in more orthodox regular notation, which will certainly benefit you a lot in the future!

Example 3: I want to list all knows, regardless of Case sensitivity, and list the row numbers:
[Root @ test/root] # grep-ni 'know' regexp.txt
3: * I don't know how to do this *
4: # I don't Know how to do this $
5: ^ I don't KNOW how to do this @
If the case sensitivity difference is ignored, add the-I parameter! -N is used to list the row numbers!

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.