Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
03-30-2006, 04:16 AM
|
#1
|
Member
Registered: Dec 2005
Location: South Africa
Distribution: CentOS,Ubuntu,Fedora
Posts: 249
Rep:
|
Script to create multiple directories under users homes
Good Day
I am having a bit of a problem with a script ( in other words,all attempts have failed :-) )
I am looking to create 3 new directories under everybodies home directory like this.
/home/user - tmp
- docs
- pdf
/home/user2 - tmp
- docs
- pdf
I have about a thousand users to do this to,and I dont want to manually add all these directories.Can somebody tell me how I could do this via a script
Cheers
Shawn
|
|
|
03-30-2006, 05:10 AM
|
#2
|
Senior Member
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802
Rep:
|
WARNING: I did this on cygwin so it might need a little tweeking.
Code:
#!/bin/bash
cd /home
for i in *;do
USER=`grep $i /etc/passwd|cut -d: -f3,4`
cd $i
mkdir tmp doc pdf
chown $USER tmp doc pdf
cd ../
done
|
|
|
03-30-2006, 05:22 AM
|
#3
|
Member
Registered: Dec 2005
Location: South Africa
Distribution: CentOS,Ubuntu,Fedora
Posts: 249
Original Poster
Rep:
|
hi /bin/bash
Great thank you that work fantastically...
Cheers
|
|
|
03-30-2006, 05:47 AM
|
#4
|
Senior Member
Registered: Oct 2003
Posts: 3,057
Rep:
|
This also seems to work on my FC5 box.
Code:
#!/bin/bash
for i in $(cat /etc/passwd | grep /home |cut -d: -f6); do
mkdir $i/{tmp,doc,pdf}
done
|
|
|
03-30-2006, 08:11 AM
|
#5
|
Senior Member
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802
Rep:
|
You're welcome, HTH.
|
|
|
All times are GMT -5. The time now is 11:03 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|