Linux transport Viban the first off after-class learning effect ability on-machine big investigation

Source: Internet
Author: User
Tags create directory gopher

Kan1, create directory/data/oldboy, and create file Oldboy.txt in this directory. The content "net addr:192.168.181.134 bcast:192.168.181.255 mask:255.255.255.0" (without quotation marks) is then written in the file oldboy.txt. Answer: The analysis process: To complete this problem, we first want to how to create a recursive directory. Law 1:[[email protected] oldboy]# mkdir/data/oldboy-p[[email protected] oldboy]# echo net addr:192.168.181.134 bcast:192.1 68.181.255 mask:255.255.255.0 >oldboy.txt Summary: 1) mkdir-p is used to recursively create the directory. 2) echo can be used to write content directly to the file, if the file does not exist, will automatically create the file, 2, the title 1 in the Oldboy.txt file content through the command filter only output the following: *****10.0.0.8 10.0.0.255 255.255.255.0net addr:192.168.181.134 bcast : 192.168.181.255 mask:255.255.255.0 Answer: [[email protected] oldboy]# awk-f "[:]+" ' {print $3,$5,$7} ' oldboy.txt192.168.18 1.134 192.168.181.255 255.255.255.0[[email protected] oldboy]# awk-f "[:]+" ' {print $ "" $ $ "" $7} ' oldboy.txt192.168.181 .134 192.168.181.255 255.255.255.0 Summary: 1)-F ' [:]+ ' indicates that the specified delimiter is a space and: there are two delimiters in the square brackets, so you need to add the + sign ' {print $ ' "$ $" "$7} ' to print out the characters of the third placeholder String, a fifth placeholder??? Seventh. "Space" is based on the title of the space to be printed to distinguish 3. Move the Oldboy directory in Title 1 to/tmp and copy the/etc/passwd file to/tmp/oldboy. [[email protected] ~]# mv/data/oldboy/tmp[[email protected] ~]# cp/etc/passwd/tmp/oldboy/Summary: 1) MV is a command for moving directories and files, with less RM command, Can first MV to/TMP after a long time there is no effect to delete, blood lesson ah. 2) CP is a copy file 4, on the basis of question 3, using awk to fetch passwd files, and so on line 10th to 20, redirect the third column to the/tmp/oldboy/test.txt file *****[[email protected] oldboy]# awk ' nr>9 && Amp Nr<21 ' Passwd[[email protected] oldboy]# awk-f ': ' nr>9 && nr<21 {print $} ' passwd >/tmp/oldboy/tes T.txt Summary: 1) AWK:NR line number,&& is and meaning. Awk can be used to handle the text that each row has to process. 2) using awk we have to look at the separators first and see their patterns. Then the-F ': ' To define the delimiter, the delimiter for this article is:. 3) ' nr>9 && nr<21 {print $} ' means that the NR line number is greater than 9 and less than 21,{} curly braces indicate that the preceding result is performed. That is, the string that prints the third placeholder for each line of NR10~20, and awk executes each line.   5, on the basis of question 3, requires the command RM to delete the file when prompted to disable the use of RM, and make the effect permanent. Rm-f passwd Donot Use rm command*****   answer: [[email protected] oldboy]# Echo ' Alias rm= ' echo not use RM Comm and "' Alias rm=" Echo not use RM command "[[email protected] oldboy]# Echo ' Alias rm= ' echo not use RM command ' >> /etc/profile[[email protected] oldboy]# Echo ' Alias rm= ' echo not use RM command ' Alias rm= ' echo not use RM command ' [[ Email protected] oldboy]# Echo ' Alias rm= ' echo not use RM command ' >>/etc/bashrc[[email protected] oldboy]#. /etc/profilealias rm= ' echo not use RM command ' Bash:alias: =echo:not foundbash:alias:not:not Foundbash:alias:use:no T Foundalias rm= ' echo not with rm command ' bash:alias:command:not foundalias rm= ' echo not use RM command ' Bash:alias: =ec Ho:not foundbash:alias:not:not foundbash:alias:use:not foundalias rm= ' echo not use RM command ' BASH:ALIAS:CHENBAOJ Ia:not found[[email protected] oldboy]#. /etc/bashrcalias rm= ' echo not use RMCommand ' Bash:alias: =echo:not foundbash:alias:not:not foundbash:alias:use:not foundalias rm= ' echo not use RM comma nd ' bash:alias:command:not foundalias rm= ' echo not use RM command ' Bash:alias: =echo:not foundbash:alias:not:not Fou Ndbash:alias:use:not Foundalias rm= ' echo not the use RM command ' Bash:alias:chenbaojia:not found summary: 1) alias setting aliases 2) etc/prof Ile This file is an environment variable setting that runs every time a user logs on. Bashfile is a single-user login, such as Root will run 3)./Etc/profile (./dots plus a file, which means that you can reload the file and make it effective without rebooting.) ) 6, on the basis of the title 3, delete/tmp/oldboy/passwd other than the beginning of the document. Solution: French one [[email protected] oldboy]# find/tmp/oldboy/-type f! -name ' passwd '-exec rm-f {} \; [[email protected] oldboy]# Lspasswd[[email protected] oldboy]# touch oldboy.txt test.txt/tmp/oldboy/[[email protected] oldboy]# lsoldboy.txt passwd test.txt[[email protected] oldboy]# find/tmp/oldboy/-type f! -name "passwd" |xargs/tmp/oldboy/oldboy.txt/tmp/oldboy/test.txt Law II [[email protected] oldboy]# find/tmp/oldboy/-type F ! -name "passwd" |xargs rm-f[[email protected] oldboy]# lspasswd Summary: 1)! is to take the opposite meaning,! -name ' passwd ' is said to find other files besides passwd. -exec is the find parameter, which means that the result of the-exec front is given to the following command execution, {} \; This is a fixed format that must be added after the command. 2) |xargs is also to the previous results to the following command processing. 7, on the basis of question 3, please print the 2nd to 5th line in the/etc/passwd file (no less than three methods) answer: Law one [[email protected] oldboy]# head-5 passwd |tail-4bin:x:1:1:bin:/bin :/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/ Spool/lpd:/sbin/nologin Law II: [[email protected] oldboy]# head-5 passwd |tail-4bin:x:1:1:bin:/bin:/sbin/nologindaemon:x : 2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologin Law III: [[email protected] oldboy]# sed-n ' 2,5 ' p passwdbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/ Nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologin Summary: 1) The head command defaults to the output text before 10,-(number) Represents the line number that needs to be output 2) the tail command defaults to the output text after 10,-(number) indicates the need to output to line number 3) Sed-n (without the-n default all output, plus after the output according to our specified result,) p means the print output. 8, on the basis of the title 3, use the command to replace the root position and/bin/bash location in the passwd file? All the first and last column positions will be swapped. Example: * * * * * default:root:x:0:0:root:/root/:/bin/bash  modified after/bin/bash:x:0:0:root:/root:root answer: [[email protected] oldboy]# awk-f ': ' {print $7,$2,$3,$4,$5,$6,$1} ' Passwd/bin/bash x 0 0 root/root root/sbin/nologin x 1 1 bin/bin bin/s Bin/nologin x 2 2 daemon/sbin daemon/sbin/nologin x 3 4 adm/var/adm adm/sbin/nologin x 4 7 LP/VAR/SPOOL/LPD Lp/bin/sync X 5 0 Sync/sbin Sync/sbin/shutdown x 6 0 shutdown/sbin Shutdown/sbin/halt x 7 0 halt/sbin halt/sbin/nologin x 8 mai L/var/spool/mail mail/sbin/nologin x UUCP/VAR/SPOOL/UUCP uucp/sbin/nologin x 0 operator/root Operator/sbin/nol Ogin x games/usr/games games/sbin/nologin x gopher/var/gopher gopher/sbin/nologin x GB FTP user/var/ftp Ftp/sbin/nologin x Nobody/nobody/sbin/nologin x owner/dev vcsa/sbin/nologin x 499 7 6 SASLAUTHD user/var/empty/saslauth saslauth/sbin/nologin x 89/var/spool/postfix postfix/Sbin/nologin x privilege-separated ssh/var/empty/sshd sshd/bin/bash x 500/home/oldboy oldboy/sbin/nologin x 38 38/ETC/NTP NTP Summary: 1) awk can be used to process text that each row needs to process, because awk executes on a line-by-row basis. Use the delimiter, and then print the string that corresponds to the placeholder   9. Replace all strings containing oldgirl in the/data directory and its subdirectories with all files that end with the extension. txt as Oldboy. Answer: [[email protected] data]# find/data/-type f-name ' *.txt '/data/12.txt/data/1.txt/data/oldboy.txt/data/ 3307/aa.txt/data/3307/123.txt/data/456.txt/data/a.txt/data/3306/456.txt/data/3306/123.txt/data/123.txt[[email  protected] data]# find/data/-type f-name ' *.txt ' |xargs sed "s#oldgirl#oldboy#g" oldboyoldboyinet addr : 192.168.181.134 bcast:192.168.181.255 mask:255.255.255.0oldboyoldboyoldboyoldboyoldboyoldboyoldboy[[email  Protected] data]# find/data/-type f-name ' *.txt ' |xargs sed-i "s#oldgirl#oldboy#g" [[email protected] data]# Find/ data/-type f-name ' *.txt ' |xargs catoldboyoldboyinet addr:192.168.181.134 bcast:192.168.181.255 Mask : 255.255.255.0oldboyoldboyoldboyoldboyoldboyoldboyoldboy Summary: 1) First find plus file path then-type f to determine file type,-name "*.txt" * Represents all files whose name is a. txt suffix. Show up. 2) |xargs The meaning of the pipeline to the previous search results to the following command 3) sed ' s## #g ' This is the standard format, of course the # key can be any of the same characters instead. The sed "s#oldgirl#oldboy#g" replaces Oldgirl with Oldboy. Then you can see the results. 4) Confirm error after seeing the result, find/data/-type f-name ' *.txt ' |xargs sed-i "s#oldgirl#oldboy#g" plus-I confirm the change, and then we're looking at it. Confirm the results. &NBSP;10, find/oldboy all 7 days ago with the olg end of the heavy rain 1M file moved to/tmp * * * * * * * * * * * * * *: [[email protected] oldboy]# LS-LH first simulation of files larger than 1M, View the maximum number of files closest to the current file. Total dosage 624k-rw-r--r--1 root root 596K November 13:34 456.log This is the closest drwxr-xr-x 3 root root 4.0K November 06:27 ext-rw-r--r--1 ro OT root 0 November 06:27 jeacendrwxr-xr-x 2 root root 4.0K November 07:16 new-rw-r--r--1 root root 24 November 05:57 nginx.conf -rw-r--r--1 root root 0 November 06:27 oldboydrwxr-xr-x 2 root root 4.0K November 06:27 test-rw-r--r--1 root root 0 November 12 0 6:27 widi.gzdrwxr-xr-x 2 root root 4.0K November 06:27 xiaodongdrwxr-xr-x 2 root root 4.0K November 06:27 xiaofandrwxr-xr-x 2 Root root 4.0K November 06:27 xingfujie-rw-r--r--1 root root 0 November 06:27 yingsui.gz[[email protected] oldboy]# cat 456.log >>123.log Append data, let him become 1m+[[email protected] oldboy]# cat 456.log >>123.log not enough again, and append the data to 123.log[[email protected] oldboy]# ls-lh Total usage 1.8m-rw-r--r--1 root root 1.2M December 3 00:07 123.log meet data requirements-rw-r- -r--1 root root 596K November 13:34 456.loGdrwxr-xr-x 3 root root 4.0K November 06:27 ext-rw-r--r--1 root root 0 November 06:27 jeacendrwxr-xr-x 2 root root 4.0K November 1 2 07:16 new-rw-r--r--1 root root 24 November 05:57 nginx.conf-rw-r--r--1 root root 0 November 06:27 oldboydrwxr-xr-x 2 root Root 4.0K November 06:27 test-rw-r--r--1 root root 0 November 06:27 widi.gzdrwxr-xr-x 2 root root 4.0K November 06:27 xiaodongd Rwxr-xr-x 2 root root 4.0K November 06:27 xiaofandrwxr-xr-x 2 root root 4.0K November 06:27 xingfujie-rw-r--r--1 root root 0 November 06:27 yingsui.gz [[email protected] oldboy]# cat 456.log >>455.log This is to make two files time consistent,[[email  Protected] oldboy]# LS-LH total dosage 2.4m-rw-r--r--1 root root 1.2M December 3 00:07 123.log-rw-r--r--1 root root 596K December 3 00:08 4 55.log-rw-r--r--1 root root 596K November 13:34 456.logdrwxr-xr-x 3 root root 4.0K November 06:27 ext-rw-r--r--1 root root 0 November 06:27 jeacendrwxr-xr-x 2 root root 4.0K November 07:16 new-rw-r--r--1 root root 24 November 05:57 nginx.conf-rw-r--r- -1 root root 0 November 12 06:27 Oldboydrwxr-xr-x 2 root root 4.0K November 06:27 test-rw-r--r--1 root root 0 November 06:27 widi.gzdrwxr-xr-x 2 root root 4. 0K November 06:27 xiaodongdrwxr-xr-x 2 root root 4.0K November 06:27 xiaofandrwxr-xr-x 2 root root 4.0K November 06:27 Xingfujie -rw-r--r--1 root root 0 November 06:27 yingsui.gz[[email protected] oldboy]# date-s 201,612,152,016 December 15 Thu 00:00:0 0 cst[[email protected] oldboy]# find/oldboy/-type f-name "*log"-size +1m-mtime +7/OLDBOY/123.LOG[[EMAIL&NBSP;PR Otected] oldboy]# find/oldboy/-type f-name "*log"-size +1m-mtime +7-exec MV {}/tmp \; [[email protected] oldboy]# ls-lh/tmp/total dosage 1.2m-rw-r--r--1 root root 1.2M December 3 00:07 123.log-rw-r--r--1 root root 0 November 09:13 ettdrwxr-xr-x 2 root root 4.0K November 10:35 oldboy-rw-r--r--1 root root 931 November 08:27 passwd[[email&nb Sp;protected] Oldboy] #总结1) First we simulate the data, create a file greater than 1M 2) and then change the time to seven days after the date-s modification time, because the system creates the file time at the time of creation, and when we modify the system time, the file time remains the same. 3) find/oldboy/-type f-name "*log"-size +1m-mtime +7 indicates the OldboyDirectory looking for *.log files,-size is the file size parameters, note kb words are to lowercase. MB is uppercase. -mtime +7 is the time parameter, +7 is seven days ago,-7 is within seven days. 7 is the last seven days. 4)-exec MV {}/tmp \; The MV {} curly braces indicate the result of the preceding processing. 11, what is the operating level of Linux, please describe the Linux operating level of different numbers meaning (additional questions) [[email protected] data]# Cat/etc/inittab View current system run level file 0-halt (do not set Initdefault to this) shutdown # 1-single user mode Single-user mode # 2-multiuser, without NFS (the same as 3, if you don't have networking) multi-user no NFS equivalent to Windows Safe Mode # 3-full Multius Er mode full multi-user command line mode # 4-unused reserved # 5-x11 graphical interface mode # 6-reboot (do not set Initdefault to this) restart 12. Please describe the difference between buffer and cache (additional questions) Answer: 1) write the data into memory, where the data is stored is called Buffer buffer 2) to access the data from within, this is called the cache cache. 13, please say you know the following characters in Linux can represent the meaning (additional questions) ~-. .. | > >> < <<! Answer: ~: Indicates the administrator's home directory-: Represents the previous level of directory.: Indicates the current directory |: The output heavy object >>: Append output Heavy object <: Input Heavy Object << : Append input Heavy Object! : Take the opposite meaning.

Linux transport Viban the first off after-class learning effect ability on-machine big investigation

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.