Getting the mode of a file in number format

Getting the mode of a file in number format

Post by Don Wol » Sat, 02 Apr 1994 00:06:48



Does anyone out there know of a UNIX command that will
return the mode of a file in number format (i.e. 644, 755, etc.)?


 AT&T Global Information Solutions                             (513) 445-4739
 Professional Services Division, Data Services             VOICEplus 622-4739
 1700 S. Patterson Blvd          PCD-3                     Dayton, Ohio 45479

 
 
 

Getting the mode of a file in number format

Post by Tom Park » Sat, 02 Apr 1994 03:41:12



>Does anyone out there know of a UNIX command that will
>return the mode of a file in number format (i.e. 644, 755, etc.)?

This was answered recently, I believe in this newsgroup:

    perl -e 'printf "%04o\n", (stat(shift))[2] & 07777' <the.file>

-- Tom
--
+--------------------------------------------------------------------+
| Tom Parker             |  National Center for Atmospheric Research |

+--------------------------------------------------------------------+

 
 
 

1. Getting the mode of a file in number format

Don> Does anyone out there know of a UNIX command that will
Don> return the mode of a file in number format (i.e. 644, 755, etc.)?

This is turning into a FAQ.

$ perl -e 'printf "%o\n", 07777 & (stat(shift))[2]' /etc/passwd
644
$

print "Just another Perl hacker,"

--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying

Phrase: "Welcome to Portland, Oregon ... home of the California Raisins!"

2. intel chipset

3. OpenLinux 1.3 Installation Problems

4. Setting Up Linux Diskless Workstations

5. Is there a UNIX command that will give mode of a file in number format?

6. ppp question

7. Format numbers to time format using SED

8. gdb: core file not in executable format: File format not recognized

9. Convert vc file format to Lotus 1-2-3 file format?

10. magic file number for PICTURE formats

11. Mode gets screwed up going back to text mode