home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!haven.umd.edu!news.umbc.edu!math13.math.umbc.edu!rouben
- From: rouben@math13.math.umbc.edu (Rouben Rostamian)
- Newsgroups: comp.unix.shell
- Subject: Re: Help with directories!
- Message-ID: <1992Aug26.145029.19492@umbc3.umbc.edu>
- Date: 26 Aug 92 14:50:29 GMT
- References: <1992Aug24.175614.15627@netnews.synoptics.com> <1992Aug26.031742.12476@aplcen.apl.jhu.edu>
- Sender: newspost@umbc3.umbc.edu (News posting account)
- Organization: University of Maryland Baltimore Campus
- Lines: 43
-
- In article <1992Aug26.031742.12476@aplcen.apl.jhu.edu> bandy@aplcen.apl.jhu.edu (Mike Bandy) writes:
- >>ericd@synoptics.com (Eric Davis) writes:
- >>
- >>I am looking for a sh routine to return a numerical value for a
- >>file/directory. i.e. the files permissions are -rwxr-xr-x it would
- >>return a 755.
- >>
- >>P.S. If there is a way to do it with an existing utility, please let me know.
-
- >I've just read 18 messages regarding this question. And not one of them
- >told us the answer (to which I'm curious or I wouldn't have wasted your
- >precious time with this message)... Give us a break, and the answer to the
- >question, and let's get on with our lives ...
-
- I agree. Cut the religious arguments and offer solutions. Here's how
- you do it in awk:
-
- Create a file called convert.awk, containing:
-
- { for (i=2; i<=10; i++) {
- n = 2*n
- if ( substr($0,i,1) != "-" )
- n++;
- }
- printf ("%o\n", n)
- }
-
- Then the apply the command:
- echo -rwxr-xr-x | awk -f convert.awk
- to get 755.
-
- If you have nawk, you can write the script a bit more elegantly as:
-
- { for (i=2; i<=10; i++)
- n = 2*n + ( substr($0,i,1) != "-" ? 1 : 0 )
- printf ("%o\n", n)
- }
-
- Usage remains the same. Handling suid bits, etc., is left as excercise.
- That's all, folks!
-
- --
- Rouben Rostamian
-