Your Ad Here

Kamis, 20 September 2012

Unix Tip: METAVALUES FROM A SHELL SCRIPT

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 3512 - September 20, 2012

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


METAVALUES FROM A SHELL SCRIPT

Getting a file's size, link count or other metavalue in a shell script:

When you want to extract a specific piece of meta information about a
specific file (such as it's size, link count, or one of its time stamps)
you can use the find -printf option and any of the various
%-directives listed in the find(1) man page. Example:

size=$(find some_file -printf "%s" )

(under ksh, bash, and similar shells). Here the $() form
is used as a more readable equivalent to the older `` (back
tick) operator. (Another advantage to the $() is that it
is nestable). To get the user name of the owner of a
file "foo" you could use:

set owner = `find foo -maxdepth 0 -printf "%u"`

(here we're using the csh syntax). This also uses
the -maxdepth option in case "foo" is actually a
directory name; since we don't want find to
spend time traversing directory and printing the
owners to ALL of the entries thereunder. A
maxdepth of zero ensures that this will only print
the detail we want on the specific link that we
named on the command line.

This can be much more flexible than the options provided
by the test command (try to see which of two files is
larger, or if to files are owned by the same user or
assigned to the same group, using just test).



This tip generously supported by: jdennis@linuxcare.com



--------------------------------------------------------------------------
To Subscribe: http://www.ugu.com/sui/ugu/show?tip.subscribe
To Unsubscribe: http://www.ugu.com/sui/ugu/show?tip.unsubscribe
To Submit A Tip: http://www.ugu.com/sui/ugu/show?tip.today

==========================================================================
DISCLAIMER: All UNIX HOT TIPS ARE OWNED BY THE UNIX GURU UNIVERSE AND ARE
NOT TO BE SOLD, PRINTED OR USED WITHOUT THE WRITTEN CONSENT OF THE UNIX
GURU UNIVERSE. ALL TIPS ARE "USE AT YOUR OWN RISK". UGU ADVISES THAT
ALL TIPS BE TESTED IN A NON-PRODUCTION DEVELOPMENT ENVIRONMENT FIRST.

Unix Guru Universe - www.ugu.com - tips@ugu.com - Copyright 1994-2001
==========================================================================

Tidak ada komentar:

Posting Komentar

Your Ad Here
Free Automatic Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink