2014 the answers to 2,143 questions in the Linux0217 of Ma Brothers

Source: Internet
Author: User

A few days ago in doing 2014 Ma brother Linux0214 's homework, found that in fact, the three questions in 0217 has a solution, of course, I think Ma brother than his own writing too much, so can not help but to Marco the answer to put out for their own study.


First question: Write a script that shows how many lines/etc/init.d/functions,/etc/rc.d/rc.sysinit,/etc/fstab are displayed with a for loop


#!/bin/bash

For FileName In/etc/init.d/functions/etc/rc.d/rc.sysinit/etc/fstab;do

Linecount= ' Wc-l $fileName | Cut-d '-f1 '

echo "$fileName: $lineCount lines."

Done


or more concise:

#!/bin/bash

For FileName In/etc/init.d/functions/etc/rc.d/rc.sysinit/etc/fstab;do

echo "$fileName: ' Wc-l $fileName | cut-d '-f1 ' lines.

Done

The writing is undoubtedly the most concise.


The second question: write a script, the previous question in the three files copied to the/tmp directory, with A For loop implementation, respectively, each file last modified time to September 15, 2011 13:27.

#!/bin/bash

For FileName In/etc/init.d/functions/etc/rc.d/rc.sysinit/etc/fstab;do

CP $fileName/tmp

Basename= ' BaseName $fileName '

TOUCH-MT 201109151327/tmp/$baseName

Done


Third question: Write a script that shows the user names and ID numbers for the 3, 7, and 11 users in/etc/passwd.

#!/bin/bash

For Lineno in 3 7 11;do

userinfo= ' Head-n $lineNo/etc/passwd | Tail-1 | cut-d:-f1,3 '

Echo-e "User: ' Echo $userInfo | cut-d:-f1 ' \nuid: ' echo $userInfo | cut-d:-f2 ' "

Done

I wrote the following, made a little change, I feel fit my style, but the main frame unchanged.

#!/bin/bash

way=/etc/passwd

For Lineno in 3 7 11;do

echo "User name: ' head-$lineNo $way | Tail-1 | cut-d:-f1 ' UserID: ' head-$lineNo $way | Tail-1 | cut-d:-f3 ' "

Done

Personal feeling, Marco's third problem is a bit cumbersome ah.

At the beginning of a few toy programme, the value of inspiration for ideas is relatively large.

2014 the answers to 2,143 questions in the Linux0217 of Ma Brothers

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.