PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Pls with this 'find' command line
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Pls with this 'find' command line

Réponse
 
LinkBack Outils de la discussion
Vieux 28/12/2007, 16h39   #1
larryalk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Pls with this 'find' command line

I somehow messed up ( as root - my bad ) an important directory
and made many subdirectories _not_ executable.

I wish to change these directories to executable by user so I can
enter them.

I've worked out the following find command line.
Will it work to do what I want?

find . -type d -execdir chmod u+x '{}' \;

Questions:
1. Is there an easy way to test this before I run it on the important
directory? I can't see any way to test when running chmod.

2. Is there a way to first test whether the directory is not
chmod u+x
and only then mess with the directories?

3. Is -execdir necessary here or could I use -exec?

Thank you.
Larry
--
My real sig is much better.
  Réponse avec citation
Vieux 28/12/2007, 17h17   #2
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Pls with this 'find' command line

On Fri, 28 Dec 2007 10:39:19 -0600, larryalk wrote:

> I somehow messed up ( as root - my bad ) an important directory and made
> many subdirectories _not_ executable.
>
> I wish to change these directories to executable by user so I can enter
> them.
>
> I've worked out the following find command line. Will it work to do what
> I want?
>
> find . -type d -execdir chmod u+x '{}' \;
>
> Questions:
> 1. Is there an easy way to test this before I run it on the important
> directory? I can't see any way to test when running chmod.


Make a test set of directories somewhere (/tmp if you can not think of
anywhere else), with various permissions, then run the command and see if
they have changed.

> 2. Is there a way to first test whether the directory is not chmod u+x
> and only then mess with the directories?


Yes. Essentially you want to have a shell script to do the work. This can
either be inserted inline by using a construct such as
find .... -exec sh -c "do something or other" '{}' '{}' ';'
or putting the script in say ~/FIXUP and running
find .... -exec ~/FIXUP '{}' ';'
However you almost certainly don't need to do this. "chmod u+x" will
probably not change a directory if it already has 'x' permission for
'user'.

> 3. Is -execdir necessary here or could I use -exec?


You can use '-exec' here, which is more standard.

> Thank you.
> Larry


  Réponse avec citation
Vieux 28/12/2007, 19h01   #3
James Michael Fultz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Pls with this 'find' command line

* larryalk <nobody@nowhere.com>:
> I somehow messed up ( as root - my bad ) an important directory
> and made many subdirectories _not_ executable.
>
> I wish to change these directories to executable by user so I can
> enter them.
>
> I've worked out the following find command line.
> Will it work to do what I want?
>
> find . -type d -execdir chmod u+x '{}' \;
>
> Questions:
> 1. Is there an easy way to test this before I run it on the important
> directory? I can't see any way to test when running chmod.


Use the '-print' command in place of '-execdir ...' to see what
directories would be acted upon.

> 2. Is there a way to first test whether the directory is not
> chmod u+x
> and only then mess with the directories?


See find's '-perm' option, for instance:

find . -type d ! -perm -100 -execdir chmod u+x {} \;

> 3. Is -execdir necessary here or could I use -exec?


It is not necessary but is considered a more secure alternative to '-exec'.
On the other hand, '-exec' is more portable than '-execdir'.

--
James Michael Fultz <xyzzy@sent.as.invalid>
Remove this part when replying ^^^^^^^^
  Réponse avec citation
Vieux 31/12/2007, 06h56   #4
Kiri
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Pls with this 'find' command line

On Dec 28, 6:39 pm, larryalk <nob...@nowhere.com> wrote:
> I somehow messed up ( as root - my bad ) an important directory
> and made many subdirectories _not_ executable.
>
> I wish to change these directories to executable by user so I can
> enter them.
>
> I've worked out the following find command line.
> Will it work to do what I want?
>
> find . -type d -execdir chmod u+x '{}' \;


That should do it.

>
> Questions:
> 1. Is there an easy way to test this before I run it on the important
> directory? I can't see any way to test when running chmod.


Yes, create a test directory tree like below:

cd /tmp
mkdir test
mkdir -p test/1/2/3
mkdir -p test/1/5/7/3
mkdir -p test/1/a/b/2/3

# do a normal ls and see the directory permissions
# then do something like:

find . -type d -execdir chmod 770 '{}' \;

# If you check permissions on all those directories we created you
will see something like:

$ ls -al
total 6
drwxrwx--- 3 user user 72 Dec 31 08:27 .
drwx------ 63 user user 6224 Dec 31 08:31 ..
drwxrwx--- 4 user user 96 Dec 31 08:27 1

# do check the other subdirectories as well.

# Then try to change permissions as follows:

find . -type d -execdir chmod 755 '{}' \;

# ...checking the permissions again, you will see something like:

$ ls -al
total 6
drwxr-xr-x 3 user user 72 Dec 31 08:27 .
drwx------ 63 user user 6224 Dec 31 08:31 ..
drwxr-xr-x 4 user user 96 Dec 31 08:27 1

>
> 2. Is there a way to first test whether the directory is not
> chmod u+x
> and only then mess with the directories?


Yes, you might need to write a shell script here.

>
> 3. Is -execdir necessary here or could I use -exec?


There are security concerns with using -exec. Check the manual pages,
but I guess you can use both.
  Réponse avec citation
Vieux 31/12/2007, 13h24   #5
Sven Mascheck
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Pls with this 'find' command line

larryalk <nobody> wrote:
> [...] made many subdirectories _not_ executable.
> [...]
> find . -type d -execdir chmod u+x '{}' \;


Interestingly, chmod implements something similar
with the capital X flag,

chmod -R u+X .
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 09h14.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16706 seconds with 13 queries