Linux Basic Test--11 problem

Source: Internet
Author: User

000. Create a directory/data

1 mkdir/data

001. Create a file under/data oldboy.txt

1 touch/data/oldboy.txt

002. Add content for Oldboy.txt to "I am studying Linux."

1 vi/data/oldboy.txt #点按i键进入编辑模式 2 I am studying Linux.  #点按ESC键退出编辑模式 3~                                                                                                                                                     4~                                                                                                                                                     5~                                                                                                                                                 
: Wq

003. Copy the Oldboy.txt file to/tmp

Cp/data/oldboy.txt/tmp

004. Move the/data directory to the/root

Cp/data/oldboy.txt/tmp

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

Cd/root/data
Find-type f-name ' oldboy.txt ' |xargs rm

006, answer the question, exit to the previous level directory, delete the data directory

Cd.. \rm-r  /root/data

007, the known file Test.txt content is: 

1 Test 2 Liyao 3 Oldboy

Please give a command that does not include the Oldboy string when outputting the contents of the Test.txt file

Create a test environment

1 [email protected]/]# Touch/data/test.txt 2 [email protected]/]# Cd/data 3 [ Email protected] data]# vi test.txt               #创建环境 4[[email protected] data]# cat Test.txt #查看测试 File 5test6Liyao7 Oldboy

1. Head command

1 [email protected] data]# head-2/data/test.txt 2 Test 3 Liyao

2. grep command

1 [email protected] data]# grep-v ' Oldboy '/data/test.txt 2 Test 3 Liyao

3. SED command

1 [[email protected] data]# sed '/oldboy/d '/data/test.txt 2 Test 3 Liyao

008. Use a command to complete the creation of the directory/oldboy/test, that is to create the/oldboy directory and/oldboy/test directory

1. Clumsy wording

Mkdir/oldboy/oldboy/test

2. Elegant notation

Mkdir-p/oldboy/test

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

  Use cp-f directly, fail.

1, first think even use cp-f will also prompt whether to overwrite, and then think of the Linux alias mechanism:

12alias cp= ' cp-i '3alias l.= ' ls-d. *--color=auto '4  Alias ll= ' ls-l--color=auto '5alias ls= ' ls--color=auto '6alias mv= ' Mv-i '  7alias rm= ' echo * use more secure command '8 alias Which= ' Alias | /usr/bin/which--tty-only--read-alias--show-dot--show-tilde '

You can see that Linux executes the CP command when the default parameter is-I, modifying the default parameter to-F (dangerous, only for the purpose of the problem):

1 [email protected]/]# Touch/mnt/test.txt 2 [email protected]/]# cp/mnt/test.txt/tmp 3

You can see that there is no prompt to overwrite directly.

2. Use \

1 [email protected]/]# \cp/mnt/test.txt/tmp 2

010. View only the contents of lines 20th through 30th in the Ett.txt file (total 100 lines)

To create a test environment:

  1[[email protected]/]# seq >ett.txt  2[[email protected]/]# cat Ett.txt    31  42  53  6 4   75          #太长省略

1. Use head, tail command

1 [email protected]/]# Head-30/ett.txt | tail-11 2  - 3  + 4  A 5  at 6  - 7  - 8  - 9  - Ten  -  One  in  30

2. Using the SED command

1 [email protected]/]# sed-n ' 20,30p ' ett.txt 2  - 3  + 4  A 5  at 6  - 7  - 8  - 9  - Ten  -  One  in  30

#说明: The above code reference study "old boy education 36 preview Video"

#https://linux.cn/

#https://linux.cn/article-2713-1.html

Linux Basic Test--11 problem

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.