Need help writing a simple script to chown files

Jim Kronebusch jim at winonacotter.org
Fri Aug 3 14:36:35 BST 2007


> > > for i in *
> > > do
> > > chown $i $i
> > > done
> 
> The bash shell evaulates the * as the files and directories in the current
> working directory.  So if you do 
> 	echo *
> you'll get back a plain list of files and directories.  This is much like
> running "ls" in the directory, but in one case /bin/ls answers and in the
> other bash answers (echo is actually a bash built-in).
> 
> So, in the above, we loop over each file or directory, with $i getting the
> name.  If each time you do 
> 	chroot $i $i
> 
> Then you're setting ownership of every file to the user of the same name
> (assuming that user exists).
> 
> For more details on how these bash and other shells work, you can have a
> look at this
> 	http://www.linux.ie/newusers/beginners-linux-guide/shells.php
> it's not perfect, but it's mostly correct now that I look back at it.

Great explanation Gavin.  Very simple script.  I will most likely use it in the future.

Thanks for the link to the tutorial as well.  I will be certain to read it.

-- 
This message has been scanned for viruses and
dangerous content by the Cotter Technology 
Department, and is believed to be clean.




More information about the edubuntu-users mailing list