[talk] Recursive chmod problem

ori at eigenstate.org ori at eigenstate.org
Thu Dec 2 22:18:05 EST 2021


Quoth Jonathan Drews <jondrews at fastmail.com>:
> On Thu, Dec 02, 2021 at 09:49:38PM -0500, ori at eigenstate.org wrote:
> > > $ chmod -R 660 *.pdf
> > > 
> > > does not change entries in directories.
> > 
> > of course; think about what globs expand to. Do you have
> > any directories named 'dir.pdf'? if not, how would they
> > show up in the glob?
> > 
> > 	echo chmod -R 660 *pdf
> > 
> > will let you see the expanded command.
> > 
> 
> Interesting! I am following the instructions in a book called "The
> Linux Phrasebook" and the author shows that:
> 
> $ chmod -R 660 *.jpg
> 
> will only affect images (*.jpg) and not directories. Maybe he is
> wrong?

I'm confused. Why do you think that he's
wrong?

The shell expands the list of filenames.
The programs never see the globs.

Unless you happen to name your directory
'mydir.jpg', the expansion of the glob
never contains a directory, so it never
gets passed to the program.

It's that simple.

	myprogram *.jpg

is the same as typing out a list of every
jpg in the current directory:

	myprogram a.jpg b.jpg c.jpg ...

there's precisely zero difference.




More information about the talk mailing list