LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-03-2020, 04:50 AM   #1
Usalabs
Member
 
Registered: Jan 2004
Distribution: OpenSUSE 42.1 Server
Posts: 158

Rep: Reputation: 15
Is there something that can turn file permissions display into numeric?


OK, when I use ls -l I get the list of files and folders but also a list of permissions, unless I have a printed out table of what they mean when choosing a chmod value, I have absolutely no idea what they are, is there a command that I can use that will show the permissions in numeric form?

For Example this bash file in my user directory

-rwxr--r-- 1 usalabs usalabs 237 Aug 24 06:20 start-irc.sh

I would like it to show a number instead of all that xyz crap, that is not understandable.
 
Old 01-03-2020, 05:09 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
https://www.linuxquestions.org/quest...etters-811890/
https://askubuntu.com/questions/5509...ers-to-numbers
https://askubuntu.com/questions/1520...m-command-line

by the way, it is not crap and it is definitely understandable, probably better to learn it.

Last edited by pan64; 01-03-2020 at 05:11 AM.
 
1 members found this post helpful.
Old 01-03-2020, 03:50 PM   #3
Basslord1124
Member
 
Registered: Jun 2004
Location: KY
Distribution: Debian, Mint, Puppy
Posts: 507

Rep: Reputation: 51
r=read
w=write
x=execute

Pretty easy to understand to me.

1st space on the left is designated if it's a directory (d) or not...the rest are in groups of 3 for: owner, group, and everyone else.

So what you listed is just a file (no d for directory was indicated),
-usalabs is the owner who can read,write, and execute the file
-Next, anyone in the usalabs group can read it'
-Finally, everyone else can read it.
 
1 members found this post helpful.
Old 01-03-2020, 06:36 PM   #4
HappyTux
Senior Member
 
Registered: Mar 2003
Location: Nova Scotia, Canada
Distribution: Debian AMD64
Posts: 4,170

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by Usalabs View Post
OK, when I use ls -l I get the list of files and folders but also a list of permissions, unless I have a printed out table of what they mean when choosing a chmod value, I have absolutely no idea what they are, is there a command that I can use that will show the permissions in numeric form?

For Example this bash file in my user directory

-rwxr--r-- 1 usalabs usalabs 237 Aug 24 06:20 start-irc.sh

I would like it to show a number instead of all that xyz crap, that is not understandable.
They have the value of 4 = r, 2 = w, 1 = x so it can add up to a 7 the highest number in the numeric numbering. So in your example it is 0744 as there is nothing in front of the first r.

Code:
ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/) \
             *2^(8-i));if(k)printf("%0o ",k);print}'
Found in this third hit of a google search.


https://askubuntu.com/questions/2954...ormat-i-e-0755
https://www.google.com/search?ei=hto...4dUDCAs&uact=5

Gives you a result like this when used.

Code:
seeder1@haswell:~$ ls -l
total 12
drwx------  2 seeder1 seeder1 4096 Nov  4 22:01 bin
drwxr-xr-x 12 seeder1 seeder1 4096 Jul  9 00:44 rtorrent
drwxr-xr-x  2 root    root    4096 Dec 11 17:17 src
seeder1@haswell:~$ ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/) \
>              *2^(8-i));if(k)printf("%0o ",k);print}'
total 12
700 drwx------  2 seeder1 seeder1 4096 Nov  4 22:01 bin
755 drwxr-xr-x 12 seeder1 seeder1 4096 Jul  9 00:44 rtorrent
755 drwxr-xr-x  2 root    root    4096 Dec 11 17:17 src
 
1 members found this post helpful.
Old 01-03-2020, 07:29 PM   #5
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,326
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
This tutorial explains how both sets of permissions (numeric and alpha) work. https://www.linux.com/tutorials/unde...e-permissions/

Here's an excerpt:

Quote:
The first number represents the Owner permission; the second represents the Group permissions; and the last number represents the permissions for all other users. The numbers are a binary representation of the rwx string.

r = 4
w = 2
x = 1
 
Old 01-05-2020, 05:36 AM   #6
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
The answer is in post #2, last link therein.
I hope OP can muster the energy to click it, read it, and reply here.
 
1 members found this post helpful.
Old 01-05-2020, 04:18 PM   #7
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by HappyTux View Post
So in your example it is 0744 as there is nothing in front of the first r.
The first dash is NOT a permission mode, it means "a normal file".
The permission word represents both the (12) bits of the actual file mode (chmod can modify those) and the (4) bits of what type of entry it is: like "normal file", "directory", "symbolic link", "device special file" etc.
The 0 in your example means: there are no setuid, setgid or sticky bits and thus has nothing to do with this
Quote:
- in front of the first r
the file mode always is a set of 9 characters, even though there are 12 bits represented in it.
For instance
-rwsr-s--- means 6750 as an octal value.

Last edited by ehartman; 01-05-2020 at 04:20 PM.
 
Old 01-09-2020, 11:31 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Personally I prefer symbolic anyway - it's more intuitive as to what perms are set.

Also, you can use symbolic representations in cmds eg chmod etc, so the numeric format is superfluous for humans, although I expect the underlying C code uses the numeric form.
 
Old 01-10-2020, 04:22 AM   #9
jmgibson1981
Senior Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,141

Rep: Reputation: 392Reputation: 392Reputation: 392Reputation: 392
It took me a week or two of trying to focus it out, now all I see are octals when I look at permissions. I had a real hard time with it at first I admit. It will come. I have no clue how that is implemented but I'd guess changing it to numbers is not a simple task.
 
Old 01-10-2020, 04:26 AM   #10
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by chrism01 View Post
so the numeric format is superfluous for humans,
It is useful to set the mode to a known default:
instead of
chmod a+r,go-w,a-x <some file(s)>
(which for normal users will clear set?id and sticky bits too, for the superuser you
would need ,a-s,-t to be added to the mode string too);
just use
chmod 644 <those files>
to do all of those at once (or i.e. 755 for directories and/or executables).
 
Old 01-10-2020, 11:36 AM   #11
Soadyheid
Senior Member
 
Registered: Aug 2010
Location: Near Edinburgh, Scotland
Distribution: Cinnamon Mint 20.1 (Laptop) and 20.2 (Desktop)
Posts: 1,672

Rep: Reputation: 486Reputation: 486Reputation: 486Reputation: 486Reputation: 486
Quote:
For Example this bash file in my user directory

-rwxr--r-- 1 usalabs usalabs 237 Aug 24 06:20 start-irc.sh

I would like it to show a number instead of all that xyz crap, that is not understandable.
You know nothing John Snow! Do people with computers not know about binary or Octal numbers anymore (or am I just a wee bit tooooo old?)
As mentioned by Basslord1124 in post #3 above:
Quote:
1st space on the left is designated if it's a directory (d) or not...the rest are in groups of 3 for: owner, group, and everyone else.
I'd have named the groups, Owner, Group and World though. Each group has Read, Write and EXecute permission flags, in your case you have:

User: Read, Write and Execute or in Binary 111. Translated to Octal gives 7
Group: Read, no Write, no Execute. Binary 100. Translated to Octal gives 4
World: Read, no Write, no Execute. Binary 100. Translated to Octal gives 4

So, the number you want to show the permissions of your file is 744! Ta Da!

Play Bonny!


Last edited by Soadyheid; 01-10-2020 at 11:41 AM. Reason: Text formatting
 
Old 01-10-2020, 01:04 PM   #12
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by chrism01 View Post
although I expect the underlying C code uses the numeric form.
Yes, from the man page for chmod(2) - the system call, not the command:
Code:
The new file mode is specified in mode, which is a bit mask created by
ORing together zero or more of the following:

       S_ISUID  (04000)  set-user-ID (set process effective user ID on execve(2))

       S_ISGID  (02000)  set-group-ID (set process effective group ID on execve(2);
                         mandatory locking, as described in fcntl(2); take a new
                         file's group from parent directory, as described in
                         chown(2) and mkdir(2))

       S_ISVTX  (01000)  sticky bit (restricted deletion flag, as described in unlink(2))

       S_IRUSR  (00400)  read by owner

       S_IWUSR  (00200)  write by owner

       S_IXUSR  (00100)  execute/search by owner ("search" applies for directories,
                         and means that entries within the directory can be accessed)

       S_IRGRP  (00040)  read by group

       S_IWGRP  (00020)  write by group

       S_IXGRP  (00010)  execute/search by group

       S_IROTH  (00004)  read by others

       S_IWOTH  (00002)  write by others

       S_IXOTH  (00001)  execute/search by others
The words with (2) behind it are references to other man pages (in man section 2)

So on the programming level you specify a single value (int) of which the lower 12 bits are significant.

The chmod command translates symbolic changes into the right 12-bits mask (see man 1 chmod).
And as far as I know ls -l always shows the 9-character mode string.

Last edited by ehartman; 01-10-2020 at 01:10 PM. Reason: addition about chmod(1)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Turn a WebP Graphic File Into Something Useful in Linux LXer Syndicated Linux News 0 12-20-2015 11:22 AM
non numeric number to numeric DoME69 Programming 8 06-19-2015 07:13 AM
[SOLVED] [Solved] spamassassin error: Argument perl_version isn't numeric in numeric ge (>=) carltm CentOS 12 12-02-2014 08:23 AM
Something depends on something else but something else is to be installed javascriptninja Linux - Newbie 3 02-05-2012 04:22 PM
is there a program that can turn a short avi clip into an animated gif file baronobeefdip Linux - Software 1 12-28-2010 10:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration