Shell Learning Example One

Source: Internet
Author: User
Tags stdin

Enterprise Face question 1:
Use the For loop to create a batch of 10 files in the/oldboy directory, with the name in turn:
Oldboy-1
Oldboy-2
Oldboy-3
......
Oldboy-10
Hint: In the future to test everyone file prefix is also random, the end is a number sequence.
For example, randomly create 10 files, contain Oldboy strings, end with 1-10, and the extension is HTML.
Example: afds_oldboy_1.html,khadf_oldboy_2.html

The script is as follows:

#!/bin/bash#if [!-D "./oldboy"]# then mkdir./oldboy#fi# The following statements can also achieve the function of the above judgment [!-D./oldboy] && mkdir./oldboyfo R i in ' seq 1 ' do touch./oldboy/oldboy-${i}done

or use the following command directly: Touch oldboy-{1..10}

Enterprise Face question 2:
Change all the Oldboy in the above file name to Linux (implemented with a For loop).
Hint: In the future, we will try to replace the Oldboy in the file name with Linux, and the extension to uppercase.

Non-generic:

#!/bin/bashfor i in ' seq 1 ' do mv./oldboy/oldboy-${i}./oldboy/chen-${i}done

More general:

#!/bin/bashif [-D./oldboy]then echo "if" CD./oldboyelse echo "Else" mkdir./oldboy CD./oldboyfifor i in ' ls jun* ' do MV $i ' echo $i | Sed "s/jun/chen/g" ' Done

Note the use of SED commands, which can replace characters

or use the following command directly: Rename Chen June chen*

Note the use of the Rename command, rename from to File,man rename, press Q to exit

Enterprise Face question 3:
Batch Create 10 System account OLDBOY01-OLDBOY10 and set the password (the password cannot be the same).
The number plus 0 idea: http://oldboy.blog.51cto.com/2561410/788422

#!/bin/bashfor i in ' SEQ 1 3 ' Do useradd chen${i} && echo "Chen${i}" | passwd--stdin Chen${i}done

passwd--stdin to enter the password from the standard input.

Enterprise Face question 4:
Batch Create 10 System account OLDBOY01-OLDBOY10 and set the password (password is a random 8-bit string).
Generate 8-bit random number: echo $RANDOM ' OpenSSL rand-base64 8 ' | md5sum | Cut-c 1-8

Reference:

Shell Enterprise interview and Enterprise practical problem expert explaining

Enterprise Shell common face examination questions and enterprise practical cases explained in layman's

Shell Learning Example One

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.