Copying all of the files that are owned by the user.

Hi,

How do I copy all of the files that are owned by the user ?
i.e copy all of the files in /tmp that are owned by the user who
performs the command/

Thanks,
Tom Gur
Tom Gur [ So, 30 März 2008 12:22 ] [ ID #1932350 ]

Re: Copying all of the files that are owned by the user.

Tom Gur wrote:

> Hi,
>
> How do I copy all of the files that are owned by the user ?
> i.e copy all of the files in /tmp that are owned by the user who
> performs the command/

Assuming the user is the one returned by "whoami", then

u=`whoami`
find /tmp -user "$u" -exec cp '{}' /dest/dir \;

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
PK [ So, 30 März 2008 12:44 ] [ ID #1932351 ]

Re: Copying all of the files that are owned by the user.

On Mar 30, 11:22 am, Tom Gur <gur.... [at] gmail.com> wrote:
> Hi,
>
> How do I copy all of the files that are owned by the user ?
> i.e copy all of the files in /tmp that are owned by the user who
> performs the command/
>
> Thanks,
> Tom Gur

Hello ,
Also you can do the following

find / -name $(username) |xrags -i cp -r {} $(destination)
medomoe [ So, 30 März 2008 13:12 ] [ ID #1932353 ]

Re: Copying all of the files that are owned by the user.

On Mar 30, 2:12 pm, "medo... [at] gmail.com" <medo... [at] gmail.com> wrote:
> On Mar 30, 11:22 am, Tom Gur <gur.... [at] gmail.com> wrote:
>
> > Hi,
>
> > How do I copy all of the files that are owned by the user ?
> > i.e copy all of the files in /tmp that are owned by the user who
> > performs the command/
>
> > Thanks,
> > Tom Gur
>
> Hello ,
> Also you can do the following
>
> find / -name $(username) |xrags -i cp -r {} $(destination)

Thanks !
Tom Gur [ So, 30 März 2008 14:05 ] [ ID #1932356 ]

Re: Copying all of the files that are owned by the user.

On 2008-03-30, medomoe [at] gmail.com <medomoe [at] gmail.com> wrote:
>
>
> On Mar 30, 11:22 am, Tom Gur <gur.... [at] gmail.com> wrote:
>> Hi,
>>
>> How do I copy all of the files that are owned by the user ?
>> i.e copy all of the files in /tmp that are owned by the user who
>> performs the command/
>>
>> Thanks,
>> Tom Gur
>
> Hello ,
> Also you can do the following
>
> find / -name $(username) |xrags -i cp -r {} $(destination)

That would only return files who have the same name as the user, wouldn'it?
He wants the files owned by the user.

--
There is an art, it says, or rather, a knack to flying.
The knack lies in learning how to throw yourself at the ground and miss.
Douglas Adams
Rikishi 42 [ So, 30 März 2008 23:12 ] [ ID #1932366 ]

Re: Copying all of the files that are owned by the user.

=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

* pk <pk [at] pk.invalid> writes:

> Tom Gur wrote:
>> How do I copy all of the files that are owned by the user ?
>> i.e copy all of the files in /tmp that are owned by the user who
>> performs the command/

> Assuming the user is the one returned by "whoami", then

> u=3D`whoami`
> find /tmp -user "$u" -exec cp '{}' /dest/dir \;

Is there any point/advantage to using a variable there? I would have
simply...

find /tmp -user $(whoami) -type f -exec cp {} /dest \;

The `-type f' so you don't run into trouble if there are directories or
other special files.

=2D-
|---<Steve Youngs>---------------<GnuPG KeyID: A94B3003>---|
| SXEmacs - The only _______ you'll ever need. |
| Fill in the blank, yes, it's THAT good! |
|------------------------------------<steve [at] sxemacs.org>---|
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.8 (GNU/Linux)
Comment: The SXEmacs Project <http://www.sxemacs.org/>
Comment: EMchat - The SXEmacs IM client <http://www.emchat.org/>

iEYEARECAAYFAkfwKqIACgkQHSfbS6lLMAPHrQCguuGsiY2vcstMtOwuXK6e s9qe
9DgAoIYEXGTrcQLApy+elsP04WZcCJfJ
=3DuRGR
=2D----END PGP SIGNATURE-----
Steve Youngs [ Mo, 31 März 2008 02:04 ] [ ID #1932367 ]

Re: Copying all of the files that are owned by the user.

Steve Youngs wrote:

> Is there any point/advantage to using a variable there? I would have
> simply...
>
> find /tmp -user $(whoami) -type f -exec cp {} /dest \;
>
> The `-type f' so you don't run into trouble if there are directories or
> other special files.

Thanks, that's probably better.

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
PK [ Mo, 31 März 2008 09:50 ] [ ID #1932377 ]
Linux » comp.unix.shell » Copying all of the files that are owned by the user.

Vorheriges Thema: Re: shell script replacing original file
Nächstes Thema: echo "\000root\@test.com\000root" | base64