Old boys Education-linux operation and maintenance employment class first pre-course test questions and Answers

Source: Internet
Author: User
Tags create directory tmp folder

First question Create a directory/data

[Email protected] ~]# Mkdir/data

1.1 Extension Knowledge 1:

Create directory ===== make directory mkdir

1.2 Extension Knowledge 2: If an identical directory already exists, the following error message will be reported

[[email protected] ~]# mkdir/datamkdir:cannot Create directory '/data ': File exists

1.3 Extension Knowledge 3: View content below the display directory

[[email protected] ~]# ls/data[[email protected] ~]# ls-l/data/total 0

1.4 Extension Knowledge 4: Go to another directory to enter the directory

[Email protected] ~]# cd/data/

1.5 extension Knowledge 5: View current directory/path (location)

[Email protected] data]# Pwd/data

1.6 Extension Knowledge 6: Relative path and absolute path

1. Simple-relative path is not the path from the root start from the current position

Data

etc/hosts

Etc/sysconfig/network-scripts/ifcfg-eth0

2. Exact-Path of absolute path starting from root

/data

/etc/hosts

/etc/sysconfig/network-scripts/ifcfg-eth0


The second question creates a file under/data oldboy.txt

[Email protected] data]# touch/data/oldboy.txt[[email protected] data]# ls-l/data/total 0-rw-r--r--. 1 root root 0 Sep 3 15:04 oldboy.txt



The third is titled Oldboy.txt add Content "I am studying Linux."

3.1 Method One: VI or VIM

First Step: Open file

Vi/data/oldboy.txt

Step two: Edit the file

Press I (A,O)

Edit file, enter content

Step three: Exit edit mode

After programming, press ESC to exit edit mode

Fourth Step: Save exit

: Wq (Plus! for coercion)

: q! Force quit does not save

: wq! Force Save exit

Which: W means that write,q means quit.

Fifth Step: View

[Email protected] ~]# cat/data/oldboy.txt I am studying Linux.


Note: In Linux, VI is equivalent to Notepad in Windows, and Vim is equivalent to notepad++, EmEditor, subline in Windows


3.2 Method Two: Use echo+ append/output redirection

[Email protected] ~]# echo "I am studying Linux." I am studying Linux. [Email protected] ~]# echo "I am studying Linux." >>/data/oldboy.txt [[email protected] ~]# Cat/data/oldboy.txti am studying Linux.

>> Funnel Append redirect appends the content to the end of the file, equivalent to "add"

> Funnel Output redirection clears the contents of the source file before storing it in the file, which is equivalent to "overwrite"


3.3 Method Three: Append multiple lines to a file using the Cat command

Cat >>/data/oldboy.txt<<eofiam oldboylinuxeof


EOF means: End of file here can replace EOF with any text, including Chinese, but must match the use.

Cannot have any symbols before closing the flag


The fourth question copies the Oldboy.txt (copy) to/tmp.

CP command: Copying copy

[Email protected] ~]# cp/data/oldboy.txt/tmp/[[email protected] ~]# ls-l/tmp/total 4-rw-r--r--. 1 root root Sep 3 16:02 oldboy.txt-rw-------. 1 root root 0 Sep 3 11:01 yum.log


extension Knowledge 1: parameter-r can copy folders and include sub-folders at the next level, as well as subfolders within subfolders.

[Email protected] ~]# cp-r/data//tmp/[[email protected] ~]# ls-l/tmp/total 8drwxr-xr-x. 2 root root 4096 Sep 3 16:05 data-rw-r--r--. 1 root root Sep 3 16:02 oldboy.txt-rw-------. 1 root root 0 Sep 3 11:01 yum.log


extension Knowledge 2:Another role of the CP command, backup

[Email protected] ~]# cp/data/oldboy.txt/data/oldboy.txt.bak[[email protected] ~]# ls-l/data/total 8-rw-r--r--. 1 root root Sep 3 15:50 oldboy.txt-rw-r--r--. 1 root root 3 Sep 16:22 Oldboy.txt.bak


Fifth, move the/data under the/root directory.

MV Command: Moving move

[Email protected] ~]# mv/data//root/[[email protected] ~]# ls-l/root/total 48-rw-------. 1 root root 1073 Sep 3 11:11 anaconda-ks.cfgdrwxr-x---. 2 root root 4096 Sep 3 anaconda-screenshotsdrwxr-xr-x. 2 root root 4096 Sep 3 16:22 data-rw-r--r--. 1 root root 21736 Sep 3 11:11 install.log-rw-r--r--. 1 root root 5890 Sep 3 11:10 install.log.syslog[[email protected] ~]# ls/datals:cannot access/data:no such file or D Irectory



Sixth. Enter the data directory under the/root directory to delete the Oldboy.txt file

NOTE1: I think this topic describes a problem, whether it should be changed: How to use a command to find all the files in the/data/folder ending in. txt, and delete.


The/tmp folder in Note2:linux is equivalent to the Recycle Bin in Windows. The more secure way to delete files is to move the files to be deleted with the MV command into the/tmp folder, if you find the problem after the operation can restore the file back to the original folder, if there is no problem after the/tmp folder files can be completely deleted.


To create a test environment:

[Email protected] ~]# mkdir/data [[email protected] ~]# Touch/data/oldboy.txt/data/alex.txt/data/zbz.txt

6.1 First step: Use the Find command to locate the file

[Email protected] ~]# find/root-type f-name "Oldboy.txt" [[email protected] ~]#/root/data/oldboy.txt

#find Find Location (path)-type What type-name "what name"

-typeF file files

D Directory Directories

-name "*.txt"

Files ending in. txt

* indicates all


6.2 Step Two: Use pipe breaks | (The Find command needs to be used in conjunction with |xargs)

[Email protected] data]# find/data/-type f-name "*.txt"/data/zbz.txt/data/alex.txt/data/oldboy.txt[[email protected  ] data]# find-type f-name "*.txt" |xargs rm or: [[email protected] data]# find/data/-type f-name "*.txt" |xargs-i mv {} /tmp/


Summary:

1.RM command: Remove Remove

-f parameter, no need to confirm direct deletion

Example: Rm-f oldboy.txt

-r parameter, delete folder

Example: rm-rf/tmp/data/

2.find command if mated with pipe character | Need to add Xargs

3. The "Alias" can not be recognized after the pipe, such as LL, so RM does not add-f can be silently deleted, you need to pay attention.

The-i parameter of 4.xargs:



Question seventh exit to the previous level directory to delete the data directory. (originally in/root/data)

[Email protected] data]# CD. [Email protected] ~]# RM-RF data/


Extended Knowledge:

.. Previous level directory, top level directory of current directory

. Current directory,/etc/sysconfig

Cases:

[Email protected] ~]# cp/tmp/oldboy.txt/etc/sysconfig [[email protected] ~]# cp/tmp/oldboy.txt.



Question Eighth please give a command that does not contain the Oldboy string when outputting the contents of a Test.txt file

To create a pilot environment command:

[Email protected] ~]# mkdir/data> cat >/data/test.txt<<EOF> test> lidao> oldboy> EOF


8.1 Method 1: Filter by using the-v parameter of the grep command

The grep command defaults to the output to find the line that contains the "" quotation marks inside the content.

[[email protected] data]# grep "Oldboy"/data/test.txt oldboy[[email protected] data]# grep "old"/data/test.txt Oldboy


The function of the grep command-v argument is to reverse the lookup, that is, to output all lines that do not contain "" quotes.

[Email protected] data]# grep-v "Oldboy"/data/test.txt Testlidao


8.2 Method 2: Non-normal method: Use the head command

[Email protected] data]# Head-n2/data/test.txt Testliyao

Because the-n parameter is too commonly used, it can be omitted, the same effect.

[Email protected] data]# head-2/data/test.txt Testliyao


Extended knowledge: The head command takes the first few lines out of the file and defaults to the first 10 lines

The tail command takes the last few lines of the file and defaults to the last 10 lines


8.3 Method 3: Use the D parameter of the SED command

[[Email protected] data]# sed '/oldboy/d ' test.txt Testliyao


Extended knowledge: The main function of the SED command is to find replacements, and the D parameter is to delete the selected rows.

Cases:

To delete a blank line:

Sed '/^$/d ' file

Delete the 2nd line of the file:

Sed ' 2d ' file

Delete all lines from line 2nd to the end of the file:

Sed ' 2, $d ' file

Delete the last line of the file:

Sed ' $d ' file

Delete all lines in the file that begin with test:

Sed '/^test/' d file


8.4 Method 4: Use the awk command and!

[[email protected] data]# awk '/oldboy/' test.txt oldboy[[email protected] data]# awk '!/oldboy/' test.txt Testliyao


8.5 Other extension methods:

[[email protected] data]# sed-n '/oldboy/!p ' test.txt testliyao[[email protected] data]# grep "^[tl" "Test.txt Testliyao


Question Nineth use a command to complete the creation of the directory/oldboy/test, which is to create the/oldboy directory and/oldboy/test

Use the-P option for the mkdir command

[Email protected]/]# mkdir-p/oldboy/test


The tenth problem known AS/tmp already exists Test.txt file, how to execute the command to the/mnt/test.txt copy to/tmp to cover the/tmp/test.txt, and let the system does not prompt whether to overwrite (root authority).

10.1 Method 1:CP command before adding \

[Email protected] mnt]# \cp/mnt/test.txt/tmp/test.txt


10.2 Method 2: Use the absolute path of the command

[email protected] mnt]# which Cpalias cp= ' cp-i '/bin/cp[[email protected] mnt]#/bin/cp/mnt/test.txt/tmp/test.txt


Question 11th only see the contents of lines 20th through 30th in the Ett.txt file (total 100 lines)

Create a test environment

[[email protected] tmp]# seq >ett.txt[[email protected] tmp]# cat Ett.txt


11.1 Method 1:head + Tail

[Email protected] data]# head-30 ett.txt |tail-112021222324252627282930

11.2 Method 2:sed

[Email protected] data]# sed-n ' 20,30p ' ett.txt 20 ... 30


11.3 Method 3:awk

[[email protected] data]# awk ' nr==20 ' ett.txt 20[[email protected] data]# awk ' nr==30 ' ett.txt 30[[email protected] data] # awk ' nr==20,nr==30 ' ett.txt 20 ... 30


Note: NR denotes line number in awk


11.4 Method 4:grep

[Email protected] data]# grep-a10 "Ett.txt 20 ... 30


NOTE:-A9 shows what grep found and the next 9 lines



Old boy Education daily-125th day-show file Oldboy.txt line 20th to 30 lines how do I do that?

http://lidao.blog.51cto.com/3388056/1961519


Summary:

1.head+tail

2.sed take a row to take a contiguous number of rows

3. Learn how awk is used


The 12th Analysis picture Service log, the log (each picture access times * Picture size sum) ranked, take Top10, that is, calculate the total access size of each URL "additional title: The work scene high difficulty plus sub-problem, will not students can give up not answer."

Description: The production environment application: This function can be used for IDC website traffic bandwidth is very high, and then by analyzing the server log which elements occupy too much traffic,

In order to optimize or cut the picture, compression JS and other measures.


The subject needs to output three indicators: "Number of visits" "Number of Visits * Single File size" "File name (can take URL)"

Test data

59.33.26.105--[08/dec/2010:15:43:56 +0800] "get/static/images/photos/2.jpg http/1.1" 200 11299

"Http://oldboy.blog.51cto.com/static/web/column/17/index.shtml?courseId=43" "mozilla/4.0 (compatible;

MSIE 6.0; Windows NT 5.1; SV1;. NET CLR 2.0.50727;. NET CLR 3.0.4506.2152;. NET CLR 3.5.30729) "

59.33.26.105--[08/dec/2010:15:43:56 +0800] "get/static/images/photos/2.jpg http/1.1" 200 11299

"Http://oldboy.blog.51cto.com/static/web/column/17/index.shtml?courseId=43" "mozilla/4.0 (compatible;

MSIE 6.0; Windows NT 5.1; SV1;. NET CLR 2.0.50727;. NET CLR 3.0.4506.2152;. NET CLR 3.5.30729) "

59.33.26.105--[08/dec/2010:15:44:02 +0800] "get/static/flex/vedioloading.swf http/1.1" 200 3583

"Http://oldboy.blog.51cto.com/static/flex/adobevideoplayer.swf?width=590&height=328&url=/[[dynamic]]/2 "

"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;. NET CLR 2.0.50727;. NET CLR 3.0.4506.2152;. Net

CLR 3.5.30729) "

124.115.4.18--[08/dec/2010:15:44:15 +0800] "GET/?= http/1.1" 200 46232 "-" "-"

124.115.4.18--[08/dec/2010:15:44:25 +0800] "get/static/js/web_js.js http/1.1" 200 4460 "-" "-"

124.115.4.18--[08/dec/2010:15:44:25 +0800] "get/static/js/jquery.lazyload.js http/1.1" 200 1627 "-" "-"


Answer: not currently





The 13th question is to replace all files containing Oldboy in the/oldboy directory and its subdirectories with the file with the extension. SH, replacing all the strings with Oldgirl

Research highlights:

How the SED command performs a lookup substitution

Find command mates with sed command


To create a pilot environment:

Mkdir-p/oldboy/test

Cd/oldboy

echo "Oldboy" >test/del.sh

echo "Oldboy" >test.sh

echo "Oldboy" >t.sh

Touch Oldboy.txt

Touch Alex.txt


Check the test environment:

[[email protected] oldboy]# find

.

./t.sh

./test.sh

./test

./test/del.sh

./alex.txt

./oldboy.txt


13.1 First step: Find all files in the/oldboy directory and its subdirectories that end with the extension. sh

Find all Files:

[Email protected] oldboy]# find/oldboy/-type f/oldboy/t.sh/oldboy/test.sh/oldboy/test/del.sh/oldboy/alex.txt/ Oldboy/oldboy.txt

Find all files ending with. sh

[Email protected] oldboy]# find/oldboy/-type f-name "*.sh"/oldboy/t.sh/oldboy/test.sh/oldboy/test/del.sh


13.2 Step Two: How to replace the Oldboy in a file with the Oldgirl

[[email protected] oldboy]# #sed ' s# What you're looking for # replace it with what #g '/oldboy/t.sh [[email protected] oldboy]# sed ' s#oldboy#oldgirl#g '/old boy/t.sh Oldgirl[[email protected] oldboy]# cat/oldboy/t.sh Oldboy

The note:sed command does not add the-I parameter, only the characters displayed to the screen are modified, not the characters of the original file.

[Email protected] oldboy]# sed-i ' s#oldboy#oldgirl#g '/oldboy/t.sh [[email protected] oldboy]# cat/oldboy/t.sh Oldgirl


13.3 Step three: passing content found by the Find command to SED

[Email protected] oldboy]# find/oldboy/-type f-name "*.sh" |xargs sed ' s#oldboy#oldgirl#g ' oldgirloldgirloldgirl[[ Email protected] oldboy]# find/oldboy/-type f-name "*.sh" |xargs sed ' s#oldboy#oldgirl#g '-i[[email protected] oldboy]# find/oldboy/-type f-name "*.sh" |xargs cat Oldgirloldgirloldgirl


Note:

1.find command to mate with |xargs

How the 2.sed command finds and replaces

3.sed-i to modify the contents of a file


This article is from "Laopan linux" blog, please be sure to keep this source http://oldpan.blog.51cto.com/1603893/1965211

Old boys Education-linux operation and maintenance employment class first pre-course test questions and Answers

Related Article

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.