Create Folder in Multiple Directories

Hi, I am trying to figure out how to have a folder created in multiple directories. For example /home is where we have over 1500 staff members directories, the staff members name is the name of directory under /home. I need to have a folder called "Desktop" created in every staff members directory. Any help is appreciated.

Thank You..

assuming the username does in fact match the /home directory name, try something like this:

cd /
ls -1 /home | \
while read directory ; do
      if [[ -d /home/"$directory" ]]; then
            mkdir /home/"$directory"/Desktop
            chown "$directory" /home/"$directory"/Desktop
      fi
done

When I run this it gives me this error:

test.sh: line 12: syntax error near unexpected token `done'
test.sh: line 12: `done'

Thank You..

I made a small update to Jim's code to correct that problem.

Sorry to bother you again but when I run it now I get this.

[[: not found
[[: not found
[[: not found
[[: not found
[[: not found

Thank You..

its'
#!/bin/ksh

on the very first line. It sounds like you are using csh...

Hi, I changed it ksh and I am still getting the error. This is what I have for the script..

#!/bin/ksh

cd /
ls -1 /home/staff/ | \
while read directory ; do
if [[ -d /home/staff/"$directory" ]]; then
mkdir /home/staff/"$directory"/Desktop
chown "$directory" /home/staff/"$directory"/Desktop
fi
done

Note: When I ran it on my OS X Server as a test it worked great.. But when I ran it on the actual FreeBSD machine it keeps giving this error.

[[: not found
[[: not found
[[: not found
[[: not found
[[: not found

Once again thank you for all your help.

post the output of the command:

echo $0

Okay, So it would go something like this? I am sorry if I seem novice at this. I am learning a lot here at this forum and appreciate all your guys help..

#!/bin/ksh

cd /
echo $0
ls -1 /home/staff/ | \
while read directory ; do
if [[ -d /home/staff/"$directory" ]]; then
mkdir /home/staff/"$directory"/Desktop
chown "$directory" /home/staff/"$directory"/Desktop
fi
done

no, I mean at you normal shell prompt echo $0.

Also make sure the #!/bin/ksh is the very first line. You cannot have ANYTHING, not even a blank line before that.

When I echo $0 it displays:
-zsh

ok, now:

ls -l /bin/ksh

I am having a hard time installing ksh93 on my FreeBSD server. Im sure this will work if I ever get it installed (the make install is not working). Thank You for your help, I really do appreciate it.

Do you have bash? This script should run in bash without any modifications. Or, you can run it in sh. Change the first line to #!/bin/sh and change the following line:

if [[ -d /home/staff/"$directory" ]];

to

if [ -d /home/staff/"$directory" ];

That worked great. I just want to thank everyone who helped out on this.

Thank You.