Linux System Command Advanced

Source: Internet
Author: User
Tags alphabetic character control characters printable characters uppercase character

1, the Replication/etc/skel directory is/home/tuser1, requires/home/tuser1 and its internal files belong to the group and other users do not have any access rights.

Cp-a/etc/group/home/tuser1chown-r O-rwx/home/tuser1

2. Edit the/etc/group file and add the group Hadoop.

The new method is known for the following two examples 1:echo "hadoop:x:2024:" >>/etc/group example 2:group Hadoop

The following method of creation, relatively common, specific to the individual operating habits

3. Manually edit the/etc/passwd file to add a new line, adding user Hadoop, whose basic group ID is the Hadoop group ID number; its home directory is/home/hadoop.

There are also two new methods available here:

Example 1:echo "Hadoop:x:2020:2026::/home/hadoop:/bin/bash" Example 2:useradd Hadoop

Explanation: The user created by default will be under the/home directory, the default/bin/bash/users are allowed to log on to the system, if you need to have the maximum Super Administrator privileges, you just need to change the ID number to 0:0.


4. Copy the/etc/skel directory as/home/hadoop, which requires that the genus Group and other users of the Hadoop directory be modified without any access rights.

[Email protected] ~]# cp-a/etc/skel/home/hadoop [[email protected] ~]# chmod go-y/home/hadoop[[email protected] Hado op]# su hadoopbash:/home/hadoop/.bashrc:permission deniedbash-4.2$

According to the above operation, Hadoop, there is no access to the home directory

5, modify the/home/hadoop directory and all the internal files of the owner of Hadoop, belong to Hadoop group.

Chown-r Hadoop.hadoop/home/hadoop | | Chown-r Hadoop:doop/home/hadoop

The above two modes of operation can be performed, most of the 5 series is the use of the former, the latter because there is no environment is also feasible, temporarily unknown, the next opportunity to test, and then fill up.

6. Display the lines in the/proc/meminfo file beginning with uppercase or lowercase s, in two ways;

Case 1[[email protected] hadoop]# grep "^[SS]"/proc/meminfo case 2[[email protected] hadoop]# cat/proc/meminfo |grep-i "^s"

Explanation: There is no need to use the pipe symbol here is also possible "|", in the work, we inevitably need to use the pipe, in the writing match can be as far as possible without the best pipeline, add a pipeline, means the need to increase the loss of resources. It depends on your personal habits and needs.


7. Display the default shell of the/etc/passwd file as a non-/sbin/nologin user;

[[email protected] hadoop]# grep "/bin/nologin"/etc/passwd

8. Display the user whose default shell is/bin/bash in/ETC/PASSW D file;

[[email protected] hadoop]# grep "/bin/bash"/etc/passwd

9. Find out one or two digits in the/etc/passwd file;

Grep-o "[0-9]\{1,2\}"/etc/passwd

10. Display the line beginning with at least one blank character in/boot/grub/grub.conf;

grep "^[[:space:]]"/boot/grub/grub.conf

11, the display/etc/rc.d/rc.sysinit file with the beginning of #, followed by at least one white space character, and then have at least one non-whitespace character line;

[[email protected] hadoop]# grep "^#[[:space:]]\+[^[:space:]]\+"/etc/rc.d/rc.sysinit

12, the Netstat-tan command execution results in the "LISTEN", followed by or with a blank character end of the line;

[Email protected] hadoop]# Netstat-lan | grep "listen[[:space:]]\+$" parameter description: A (All) display all options, default does not show LISTEN related-t (TCP) only show TCP-related options-U (UDP) only show UDP-related options-n deny display alias, Can show that all numbers are converted into numbers. -L only lists the service status in Listen (listening)-p displays the program name that establishes the relevant link-r display routing information, routing table-e displays extended information, such as UID, etc.-s per protocol to statistics-C every other fixed time, executes the netstat command.

13, add user bash, Testbash, basher, Nologin (this one user's shell is/sbin/nologin), and then find the current system on its user name and the default shell of the same user information;

[[email protected] hadoop]# useradd bash[[email protected] hadoop]# useradd testbash[[email protected] hadoop]# useradd BA Sher[[email protected] hadoop]# useradd nologin-s/sbin/nologin[[email protected] hadoop]# grep "^\ (\<[[:alpha:]]\+\ >\). *\1$ "/etc/passwd

Summarize:

The most used in this chapter is GREP's command example, mainly with the regular to match the requirements of the results, here are some advanced usage of grep, listed below.

Inspirational discourse: Rotten Wood, if the effort now, the back is the oasis, if not hard now, the back will be, the beginning of the nightmare.


Grep


One. Match characters

. matches any single character [] matches any character in the specified range [^] matches any character in the specified range [: Alpha:] alphabetic character [: Lower:] Lowercase alphabetic character [: Upper:] Uppercase character [:d Igit:] Number [: alnum:] alphanumeric character [: Space:] White space characters (prohibit printing), such as carriage returns, line breaks, vertical tabs, and page breaks [:p UNCT:] punctuation characters [: Cntrl:] control characters (prohibit printing) [:p rint:] printable characters typically use two brackets, which are used in the following example.


Two. Number of matches

* Match the previous word Fuzhin once. * Match any character of any length (note that greedy mode, such as grep "R.*t"/etc/passwd) x\{m,n\} specifies that the preceding character appears at least m times and at most n times.        X\{m,\} specifies that the preceding character appears at least m times x\{0,n\} specifies that the preceding character appears at most n Times x\{m\} exactly matches m times? Match its preceding character 0 or 1 times


Three. Anchor character

1.^   Anchor Header     grep   "^r. T "  /etc/passwd2.$   Anchor Line end     grep  " h$ "  /etc/ passwd3.^$  anchor Blank line   grep   "^$"   /etc/passwd4.\<  (\b)    anchor Word Header     grep   "\<r. T "  /etc/passwd5.\>  (\b)    anchor word     grep  " R. T\> "  /etc/passwd example (easy to confuse): Contains at least one blank character            grep   "[[: Space:]]\{1,\}"   /etc/passwd contains at least one non-whitespace character          grep   "[^[:space:]]\{1,\}" &NBSP;&NBSP;/ETC/PASSWD does not have a blank character                grep  -v  "[^[:space:]]\{1,\}"    /etc/passwd6.\ (\) group characters   grep   "\ (L.. e\). *\1r "Example:grep --color " l\ ([13]\): \1:.*:\1 "  /etc/inittab


Four. Options

-V: The result is reversed-I: Ignore letter-Case-O: Show only the matched string (the other contents of the line do not display)-e: Extended Regular expression supported-A: Displays the rows that match to the N-line-B: Displays the rows that match to the top N lines-C: Displays the rows that match to row Extended Regular Expression egrep-f: a collection of strings delimited by a newline fgrep-g: basic regular-P: called Perl regular-E: The following root regular mode, default no-F: Get the matching pattern from the file-I: Case-insensitive-w: matches entire word-X: Matches whole line-Z: one 0-byte data row, but not a blank line





This article is from the "thinking under the roof" blog, please be sure to keep this source http://wuyanxxk.blog.51cto.com/4130666/1843525

Linux System Command Advanced

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.