Day4, Linux basic topics

Source: Internet
Author: User

First question

I want to create a da.txt file under the/data/da directory

[Email protected] ~]# cd/data/oldboyedu

-BASH:CD:/data/oldboyedu:no such file or directory

1. Why this error has occurred

Because there is no such directory

2. How do I resolve this error?

Create these two directories: Mkdir-p/data/da

Second question

Answer the question and add the content "I Love studying Linux" to da.txt. (not less than 2 methods)

Method One

Command format: echo "I love studying Linux." >>/data/da.txt

[Email protected] ~]# echo "I Love studying Linux." >>/data/da.txt

[Email protected] ~]# Cat/data/da.txt

I Love studying Linux.

Method Two

Command format: Cat >/data/da.txt <<eof

> I Love studying Linux.

> EOF

[email protected] ~]# cat >/data/da.txt <<eof

> I Love studying Linux.

> EOF

[Email protected] ~]# Cat/data/da.txt

I Love studying Linux.

Third question

Copy the/data directory to the/tmp directory

Command format: Cp-r/data//tmp/

[Email protected] ~]# cp-r/data//tmp/

Question Fourth

Say these special symbolic meanings: > >> 2> 2>> # (pound). (point): (two points)

Standard output redirection, first clear the contents of the file, and then put the new content into the file.

>>: Append output redirection, do not clear the contents of the file, put new content at the end of the file.

2>: Error output redirection, first clear the contents of the file, and then put the command error prompt into the file.

2>>: Error Append output Redirect, unclear file contents, append command error Prompt to end of file.

# (number): note Symbols in Linux,

. (point): Indicates the current path.

.. (dot): Represents the previous layer path.

Question Fifth

Test.txt content is:

Trainning

Fanbingbing

Lidao

Please give the command that does not contain the trainning string when outputting the contents of the Test.txt file.

Method One

Command format: Tail-2/test.txt

[Email protected] ~]# Tail-2/test.txt

Fanbingbing

Lidao

Method Two

Command format: sed '/trainning/d '/test.txt

[[Email protected] ~]# sed '/trainning/d '/test.txt

Fanbingbing

Lidao

Method Three

Command format: grep-v "trainning"/test.txt

[Email protected] ~]# grep-v "trainning"/test.txt

Fanbingbing

Lidao

Method Four

Command format: awk '!/trainning/' test.txt

[Email protected] ~]# awk '!/trainning/' test.txt

Fanbingbing

Lidao

Question Sixth

The new company, the boss lets you restrict the RM command on the server, when the user enters the RM command, it prompts "rm command is not allowed to use." What are the steps to be implemented?

The first step:

Command format: Alias rm= ' echo RM command is not allowed to use. '

[[email protected] ~]# alias rm= ' echo RM command is not allowed to use. '

[Email protected] ~]# RM test.txt

RM command is not a allowed to use. Test.txt

Step two: Write the/etc/profile configuration file

[Email protected] ~]# echo "Alias rm= ' echo RM command is not allowed to use. '" >>/etc/profile

Step Three: Effective

[Email protected] ~]# Source/etc/profile

Question Seventh

Remove the contents of the 30th to 40th line of the file ett.txt.

Method One

Command format: sed-n ' 30,40p '/ett.txt

[Email protected] ~]# sed-n ' 30,40p '/ett.txt

30

31

32

33

34

35

36

37

38

39

40

Method Two

Command format: awk ' nr==30,nr==40 '/ett.txt

[Email protected] ~]# awk ' nr==30,nr==40 '/ett.txt

30

31

32

33

34

35

36

37

38

39

40

Method Three

Command format: Head-40/ett.txt |tail-11

[Email protected] ~]# Head-40/ett.txt |tail-11

30

31

32

33

34

35

36

37

38

39

40

Question Eighth

Modify the trainning in the Test.txt file to lll.

Method One

Command format: find/data/-type f-name "test.txt" |xargs sed-i ' s#trainning#lll#g '

[Email protected] ~]# find/data/-type f-name "test.txt" |xargs sed ' s#trainning#lll#g '

lll

Fanbingbing

Lidao

[Email protected] ~]# find/data/-type f-name "test.txt" |xargs sed-i ' s#trainning#lll#g '

Method Two

Command format: Sed-i ' s#trainning#lll#g ' $ (find/data/-type f-name "Test.txt")

[[Email protected] ~]# sed ' s#trainning#lll#g ' $ (find/data/-type f-name "Test.txt")

lll

Fanbingbing

Lidao

[[email protected] ~]# sed-i ' s#trainning#lll#g ' $ (find/data/-type f-name "Test.txt")

Method Three

Command format: find/data/-type f-name "test.txt"-exec sed-i ' s#trainning#lll#g ' {} \;

[Email protected] ~]# find/data/-type f-name "test.txt"-exec sed-i ' s#trainning#lll#g ' {} \;

[[email protected] ~]# find/data/-type f-name "test.txt"-exec sed ' s#trainning#lll#g ' {} \;

lll

Fanbingbing

Lidao

Question Nineth

Find all files in the/data directory ending in. txt, and modify the trainning in the file to LLL.

Command format:

find/data/-type f-name "*.txt" |xargs sed-i ' s#trainning#lll#g '

Sed-i ' S#trainning#lll#g ' $ (find/data/-type f-name "*.txt")

find/data/-type f-name "*.txt"-exec sed-i ' s#trainning#lll#g ' {} \;

Question Tenth

Find all files under/data that are larger than 1M at the end of log copy to/tmp.

Command format: Find/data-type f-name "*.log"-size +1m

Method 1

CP $ (Find/data-type f-name "*.log"-size +1m)/tmp

Method 2

Find/data-type f-name "*.log"-size +1m |xargs cp-t/tmp

Method 3

Find/data-type f-name "*.log"-size +1m |xargs-i CP {}/tmp

Method 4

Find/data-type f-name "*.log"-size +1m-exec CP {}/tmp \;

Question 11th

What is the operating level of Linux, describe the meaning of different numbers of Linux running levels? (Additional questions)

    1. Run Level 0-6

0 means shutdown

1 means single user

2 represents multiuser but no NFS

3 represents the full multi-user status command-line mode command mode

4 Not used

5 Graphical interface mode

6 restart

    1. How to view run levels

RunLevel command

    1. How to configure the run level

/etc/inittab file

    1. Temporarily modify the init command

Init 5

Question 12th

Please describe the difference between buffer and cache (additional question)?

Buffer: buffers, write buffer data written to in-memory buffers

Cache: Cache, read cache reads data from in-memory buffers

Day4, Linux basic topics

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.