Command to return permissions in octal format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Command to return permissions in octal format
# 1  
Old 08-22-2009
Command to return permissions in octal format

Is there any command that would return the permissions of a file or folder in octal format (e.g. 755, 644, etc.)

Thanks
# 2  
Old 08-22-2009
A quick search for octal permissions reveals your answer!

Display Permissions in Octal

-Enjoy
fh : )_~
# 3  
Old 08-23-2009
try the following:
Code:
find /directory/to/check/ filestocheck -printf '%m \n'

# 4  
Old 08-23-2009
Hi,

Thanks for the answers

@Fetus Hagen

I checked out that thread and tried this command that was mentioned:

perl -e'printf "%o\n",(stat shift)[2] & 07777' FILENAME

The problem is I get this error "-bash: fork: Resource temporarily unavailable
" no matter what the file is.

@Leppie,

I'm running Mac OS X, and the find utility doesn't have -printf as an option Smilie

EDIT: the perl command works after a restart. Weird O.o
# 5  
Old 08-23-2009
Try this, Thanks goto Jimbo, I have modded it slightly.

Code:
#!/bin/sh

ls -ld "${1:-"*"}" | awk 'BEGIN {
v["r1"]=400; v["w2"]=200; v["x3"]=100; v["s3"]=4100; v["S3"]=4000
v["r4"]=40 ; v["w5"]=20 ; v["x6"]=10 ; v["s6"]=2010; v["S6"]=2000
v["r7"]=4  ; v["w8"]=2  ; v["x9"]=1  ; v["t9"]=1001; v["T9"]=1000}
{val=0
 for (i=1;i<=9;i++) val=val+v[substr($0,i+1,1)i]
 printf "%4d %s\n",val,$NF}'

What I did...

From this:
Code:
ls -ld $* | awk 'BEGIN {

To this
Code:
ls -ld "${1:-"*"}" | awk 'BEGIN {

-Enjoy
fh : )_~

---------- Post updated at 11:13 PM ---------- Previous update was at 10:54 PM ----------

I just noticed you use bash, I do not, I tried it in bash and it appears what I did broke it under bash.

Sorry!

-Enjoy
fh : )_~
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with gstat and octal value

Here are a few lines from my script. The problem I am having is that the statement for gstat returns this error: line 43: The statement is coming from gstat. Is there a way to fix it? Apparently -eq 02 is coming up as some octal value, I need it to be recognized as 02. Apparently in... (4 Replies)
Discussion started by: newbie2010
4 Replies

2. Shell Programming and Scripting

syntax for IF test or AWK for octal

Using korn shell. I am reading a file line by line. If a record has a carriage return (octal 015) then I append the second record to the first record. Not all records have a carriage return. I have the unix shell script working with grep, but when my file has +100,000 records it runs slow. I would... (3 Replies)
Discussion started by: sboxtops
3 Replies

3. UNIX for Dummies Questions & Answers

Deleting octal values

I have some junk values in my files éad. am able to find the octal values as below by using od command. 303 251 265 266 204 211 274 261 244 241 141 144 i want to know how to delete the octal this values . (5 Replies)
Discussion started by: vino.paal
5 Replies

4. Shell Programming and Scripting

return a list of unique values of a column from csv format file

Hi all, I have a huge csv file with the following format of data, Num SNPs, 549997 Total SNPs,555352 Num Samples, 157 SNP, SampleID, Allele1, Allele2 A001,AB1,A,A A002,AB1,A,A A003,AB1,A,A ... ... ... I would like to write out a list of unique SNP (column 1). Could you... (3 Replies)
Discussion started by: phoeberunner
3 Replies

5. UNIX for Dummies Questions & Answers

ls switch to view octal permissions??

Is there seriously not an easy way to do this? you really need a script for it? that is ridiculous! Please someone tell me there is an ls switch to view octal permissions instead of rwx i want 777. (1 Reply)
Discussion started by: glev2005
1 Replies

6. Shell Programming and Scripting

[bash]printf octal instead of decimal

Hello everybody, I would like to understand why the printf function is returning me an octal value with this command : printf %4.4d 0010 returns 0008 printf %4.4d 10 returns 0010 Thanks for help. (3 Replies)
Discussion started by: dolphin06
3 Replies

7. UNIX for Dummies Questions & Answers

Display permissions in octal format

Hi, Is there any way to display the permissions in octal format rather than "rwxrwxrwx" format. I have a file and i want to see the permissions in octal format. Please help. (11 Replies)
Discussion started by: venkatesht
11 Replies

8. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

9. UNIX for Dummies Questions & Answers

need command to change permissions

I have a very simple question which I am not able to crack. There is an user with same username and groupname. How do I change permissions of a file to have the username and groupname assigned for the user "test". Appreciate you help. -Carl (1 Reply)
Discussion started by: calredd
1 Replies

10. Programming

octal and strings

hi i have a peculiar problem...i have a number of stirngs separated by a '/0'. it looks somethings like: char test="abk\0jsdhj\01234\0" actually i will be reading this from a file or something... im supposed to change the \0 to a ',' but in C the octal representation starts with a '\'...... (1 Reply)
Discussion started by: strider
1 Replies
Login or Register to Ask a Question

Featured Tech Videos