Linux first pre-class test questions

Source: Internet
Author: User

1. Create a directory /data

Answer:

Method One: Mkdir/data

Method two: CD/; mkdir data

2. Create a file under/data oldboy.txt

Answer:

Method one: cd/data/; Touch Oldboy.txt

Method Two: Touch/data/oldboy.txt

3. added "I am studying linux" content for oldboy.txt

Answer:

Method One: Echo "I amstudying Linux" >oldboy.txt

Method Two: VI oldboy.txt

I am studying Linux

Method Three:CAT >>oldboy.txt<<eof

Iam studying Linux

Eof

4. Copy the Oldboy.txt file to / tmp

Solution: CP oldboy.txt/tmp

5. Copy the Oldboy.txt file to / tmp ( without any hint )

Answer:

Method One:/BIN/CP oldboy.txt/tmp

Method Two: \cp oldboy.txt/tmp

6. Move the/data directory to the /root

Answer:

mv/data//root

7.enter The data directory under the/root directory to delete the oldboy.txt file

Answer:

Cd/root/data; RM oldboy.txt

8, after the seventh question, exit to the previous level directory, delete the data directory

Answer:

Cd.. ; Rm–r/data


9, the known file test.txt content is

Congzhongzhi

Lidao

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

Answer:

Method One: Head-1 test.txt

Method Two: Grep–v "Lidao" test.txt

Method Three: sed '/lidao/d ' test.txt

Method four: Sed-n '/congzhongzhi/p ' test.txt or sed-n ' 1p ' test.txt

Method Five: awk '!/lidao/' test.txt

please use a command to complete the creation of the directory/oldboy/test, that is, create /oldboy directory and /oldboy/test directory

Answer:

Mkdir–p/oldboy/test

One, the known/ tmp already exists test.txt file, how to execute the command to put /mnt/test.txt Copy to / tmp cover it down .

/tmp/test.txt , and let the system not prompt whether to overwrite ( Root permissions).

Answer:

Method One:\cp/mnt/test.txt/tmp

Method Two:/bin/cp/mnt/test.txt/tmp

View Only the contents of the ett.txt file (a total of two lines) within the first line

Answer:

Method One: head–30 ett.txt |tail-11

Method Two: Sed-n ' 20,30p ' ett.txt

Method Three: awk ' {if (nr>19&&nr<31) print $} ' Ett.txt

Method four: awk ' nr>19&&nr<31 ' ett.txt

Method Three: Grep–a10 ett.txt

grep–b1030 Ett.txt

GREP–C5 Ett.txt

13, the /oldboy all of the directories and their subdirectories with the extension . SH the end of the file contains ./hostlists.txt all of the strings are replaced by .. /idctest_iplist

Answer:

Method One: Find/oldboy–type f–name "*.sh" |xargs sed–i ' S#./hostlists.txt #. /idctest_iplist #g '

Method Two: Find/oldboy–type f–name "*.sh" exec sed–i ' S#./hostlists.txt #. /idctest_iplist#g ' {} \;

Method Three: Sed–i ' S#./hostlists.txt #. /idctest_iplist #g '

Method four: For statement (script common)

For i in ' Ll/oldboy |grep. Sh|awk ' {print $NF} '

Do

Sed–i ' s#./hostlists.txt #. /idctest_iplist #g '

Done

Method Five: Sed-i ' s#oldboy#oldgirl#g ' find/oldboy/-type f-name "*.sh" '

Sed-i ' S#oldboy#oldgirl#g ' $ (find/oldboy/-type f-name "*.sh")


This article is from the "Heyong" blog, make sure to keep this source http://heyong.blog.51cto.com/13121269/1954505

Linux first pre-class test questions

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.