Linux Shell: ls and File Permissions

Source: Internet
Author: User

This is an entry-level article. If you are already a shell expert, please kindly advise, 3ku!


I recently used Linux Shell in an entire android project ??????!!

Fortunately, I have only written some simple shells before, and I have read a lot of shell Files written by Daniel. I admire the tears, and I hate little when books are used.


I had to study hard! Fortunately, the project has been completed and I am very touched!


The LS command is basically used by Linux users. Have wood ?!


Use the vim editor to open the why. Sh file and edit the content as follows (you can write it as needed, but follow the shell routine ):




Very simple shell!


Run the script./Why. Sh, but you cannot execute it now. Use LS-L to find the answer.




We can see that there is no execution permission (X ). Before proceeding to the following sections, let's take a look at what-RW-r -- means.


Rwx can be represented by binary data 0 and 1, that is, the existence is 1, And the absence is 0, so rwx is 111 (the decimal is 7), and so on:


R-indicates 100,-WX indicates 011, and r-X indicates 101.


Divide-RW-r -- into four parts: (1) (2) (3) (4.


(1)-indicates a file, (D indicates a directory, and l indicates that the file is a linked file)


(2) RW-indicates that the current user can operate on this file (readable and writable cannot be executed, with a value of 110 = 6)


(3) r -- indicates the permission to operate on this file in the same group as the current user (readable and writable cannot be executed, 100 = 4)


(4) r -- indicates that other users can operate on this file (readable, writable, and unexecutable; Value: 100 = 4)


If you use chmod 777 filename, all the permissions of this filename are granted to users of any user group.


In addition, we also need to know what u, O, G, and a mean ??


They are short for user, other, group, and all. So the following is simple:


Chmod U + permission (R, W, X) File


Chmod o + permission (R, W, X) File


Chmod g + permission (R, W, X) File


Chmod A + permission (R, W, X) File


Respectively:


Changes the file operation permissions of the current user, other users, and users in the same group.


At this time, the permissions of the why. Sh file can be changed to executable in two ways (equivalent ):


Chmod U + x Why. Sh


Chmod 744 why. Sh


After the change, for example:




Then you can execute this script.





Chown and chgrp can change the owner and user group of the file. I will not go into details here!





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.