Quick way to get octal permissions of files

Status
Not open for further replies.

BiTBiTE_101

Cadet
Joined
Mar 27, 2018
Messages
2
Hey guys!

I was just wondering on the correct syntax to display octal permissions of files on FreeNAS 11.
Currently on my Ubuntu server, I use:

Code:
stat -c "%a %n" *


But it returns an error complaining about the "-c" arg.

Looking at the stat manpage:
"-c --format=FORMAT
use the specified FORMAT instead of the default; output a newline after
each use of FORMAT"

When I use the "--format" it returns:
Code:
stat: illegal option -- -


I just want something quick and dirty like my original command for Ubuntu. The reason for all this is I would love to teach the kids to access the server for themselves, but I want to restrict their access to my personal files. I already know how to do this but it's stumping me as to why I can't view the octal permissions like on my ubuntu server.

That said, I apologize for any format errors in this post; I've only ever had to inquire on forums a handful of times - usually I can just figure it out but all solutions I've found points to my initial syntax, which seems to be incorrect for FreeNAS 11.
 

wblock

Documentation Engineer
Joined
Nov 14, 2014
Messages
1,506

BiTBiTE_101

Cadet
Joined
Mar 27, 2018
Messages
2
That works great!

The only "problem" I have is, with the command in Ubuntu, when I use the "*" wildcard to list all files, it would list the names of the files, along with their octal permissions.
When using "*" with your command, all that's given is:
Code:
[bitbite@vault /mnt/vault/zeus]# stat -f "%Sp == %Mp%Lp" *	
drwx------ == 0700															 
drwx------ == 0700															 
drwx------ == 0700															 
drwxrwxrwx == 0777															 
drwxr-x--- == 0750															 
drwxr-x--- == 0750															 
drwxr-x--- == 0750															 
drwxr-x--- == 0750															 
drwxr-x--- == 0750															 
drwxr-x--- == 0750			 


Although if I specify a filename, it works correctly.
Code:
[bitbite@vault /mnt/vault/zeus]# stat -f "%Sp == %Mp%Lp" "LIVE BACKUPS"			
drwxrwxrwx == 0777


The order of the permissions listed using the command was the same as when issuing "ls" so it wasn't a big deal.
I would have loved to have the folder names listed along with the permissions like on Ubuntu, but that's just me being picky.

Thanks a ton for your help, adding this one to my notes.
 

c32767a

Patron
Joined
Dec 13, 2012
Messages
371
That works great!

The only "problem" I have is, with the command in Ubuntu, when I use the "*" wildcard to list all files, it would list the names of the files, along with their octal permissions.
When using "*" with your command, all that's given is:

How's your binary math / powers of 2? :)

0 = none
1 = execute
2 = write
4 = read

left to right, first digit is user, second is group third is world.

It shouldn't take too long to learn to translate in your head..

setuid is extra.. :)
 

wblock

Documentation Engineer
Joined
Nov 14, 2014
Messages
1,506
The only "problem" I have is, with the command in Ubuntu, when I use the "*" wildcard to list all files, it would list the names of the files, along with their octal permissions.
That can be added to the format. There is a whole section on that in the man page linked above. The format code for the filename is N. So, modifying what we had:

Code:
stat -f "%Sp == %Mp%Lp   %N" *
-rw-r--r-- == 0644   samplefile1
-rw-r--r-- == 0644   samplefile2
-rw-r--r-- == 0644   samplefile3

Probably better to use a tab there instead of spaces:
stat -f "%Sp == %Mp%Lp%t%N" *

There is a whole section of examples at the end of that man page. It's worth reading.

It shouldn't take too long to learn to translate in your head..
Dude, I didn't get a computer to not be lazy. :)
 
Status
Not open for further replies.
Top