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: Seth David Schoen
Subject: Re: [Help-bash] Root access in subshell
Date: Mon, 3 Feb 2014 15:48:48 -0800
User-agent: Mutt/1.5.21 (2010-09-15)

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

-- 
Seth David Schoen <address@hidden>      |  No haiku patents
     http://www.loyalty.org/~schoen/        |  means I've no incentive to
  FD9A6AA28193A9F03D4BF4ADC11B36DC9C7DD150  |        -- Don Marti



reply via email to

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