help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Root access in subshell


From: Richard Taubo
Subject: Re: [Help-bash] Root access in subshell
Date: Tue, 4 Feb 2014 00:59:38 +0100

On Feb 4, 2014, at 12:48 AM, Seth David Schoen <address@hidden> wrote:

> Richard Taubo writes:
> 
>> I was actually trying to do the following (using $ as the prompt):
>> $ OldIFS=$IFS; IFS=$'\n'; \
>> for i in $(cat /etc/passwd); do \
>> split_word=":"; my_user="${i%%$split_word*}";\
>> if [[ "$my_user" != "root" && "$my_user" != “bin" ]]; then \
>> printf "%s\n" "------- Finding files by user: $my_user";\
>> find / -user $my_user -not -path "/proc/*" -print -quit;\
>> fi;\
>> done;\
>> IFS=$OldIFS;
> 
> If you're up for using external Unix commands instead of shell
> builtins, you can make this a bit more concise:
> 
> egrep -v '^(root|bin):' /etc/passwd | cut -d: -f1 | while read i; do
> printf "%s\n" "------- Finding files by user: $i"
> find / -user "$i" -not -path "/proc/*" -print -quit
> fi
> 
> You could also save one byte (and one subprocess) by using awk:
> 
> awk -F: '!/^(root|bin):/ {print $1}' /etc/passwd

Thanks, those are good alternatives!

Best regards,
Richard Taubo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]