Need help writing a simple script to chown files

john lists.john at gmail.com
Thu Aug 2 18:13:35 BST 2007


Thanks Gavin! And thanks for the tip re: echo. This seems to work well.


> If they're all in the same directory you can probably just do:
>
> cd <directory>
> for i in *
> do
> chown $i $i
> done
>
Would you mind explaining this a bit for me? I don't know why the
variable $i takes the name of the directory, i.e why didn't $i have
some other value, like my username or the size of the directory or
whatever? Does "i" have special meaning to the shell?

Sorry to be so ignorant!

John
> If they're spread out a bit further you might need to do something more
> complex using find.
>
> TIP: Before running a script like the above for real, run it with echo in
> front of the important command, so you get to see what it actually does, ie.
>
> cd <directory>
> for i in *
> do
> echo chown $i $i
> done
>
> which will print out all of the chown commands which would be run.  If
> you're happy, do it again without the echo to actually run the commands
> instead of printing.
>
> Gavin
>
>
>
> --
> edubuntu-users mailing list
> edubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/edubuntu-users
>



More information about the edubuntu-users mailing list