Re: [SLUG] chmod probs.

2009-04-10 Thread Daniel Pittman
jam  writes:
> On Saturday 11 April 2009 10:00:04 slug-requ...@slug.org.au wrote:
>> > On Saturday 11 April 2009 00:06:56 slug-requ...@slug.org.au wrote:
>> > [snip]
>> >
>> > > > What am I missing?
>> > >
>> > > find(1), which is used to locate a list of files matching a given set
>> > > of criteria, allowing you to do something like this:
>> > >
>> > >   chmod -R 644 `find -name '*.jpg'`
>> > >
>> > > (Note the single-quotes around the glob pattern?  Without that the
>> > > shell would expand the pattern, which would cause a syntax error for
>> > > the find command, and not do what you want.)
>> > >
>> > > There is a limit to the number of arguments you can pass to chmod,
>> > > though, so it is generally speaking better to structure that like this:
>> > >
>> > >   find -name '*.jpg' | xargs chmod -R 644
>> > >
>> > > That falls apart if any of your filenames have spaces in them, though,
>> > > since xargs splits on *any* whitespace; to work around that use:
>> > >
>> > >   find -name '*.jpg' -print0 | xargs -0 chmod -R 644
>> > >
>> > > See the manual pages for the fine detail, obviously.
>> >
>> > Um sure, but in this context too complicated IMHO
>> > find . -type d -exec chmod 775 {} \;
>> > find . -type f -exec chmod 664 {} \;

As has already been pointed out, that is significantly less efficient
than the xargs use — or the other options like 'while read' that I also
omitted from my suggestion.

Also, now the OP knows about find(1), so that when they /do/ want to do
something more complicated they can. :)

>> need "" around the {} for filenames with spaces
>
> Is that a thought experiment ? ... cause I tried it ! exactly as
> posted

Heh.  You want to know what is special?  The behaviour of that call
without quoting is going to vary between shells, because {} expansion
isn't actually as standard as it sounds.

So, in some cases it will work, and in some the braces will just vanish
away, like the snark, and things will not work as expected...

Regards,
Daniel
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] chmod probs.

2009-04-10 Thread jam
On Saturday 11 April 2009 10:00:04 slug-requ...@slug.org.au wrote:
> > On Saturday 11 April 2009 00:06:56 slug-requ...@slug.org.au wrote:
> > [snip]
> >
> > > > What am I missing?
> > >
> > > find(1), which is used to locate a list of files matching a given set
> > > of criteria, allowing you to do something like this:
> > >
> > >   chmod -R 644 `find -name '*.jpg'`
> > >
> > > (Note the single-quotes around the glob pattern?  Without that the
> > > shell would expand the pattern, which would cause a syntax error for
> > > the find command, and not do what you want.)
> > >
> > > There is a limit to the number of arguments you can pass to chmod,
> > > though, so it is generally speaking better to structure that like this:
> > >
> > >   find -name '*.jpg' | xargs chmod -R 644
> > >
> > > That falls apart if any of your filenames have spaces in them, though,
> > > since xargs splits on *any* whitespace; to work around that use:
> > >
> > >   find -name '*.jpg' -print0 | xargs -0 chmod -R 644
> > >
> > > See the manual pages for the fine detail, obviously.
> >
> > Um sure, but in this context too complicated IMHO
> > find . -type d -exec chmod 775 {} \;
> > find . -type f -exec chmod 664 {} \;
>
> need "" around the {} for filenames with spaces

Is that a thought experiment ? ... cause I tried it ! exactly as posted

Maybe I should have posted this

[eeyore] /home/jam/slug [60]% ll
total 4
-rw-r--r-- 1 jam users0 2009-04-11 07:51 silly name
drwxr-xr-x 2 jam users 4096 2009-04-11 07:51 slug/
[eeyore] /home/jam/slug [61]% find . -type d -exec chmod 775 {} \;
[eeyore] /home/jam/slug [62]% ll
total 4
-rw-r--r-- 1 jam users0 2009-04-11 07:51 silly name
drwxrwxr-x 2 jam users 4096 2009-04-11 07:51 slug/
[eeyore] /home/jam/slug [63]% find . -type f -exec chmod 664 {} \;
[eeyore] /home/jam/slug [64]% ll
total 4
-rw-rw-r-- 1 jam users0 2009-04-11 07:51 silly name
drwxrwxr-x 2 jam users 4096 2009-04-11 07:51 slug/
[eeyore] /home/jam/slug [65]% ll slug
total 0
-rw-rw-r-- 1 jam users 0 2009-04-11 07:51 silly name
James

--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] chmod probs.

2009-04-10 Thread jam
On Saturday 11 April 2009 10:00:04 slug-requ...@slug.org.au wrote:
> > On Saturday 11 April 2009 00:06:56 slug-requ...@slug.org.au wrote:
> > [snip]
> >
> > > > What am I missing?
> > >
> > > find(1), which is used to locate a list of files matching a given set
> > > of criteria, allowing you to do something like this:
> > >
> > >   chmod -R 644 `find -name '*.jpg'`
> > >
> > > (Note the single-quotes around the glob pattern?  Without that the
> > > shell would expand the pattern, which would cause a syntax error for
> > > the find command, and not do what you want.)
> > >
> > > There is a limit to the number of arguments you can pass to chmod,
> > > though, so it is generally speaking better to structure that like this:
> > >
> > >   find -name '*.jpg' | xargs chmod -R 644
> > >
> > > That falls apart if any of your filenames have spaces in them, though,
> > > since xargs splits on *any* whitespace; to work around that use:
> > >
> > >   find -name '*.jpg' -print0 | xargs -0 chmod -R 644
> > >
> > > See the manual pages for the fine detail, obviously.
> >
> > Um sure, but in this context too complicated IMHO
> > find . -type d -exec chmod 775 {} \;
> > find . -type f -exec chmod 664 {} \;
>
> need "" around the {} for filenames with spaces

Is that a thought experiment ? ... cause I tried it ! exactly as posted
James
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] chmod probs.

2009-04-10 Thread Alex Samad
On Sat, Apr 11, 2009 at 07:57:09AM +0800, jam wrote:
> On Saturday 11 April 2009 00:06:56 slug-requ...@slug.org.au wrote:
> [snip]
> > > What am I missing?
> >
> > find(1), which is used to locate a list of files matching a given set of
> > criteria, allowing you to do something like this:
> >
> >   chmod -R 644 `find -name '*.jpg'`
> >
> > (Note the single-quotes around the glob pattern?  Without that the shell
> >  would expand the pattern, which would cause a syntax error for the find
> >  command, and not do what you want.)
> >
> > There is a limit to the number of arguments you can pass to chmod,
> > though, so it is generally speaking better to structure that like this:
> >
> >   find -name '*.jpg' | xargs chmod -R 644
> >
> > That falls apart if any of your filenames have spaces in them, though,
> > since xargs splits on *any* whitespace; to work around that use:
> >
> >   find -name '*.jpg' -print0 | xargs -0 chmod -R 644
> >
> > See the manual pages for the fine detail, obviously.
> 
> Um sure, but in this context too complicated IMHO
> find . -type d -exec chmod 775 {} \;
> find . -type f -exec chmod 664 {} \;

need "" around the {} for filenames with spaces

> 
> which does what he said he wanted to do without fussing about jpgs etc
> "I have a bunch of directories with a bunch of files (pictures) in each. 
> I want to set directories to 775 and files to 664."
> 
> James

-- 
"This very week in 1989, there were protests in East Berlin and in Leipzig. By 
the end of that year, every communist dictatorship in Central America had 
collapsed."

- George W. Bush
11/06/2003
Washington, DC


signature.asc
Description: Digital signature
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Re: [SLUG] chmod probs.

2009-04-10 Thread jam
On Saturday 11 April 2009 00:06:56 slug-requ...@slug.org.au wrote:
[snip]
> > What am I missing?
>
> find(1), which is used to locate a list of files matching a given set of
> criteria, allowing you to do something like this:
>
>   chmod -R 644 `find -name '*.jpg'`
>
> (Note the single-quotes around the glob pattern?  Without that the shell
>  would expand the pattern, which would cause a syntax error for the find
>  command, and not do what you want.)
>
> There is a limit to the number of arguments you can pass to chmod,
> though, so it is generally speaking better to structure that like this:
>
>   find -name '*.jpg' | xargs chmod -R 644
>
> That falls apart if any of your filenames have spaces in them, though,
> since xargs splits on *any* whitespace; to work around that use:
>
>   find -name '*.jpg' -print0 | xargs -0 chmod -R 644
>
> See the manual pages for the fine detail, obviously.

Um sure, but in this context too complicated IMHO
find . -type d -exec chmod 775 {} \;
find . -type f -exec chmod 664 {} \;

which does what he said he wanted to do without fussing about jpgs etc
"I have a bunch of directories with a bunch of files (pictures) in each. 
I want to set directories to 775 and files to 664."

James
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] chmod probs.

2009-04-10 Thread Alex Samad
On Fri, Apr 10, 2009 at 01:00:10PM +1000, Daniel Pittman wrote:
> Kyle  writes:
> 

[snip]

> 
> There is a limit to the number of arguments you can pass to chmod,
> though, so it is generally speaking better to structure that like this:
> 
>   find -name '*.jpg' | xargs chmod -R 644
> 
> That falls apart if any of your filenames have spaces in them, though,
> since xargs splits on *any* whitespace; to work around that use:
> 
>   find -name '*.jpg' -print0 | xargs -0 chmod -R 644
> 
> See the manual pages for the fine detail, obviously.


find \( -name '*.jpg' -a -exec chmod 644 "{}" \; \) -o \( -type d -exec
chmod 775 "{}" \; \)

but this execs for each file rather inefficient, but no worries about
command line length nor about white spaces.

One tool many paths

Alex

I intentionally left out the second -a 

> 
> Regards,
> Daniel

-- 
The major advances in civilization are processes that all but wreck the
societies in which they occur.
-- A. N. Whitehead


signature.asc
Description: Digital signature
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Re: [SLUG] chmod probs.

2009-04-09 Thread Daniel Pittman
Kyle  writes:

> I'm having a bit of grief with chmod and am hoping one of you gurus
> will set me straight pls.

You have a problem with argument globbing on Unix, not chmod, which
might explain why you are having trouble finding out what is going
wrong.

> I have a bunch of directories with a bunch of files (pictures) in
> each. I want to set directories to 775 and files to 664.
>
> I can do a chmod -R 775 *. But then if I do a chmod -R 664 *.jpg (and
> repeat for all other extensions), for some reason the chmod doesn't
> work.

Sure it does, but what actually happens is:

1. You enter 'chmod -R 644 *.jpg' into the shell.
2. The shell expands the '*.jpg' part into a list of files matching that
   pattern (implicitly in the current directory.)
3. The shell runs 'chmod -R 644 example1.jpg example2.jpg etc.jpg'
4. chmod recurses if any of the arguments are a directory, which none of
   them are because only *.jpg files were matched.

So, everything works as designed, but '-R' doesn't do quite what you
thought, and neither does the '*.jpg' argument.

Also, if you quote the glob you *still* don't get what you want, because
chmod (like almost all Unix commands) doesn't do internal globbing, it
expects external globbing, so you would get:

  ] chmod -R 644 '*.jpg'
  chmod: cannot access `*.jpg': No such file or directory

[...]

> What am I missing?

find(1), which is used to locate a list of files matching a given set of
criteria, allowing you to do something like this:

  chmod -R 644 `find -name '*.jpg'`

(Note the single-quotes around the glob pattern?  Without that the shell
 would expand the pattern, which would cause a syntax error for the find
 command, and not do what you want.)

There is a limit to the number of arguments you can pass to chmod,
though, so it is generally speaking better to structure that like this:

  find -name '*.jpg' | xargs chmod -R 644

That falls apart if any of your filenames have spaces in them, though,
since xargs splits on *any* whitespace; to work around that use:

  find -name '*.jpg' -print0 | xargs -0 chmod -R 644

See the manual pages for the fine detail, obviously.

Regards,
Daniel
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


[SLUG] chmod probs.

2009-04-09 Thread Kyle

Hi Sluggers,

I'm having a bit of grief with chmod and am hoping one of you gurus will 
set me straight pls.


I have a bunch of directories with a bunch of files (pictures) in each. 
I want to set directories to 775 and files to 664.


I can do a chmod -R 775 *. But then if I do a chmod -R 664 *.jpg (and 
repeat for all other extensions), for some reason the chmod doesn't work.


the man page says; 'chmod -R ug=rwxX *' (if I understand it correctly) 
should change just the directories permissions for owner and group. (and 
I could do an o=rxX after). But that just works on everything as well.


What am I missing?

--

Kind Regards

Kyle
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html