zsh-users
 help / color / mirror / code / Atom feed
* How to find owner of file or folder?
@ 2012-02-27 16:55 TJ Luoma
  2012-02-27 17:31 ` Dan Nelson
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: TJ Luoma @ 2012-02-27 16:55 UTC (permalink / raw)
  To: zsh-users

This is the only way that I know of to get the username who owns a
certain file or folder, such as /usr/local/

          command ls -ld /usr/local | awk '{print $3}'

(or `ls -dn` if you want the number instead of the name)

but that seems fairly inelegant.

Is there a better way?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to find owner of file or folder?
  2012-02-27 16:55 How to find owner of file or folder? TJ Luoma
@ 2012-02-27 17:31 ` Dan Nelson
  2012-02-27 18:30   ` TJ Luoma
  2012-02-27 17:35 ` Danek Duvall
  2012-02-27 17:37 ` Peter Stephenson
  2 siblings, 1 reply; 8+ messages in thread
From: Dan Nelson @ 2012-02-27 17:31 UTC (permalink / raw)
  To: TJ Luoma; +Cc: zsh-users

In the last episode (Feb 27), TJ Luoma said:
> This is the only way that I know of to get the username who owns a
> certain file or folder, such as /usr/local/
> 
>           command ls -ld /usr/local | awk '{print $3}'
> 
> (or `ls -dn` if you want the number instead of the name)
> 
> but that seems fairly inelegant.
> 
> Is there a better way?

$ zmodload zsh/stat
$ zstat -H fileinfo /usr/local
$ echo $fileinfo[uid]
0
$ ls -ld /usr/local
drwxr-xr-x  42 root  wheel  42 Feb 19 17:05 /usr/local/
$ typeset fileinfo
fileinfo=(atime 1313171206 blksize 4096 blocks 5 ctime 1329692755 device
 4201426224 gid 0 inode 3366 link '' mode 16877 mtime 1329692755 nlink 42
 rdev 4294967295 size 42 uid 0 )

-- 
	Dan Nelson
	dnelson@allantgroup.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to find owner of file or folder?
  2012-02-27 16:55 How to find owner of file or folder? TJ Luoma
  2012-02-27 17:31 ` Dan Nelson
@ 2012-02-27 17:35 ` Danek Duvall
  2012-02-27 17:37 ` Peter Stephenson
  2 siblings, 0 replies; 8+ messages in thread
From: Danek Duvall @ 2012-02-27 17:35 UTC (permalink / raw)
  To: TJ Luoma; +Cc: zsh-users

On Mon, Feb 27, 2012 at 11:55:14AM -0500, TJ Luoma wrote:

> This is the only way that I know of to get the username who owns a
> certain file or folder, such as /usr/local/
> 
>           command ls -ld /usr/local | awk '{print $3}'
> 
> (or `ls -dn` if you want the number instead of the name)
> 
> but that seems fairly inelegant.
> 
> Is there a better way?

The stat builtin, from the zsh/stat module (see zshmodules(1).  Or the
similar utility of the same name, part of GNU coreutils.

Danek


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to find owner of file or folder?
  2012-02-27 16:55 How to find owner of file or folder? TJ Luoma
  2012-02-27 17:31 ` Dan Nelson
  2012-02-27 17:35 ` Danek Duvall
@ 2012-02-27 17:37 ` Peter Stephenson
  2012-02-27 18:18   ` TJ Luoma
  2 siblings, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 2012-02-27 17:37 UTC (permalink / raw)
  To: zsh-users

On Mon, 27 Feb 2012 11:55:14 -0500
TJ Luoma <luomat@gmail.com> wrote:
> This is the only way that I know of to get the username who owns a
> certain file or folder, such as /usr/local/
> 
>           command ls -ld /usr/local | awk '{print $3}'
> 
> (or `ls -dn` if you want the number instead of the name)
> 
> but that seems fairly inelegant.
> 
> Is there a better way?

% zmodload -F zsh/stat b:zstat
% zstat -s +uid /usr/local/bin/zsh
root

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to find owner of file or folder?
  2012-02-27 17:37 ` Peter Stephenson
@ 2012-02-27 18:18   ` TJ Luoma
  0 siblings, 0 replies; 8+ messages in thread
From: TJ Luoma @ 2012-02-27 18:18 UTC (permalink / raw)
  To: zsh-users

Excellent! I knew there had to be a better way. Thanks, Peter.

Here's a little script I wrote up which will show the owner if just
one argument is given, or will shown the owner and filename if more
than one argument is given:

#!/bin/zsh

zmodload -F zsh/stat b:zstat

# if there's just one argument given, show the owner and exit
if [ "$#" = "1" ]
then
		zstat -s +uid "$@"
		exit
fi		

# otherwise, loop through and shown the owner for each file which exists
for F in $@
do

	[[ -e "$F" ]] || continue

	echo -n "$F: "
	zstat -s +uid "$F"

done


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to find owner of file or folder?
  2012-02-27 17:31 ` Dan Nelson
@ 2012-02-27 18:30   ` TJ Luoma
  2012-02-27 18:38     ` Dan Nelson
  0 siblings, 1 reply; 8+ messages in thread
From: TJ Luoma @ 2012-02-27 18:30 UTC (permalink / raw)
  To: Dan Nelson; +Cc: zsh-users

On Mon, Feb 27, 2012 at 12:31 PM, Dan Nelson <dnelson@allantgroup.com> wrote:
> $ zmodload zsh/stat
> $ zstat -H fileinfo /usr/local
> $ echo $fileinfo[uid]
> 0
> $ ls -ld /usr/local
> drwxr-xr-x  42 root  wheel  42 Feb 19 17:05 /usr/local/
> $ typeset fileinfo
> fileinfo=(atime 1313171206 blksize 4096 blocks 5 ctime 1329692755 device
>  4201426224 gid 0 inode 3366 link '' mode 16877 mtime 1329692755 nlink 42
>  rdev 4294967295 size 42 uid 0 )

Oh cool… I didn't know about $fileinfo either… I actually thought
about doing something along the same lines.

THERE IS SO MUCH ABOUT ZSH I DON'T KNOW! And I've been using it since
1990-something (1995? I think)

Thanks again, and also to Danek Duvall.

TjL


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to find owner of file or folder?
  2012-02-27 18:30   ` TJ Luoma
@ 2012-02-27 18:38     ` Dan Nelson
  2012-02-27 19:55       ` TJ Luoma
  0 siblings, 1 reply; 8+ messages in thread
From: Dan Nelson @ 2012-02-27 18:38 UTC (permalink / raw)
  To: TJ Luoma; +Cc: zsh-users

In the last episode (Feb 27), TJ Luoma said:
> On Mon, Feb 27, 2012 at 12:31 PM, Dan Nelson <dnelson@allantgroup.com> wrote:
> > $ zmodload zsh/stat
> > $ zstat -H fileinfo /usr/local
> > $ echo $fileinfo[uid]
> > 0
> > $ ls -ld /usr/local
> > drwxr-xr-x  42 root  wheel  42 Feb 19 17:05 /usr/local/
> > $ typeset fileinfo
> > fileinfo=(atime 1313171206 blksize 4096 blocks 5 ctime 1329692755 device
> >  4201426224 gid 0 inode 3366 link '' mode 16877 mtime 1329692755 nlink 42
> >  rdev 4294967295 size 42 uid 0 )
> 
> Oh cool... I didn't know about $fileinfo either... I actually thought
> about doing something along the same lines.

Note that "fileinfo" is just an arbitrary variable name I picked.  See the
zshmodules manpage for more info.

-- 
	Dan Nelson
	dnelson@allantgroup.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to find owner of file or folder?
  2012-02-27 18:38     ` Dan Nelson
@ 2012-02-27 19:55       ` TJ Luoma
  0 siblings, 0 replies; 8+ messages in thread
From: TJ Luoma @ 2012-02-27 19:55 UTC (permalink / raw)
  To: Dan Nelson; +Cc: zsh-users

On Mon, Feb 27, 2012 at 1:38 PM, Dan Nelson <dnelson@allantgroup.com> wrote:
> Note that "fileinfo" is just an arbitrary variable name I picked.  See the
> zshmodules manpage for more info.

Ah, I hadn't looked closely enough. Thanks for the clarification!

TjL


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-02-27 19:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-27 16:55 How to find owner of file or folder? TJ Luoma
2012-02-27 17:31 ` Dan Nelson
2012-02-27 18:30   ` TJ Luoma
2012-02-27 18:38     ` Dan Nelson
2012-02-27 19:55       ` TJ Luoma
2012-02-27 17:35 ` Danek Duvall
2012-02-27 17:37 ` Peter Stephenson
2012-02-27 18:18   ` TJ Luoma

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).