Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chmod calculator #197

Closed
kleo opened this issue May 15, 2020 · 8 comments
Closed

chmod calculator #197

kleo opened this issue May 15, 2020 · 8 comments

Comments

@kleo
Copy link

kleo commented May 15, 2020

I would love to have a chmod calculator feature added to cheat.sh.

Something I have in mind:

curl cheat.sh/chmod/644

or

curl cheat.sh/chmod/-rw-r--r--

chmod u=rw,go=r / 644 / rw-r--r--

Linux Permissions:

Owner           Group           Public

Read    [X]     Read    [X]     Read    [X]
Write   [X]     Write   []      Write   []
Execute []      Execute []      Execute []


@chubin
Copy link
Owner

chubin commented May 15, 2020

Very cool idea! It should be definitely implemented

@ErezBinyamin
Copy link
Collaborator

I like this idea a lot! I've written a script! You can pass a permission string rwx-wx--x or a value 731 and the output will be the same

Linux Permissions String:	rwx-wx--x
Linux Permissions Number:	731

Owner		Group		Public

Read    [X]	Read    [ ]	Read    [ ]
Write   [X]	Write   [X]	Write   [ ]
Execute [X]	Execute [X]	Execute [X]

@chubin
Copy link
Owner

chubin commented May 29, 2020

@ErezBinyamin Erez, let's add this script to the adapters collection (share/adapters)
and activate it

@ErezBinyamin ErezBinyamin mentioned this issue May 29, 2020
chubin added a commit that referenced this issue May 29, 2020
@chubin
Copy link
Owner

chubin commented May 29, 2020

Cool, it works!

What does not work, what could be improved:

  • Input string format check (if it does not look like a format, the output must be like It does not look like Linux/UNIX access mode: $1
  • Sticky bit, SGID, SUID support

The rest looks very cool

@chubin
Copy link
Owner

chubin commented Jun 1, 2020

I've merged #205 but it is still wrong:

$ curl cht.sh/chmod/1777
Linux Permissions String:       rwtrwtrwt
Linux Permissions Number:       1777

Special         Owner           Group           Public

Setuid     [ ]  Read    [X]     Read    [X]     Read    [X]
Setgid     [ ]  Write   [X]     Write   [X]     Write   [X]
Sticky bit [X]  Execute [X]     Execute [X]     Execute [X]

It should be rwxrwxrwt, not rwtrwtrwt.

$ curl cht.sh/chmod/7777
Linux Permissions String:       rwtrwtrwt
Linux Permissions Number:       7777

Special         Owner           Group           Public

Setuid     [X]  Read    [X]     Read    [X]     Read    [X]
Setgid     [X]  Write   [X]     Write   [X]     Write   [X]
Sticky bit [X]  Execute [X]     Execute [X]     Execute [X]

It should be rwsrwsrwt. not rwtrwtrwt

@chubin
Copy link
Owner

chubin commented Jun 1, 2020

I referenced the new adapter in the chmod cheat sheet:

$ curl cht.sh/chmod
...

$ curl cht.sh/chmod~curl
[ chmod ]
# Convert string representation of the access right
# into numeric form and back
curl cheat.sh/chmod/750
curl cheat.sh/chmod/rwxr-x---

@chubin
Copy link
Owner

chubin commented Jun 3, 2020

It works now! Many thanks to @ErezBinyamin who implemented the adapter

@chubin
Copy link
Owner

chubin commented Jun 10, 2020

@ErezBinyamin Just for your information,
the queries to the chmod adapter (chmod/ is removed from the query + they are grouped by 10 in a line):

0 000 0001 001 002 003 004 005 006 007
01 0111 022 0222 0333 044 0444 04755 0544 0555
0644 0711 0722 0733 0744 0755 0757 077 0777 0788
07s8 -1 1 10 100 1004 11 111 123 1234
1444 150 1531 1600 1644 1755 1760 1776 1777 1788
2 200 2004 222 2444 246 2531 2600 2755 2775
2777 3 333 3600 3644 3755 3777 4 400 4004
402 420 4206 42069 444 4444 4600 4701 4711 4744
4755 4777 4855 5 531 555 5600 5777 6 600
6000 6004 632 633 634 64 640 644 645 650
655 6644 666 6764 677 6777 69 6969 6969696 69696969
7 700 701 702 703 704 705 710 711 7111
7177 722 723 7277 731 732 733 7377 744 7477
74r 75 +++750 +750 750 751 752 753 7531 754
755 7555 755+Q 755Q 756 757 7577 758 760 764
7644 765 766 7666 7666000 77 772 775 7755 776
+777 777 777+ 7772 7775 +7777 7777 +77777 8 844
850 855 855s 855S 85s5 888 9 944 955 999
a
abbc
build.sh build-failure.sh
drwxr-xr-x
:learn
ls
number
options
permissions
-r--------
rw-r--r--
rws------
rwS------
rwsr-s--s
rwsr-s--t
rwsr-s--T
rwsrwSrwx
rwsrwxrwx
rwsr-xr-x
rwSr-xr-x
rwt------
+rwx
rwx------
rwxr-s--s
rwxr-T---
rwxr-T--s
rwxrw-rw-
+rwxrwrwx
rwxrwxrw-
rwxrwxrwx
rwxrwxr-x
rwxr-x---
rwxr-xr-t
rwxr-xr-x
rwx-wx--x
rx
r-xr-xr-x
S855
--version
-wS-wsr-S
-wxr-xrw-

Some of them are interesting ones.
For example :learn that cheat.sh by convention uses
for special "learn" pages.

For example. to learn Go (or Erlang) just do:

curl cheat.sh/go/:learn
curl cheat.sh/erlang/:learn

Maybe it is a good idea to write short introduction
about unix rights and permissions (or take it from the
internet) andmake it available via chmod/:learn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants