Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of DAY2 shell exercises

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you an analysis of DAY2 shell exercises. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.

Exercise 1

Write a shell script to copy all the directories under the / app/oracle/utils directory (only one level is needed) to the new directory.

#! / usr/bin/bash

Cd / app/oracle/utils

For f in `ls`; do

If [- d $f], then

Cp-r $f / tmp

Fi

Done

Summary of error points:

1 spaces before and after brackets

There is no parameter r after 2 cp. If there are files under the directory, it will indicate that it cannot be pasted.

# # omiting directory

Exercise 2

Write shell script, batch build user user_00, user_01,... User_100 and all users belong to the users group

$cat user_day2.sh

#! / bin/bash

Groupadd users

For i in `seq-f "user_g" 0100`; do

Useradd-g users $I

Done

If you don't know how to use seq-f, you can use the following:

#! / bin/bash

Groupadd users

For i in `seq 0 9`; do

Useradd-g users user_0 $I

Done

For j in `seq 10 100`; do

Useradd-g users user_$j

Done

The above is the analysis of the DAY2 shell exercises shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report