Linux basic Knowledge Five

Source: Internet
Author: User

1. Displays the default shell for root, fedora, or User1 users on the current system.

[Email protected] ~]# grep-e "^root\>|^fedora\>|^user1\>"/etc/passwd| Cut-d:-f1,7root:/bin/bashuser1:/sbin/nologinfedora:/bin/bash

2. Find the line with a set of parentheses followed by a word in the/etc/rc.d/init.d/functions file, such as: Hello ().

[[email protected] ~]# grep-e-O "[[: Alpha:]]+\ (\)"/etc/rc.d/init.d/functions str () checkpid () Readlink () Fgrep () Checkpids () Kill () loop () Fstab () mTAB () loop () mounts () run () pidof () daemon () Killproc () Pidfileofproc () Pidofproc () Status () Success () failure () passed () Warning () stage () success () failure () passed () Warning () Action () silent () strstr () Confirm () dev () file () True () False () Sysctl () random () point () crypto ()

3. Use the echo command to output an absolute path and use grep to remove its base name.

[Email protected]/]# echo '/etc/sysconfig/network-scripts/ifcfg-eth0 ' | Egrep-o ' [^/]+/?$ ' | Cut-d '/'-f1ifcfg-eth0

Extension: Take out its path name

[Email protected]/]# echo "/etc/sysconfig/network-scripts/ifcfg-eth0" |egrep-o "/.*/\b"/etc/sysconfig/ network-scripts/

4. Find the number between 1-255 in the ifconfig command result.

[Email protected] ~]# Ifconfig | Grep-eo "\<[1-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>\<[2][0-4][0-9]\>|\<[2][5][0-5]\ > "29203120312552552552556412516431255118383

5, Challenge: Write a mode, can match the reasonable IP address.

[Email protected] ~]# Ifconfig | Egrep-o "(\<[1-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5) \>) \. (\<[0-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>) \. (\<[0-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>). (\<[0-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>) " 192.168.31.20192.168.31.255255.255.255.0127.0.0.1255.0.0.0

6. Challenge: Write a pattern that can match all the mail to the address.

^[[:alnum:]]+[-._]? [[: Alnum:]] [Email protected] [[: Alnum:]]+ (\.+[[:alpha:]]+) +

7. Find the main root of the/var directory and all files or directories belonging to the group Mail.

[[email protected] ~]# find/var-user root-a-group mail-ls394494 4 drwxrwxr-x 2 root mail 4096 Sep 2 22:03/var/spool/mail393510 92-rw-------1 root mail 90186 Sep 2 20:46/var/spool/mail/root


8. Find files that are not owned by the master or group on the current system.

# Find/-nouser-a-nogroup-ls

Further: Find files or directories on the current system that are not owned by the master or group and have been accessed in the last 3 days.

# Find/-nouser-a-nogroup-a-atime-3-ls

9. Find files with Write permission for all users in/etc directory.

# Find/etc-perm-222-ls

10. Find all files that are larger than 1M in the/etc directory and are of the normal file type.

# find/etc-size +1ma-a-type F-ls

11, find the/etc/init.d/directory, all users have execute permissions, and other users have write permissions files.

# Find/etc/init.d-perm-113-ls

12. Look for files that do not belong to root, bin, or Hadoop in the/usr directory.

find/usr/-not \ (-user root-o-user bin-o-user hadoop \)-ls

13. Find at least one type of file in the/etc/directory where the user does not have write permission.

# Find/etc-not-perm-222-ls

14. Find files whose contents have been modified and not rooted or Hadoop for the last week in/etc directory.

# find/etc-mtime-7-a-not \ (-user root-o-user hadoop \)-ls



This article is from "Bo Zi in the Water" blog, declined to reprint!

Linux basic Knowledge Five

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.