- Two questions: find files with specific permission, find files that belong to..

- Two questions: find files with specific permission, find files that belong to..

Post by wigg » Fri, 11 Jun 2004 04:42:24



Hi!
I need this pair of scipt in bash, are you able to help me?
1) Find all the files with a specific permission (for example 0644) into a
directory tree.
2) Find all the files that belong to the user who execute the bash-scipt.
(note that the script is executed from a program wrote in C, a kind of
shell..)

Excuse me for my bad english.
Tank you very much.
wigga

 
 
 

- Two questions: find files with specific permission, find files that belong to..

Post by Alan Conno » Fri, 11 Jun 2004 05:34:26



> Hi!
> I need this pair of scipt in bash, are you able to help me?
> 1) Find all the files with a specific permission (for example 0644) into a
> directory tree.
> 2) Find all the files that belong to the user who execute the bash-scipt.
> (note that the script is executed from a program wrote in C, a kind of
> shell..)

Hello, Wigga. How are things in Italy these days? I thought that
was GREAT when 10's of thousands of you protested George Bush's
visit. Don't let the lying American imperialists bring the vengeful
wrath of their Moslem victims down on you.

(your Engish is a lot better than my Italian)

--------------------------

Homework, is it? :-)

This sort of question gets asked all the time here.

Do these two things and get back to us, okay?

1) Take a close look at man find.

2) Look over the comp.unix.shell FAQ

http://home.comcast.net/~j.p.h/


If you don't have any idea how to do what you want above, then you
have not been doing your homework, or have been skipping class or
sleeping through it, or need to find another teacher in a hurry.

AC

--
Pass-List -----> Block-List ----> Challenge-Response
The key to taking control of your mailbox.  Design Parameters:
http://tinyurl.com/2t5kp ||   http://tinyurl.com/3c3ag
Challenge-Response links -- http://tinyurl.com/yrfjb

 
 
 

- Two questions: find files with specific permission, find files that belong to..

Post by Scott McMilla » Fri, 11 Jun 2004 05:38:55



>Hi!
>I need this pair of scipt in bash, are you able to help me?
>1) Find all the files with a specific permission (for example 0644) into a
>directory tree.

cd /to/the/appropriate/directory
find ./ -type f -perm 644

Quote:>2) Find all the files that belong to the user who execute the bash-scipt.
>(note that the script is executed from a program wrote in C, a kind of
>shell..)

me=`who am i | cut -d" " -f1`
find ./ -type f -user $me

Quote:>Excuse me for my bad english.
>Tank you very much.
>wigga

Scott McMillan
 
 
 

- Two questions: find files with specific permission, find files that belong to..

Post by Chris F.A. Johnso » Fri, 11 Jun 2004 13:54:11



> Hi!
> I need this pair of scipt in bash, are you able to help me?
> 1) Find all the files with a specific permission (for example 0644) into a
> directory tree.

find /path/to/directory -perm 0644 -print

    (You will probably not need -print.)

Quote:> 2) Find all the files that belong to the user who execute the bash-scipt.
> (note that the script is executed from a program wrote in C, a kind of
> shell..)

find /path/to/directory -user $USER -print

    You may have to set the USER variable first, as some systems don't
    set it, Some use LOGNAME instead. If neither is set, use:

USER=`whoami`

    Or:

set `who am i`
case $1 in
   *\!*) oldIFS=$IFS
         IFS=${IFS}\!
         set $1
         shift
         IFS=$oldIFS
         ;;
esac
USER=$1

Quote:> Excuse me for my bad english.

    No need to apologize; I've read posts by native English speakers
    that are worse. :(

--
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

- Two questions: find files with specific permission, find files that belong to..

Post by --==[bman]==- » Sun, 20 Jun 2004 13:51:51


Hi Chris,

I posed in-line comments....



>>Hi!
>>I need this pair of scipt in bash, are you able to help me?
>>1) Find all the files with a specific permission (for example 0644) into a
>>directory tree.

> find /path/to/directory -perm 0644 -print

>     (You will probably not need -print.)

>>2) Find all the files that belong to the user who execute the bash-scipt.
>>(note that the script is executed from a program wrote in C, a kind of
>>shell..)

> find /path/to/directory -user $USER -print

>     You may have to set the USER variable first, as some systems don't
>     set it, Some use LOGNAME instead. If neither is set, use:

> USER=`whoami`

>     Or:

> set `who am i`
> case $1 in
>    *\!*) oldIFS=$IFS
>          IFS=${IFS}\!
>          set $1
>          shift
>          IFS=$oldIFS
>          ;;
> esac
> USER=$1

Why would you use this convoluted code to get user id when it can be
done simply like so:

user=$(who am i); user=${user%% *}

Looks much cleaner and you do not have to play with IFS, case, set, and
shift....

Quote:

>>Excuse me for my bad english.

>     No need to apologize; I've read posts by native English speakers
>     that are worse. :(

--

     __    _
    / /   (_)___  __  ___  __
   / /   / / __ \/ / / / |/_/
  / /___/ / / / / /_/ />  <
/_____/_/_/ /_/\__,_/_/|_| is what you make of it.

 
 
 

- Two questions: find files with specific permission, find files that belong to..

Post by Chris F.A. Johnso » Sun, 20 Jun 2004 14:02:45



> Hi Chris,

> I posed in-line comments....



>>>Hi!
>>>I need this pair of scipt in bash, are you able to help me?
>>>1) Find all the files with a specific permission (for example 0644) into a
>>>directory tree.

>> find /path/to/directory -perm 0644 -print

>>     (You will probably not need -print.)

>>>2) Find all the files that belong to the user who execute the bash-scipt.
>>>(note that the script is executed from a program wrote in C, a kind of
>>>shell..)

>> find /path/to/directory -user $USER -print

>>     You may have to set the USER variable first, as some systems don't
>>     set it, Some use LOGNAME instead. If neither is set, use:

>> USER=`whoami`

>>     Or:

>> set `who am i`
>> case $1 in
>>    *\!*) oldIFS=$IFS
>>          IFS=${IFS}\!
>>          set $1
>>          shift
>>          IFS=$oldIFS
>>          ;;
>> esac
>> USER=$1

> Why would you use this convoluted code to get user id when it can be
> done simply like so:

> user=$(who am i); user=${user%% *}

> Looks much cleaner and you do not have to play with IFS, case, set, and
> shift....

     But it doesn't work on all systems (e.g. SunOS 4.1):

$ user=$(who am i); user=${user%% *}
$ echo $user
bloor!chris

--
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

- Two questions: find files with specific permission, find files that belong to..

Post by --==[bman]==- » Sun, 20 Jun 2004 23:20:36


I guess, you are using BOURNE.  Yack! :-)  HPUX and Linux do not use
BORNE as their default shell.  HPUX uses Korn and Linux uses Bash.  SUN
seems to be a "little" behind times...



>>Hi Chris,

>>I posed in-line comments....



>>>>Hi!
>>>>I need this pair of scipt in bash, are you able to help me?
>>>>1) Find all the files with a specific permission (for example 0644) into a
>>>>directory tree.

>>>find /path/to/directory -perm 0644 -print

>>>    (You will probably not need -print.)

>>>>2) Find all the files that belong to the user who execute the bash-scipt.
>>>>(note that the script is executed from a program wrote in C, a kind of
>>>>shell..)

>>>find /path/to/directory -user $USER -print

>>>    You may have to set the USER variable first, as some systems don't
>>>    set it, Some use LOGNAME instead. If neither is set, use:

>>>USER=`whoami`

>>>    Or:

>>>set `who am i`
>>>case $1 in
>>>   *\!*) oldIFS=$IFS
>>>         IFS=${IFS}\!
>>>         set $1
>>>         shift
>>>         IFS=$oldIFS
>>>         ;;
>>>esac
>>>USER=$1

>>Why would you use this convoluted code to get user id when it can be
>>done simply like so:

>>user=$(who am i); user=${user%% *}

>>Looks much cleaner and you do not have to play with IFS, case, set, and
>>shift....

>      But it doesn't work on all systems (e.g. SunOS 4.1):

> $ user=$(who am i); user=${user%% *}
> $ echo $user
> bloor!chris

--

     __    _
    / /   (_)___  __  ___  __
   / /   / / __ \/ / / / |/_/
  / /___/ / / / / /_/ />  <
/_____/_/_/ /_/\__,_/_/|_| is what you make of it.

 
 
 

- Two questions: find files with specific permission, find files that belong to..

Post by Chris F.A. Johnso » Mon, 21 Jun 2004 10:14:14





>>>Hi Chris,

>>>I posed in-line comments....



>>>>>I need this pair of scipt in bash, are you able to help me?
>>>>>1) Find all the files with a specific permission (for example 0644) into a
>>>>>directory tree.

>>>>find /path/to/directory -perm 0644 -print

>>>>    (You will probably not need -print.)

>>>>>2) Find all the files that belong to the user who execute the bash-scipt.
>>>>>(note that the script is executed from a program wrote in C, a kind of
>>>>>shell..)

>>>>find /path/to/directory -user $USER -print

>>>>    You may have to set the USER variable first, as some systems don't
>>>>    set it, Some use LOGNAME instead. If neither is set, use:

>>>>USER=`whoami`

>>>>    Or:

>>>>set `who am i`
>>>>case $1 in
>>>>   *\!*) oldIFS=$IFS
>>>>         IFS=${IFS}\!
>>>>         set $1
>>>>         shift
>>>>         IFS=$oldIFS
>>>>         ;;
>>>>esac
>>>>USER=$1

>>>Why would you use this convoluted code to get user id when it can be
>>>done simply like so:

>>>user=$(who am i); user=${user%% *}

>>>Looks much cleaner and you do not have to play with IFS, case, set, and
>>>shift....

>>      But it doesn't work on all systems (e.g. SunOS 4.1):

>> $ user=$(who am i); user=${user%% *}
>> $ echo $user
>> bloor!chris

[please don't top post]

Quote:> I guess, you are using BOURNE.  Yack! :-)

     No, I was using bash; it's not the shell that determines the
     whether the extra step is necessary, it's the "who am i" command.

     The solution I posted works in all Bourne-type shells; in a POSIX
     form it would be:

user=$(who am i)
user=${user%% *}
user=${user#*!}

Quote:>  HPUX and Linux do not use
> BORNE as their default shell.  HPUX uses Korn and Linux uses Bash.  SUN
> seems to be a "little" behind times...

     SunOS 4.1 is about 10 years old, but it works, and there's no
     reason to upgrade that machine.

--
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License