. Neter Linux Series II: Linux Files directory and file directory permissions

Source: Internet
Author: User
Tags clear screen

One, the directory of files under Linux

Summary: The Linux file system is a hierarchical, tree- like structure in which the topmost layer of the structure is the root directory "/", and then another directory is created in this directory. A deep understanding of the Linux file directory is very important, as shown in:

In the future you will be logged in with which user, and you'll be under that user's directory. In order to further deepen the understanding of the Linux file directory, the following is accompanied by a corresponding directory function explanation:

Simple demo:

Bin: File under directory:

Here you can use the above command to go to the other directory below to see the files inside. (Just a simple look oh, do not arbitrarily modify.) )

Summary: Common commands

LS: Displays all files under the current directory.

The LS command lists all the files and directories in the terminal's current directory. Of course, all of these directories may also have subdirectories and files. We want to know which directories and files under these directories can be displayed using the-R parameter.

: Ls-r

The LS command also has many parameters that can be used to obtain more detailed information. For example-1 parameters. It allows you to display only one file and directory per row in the directory.

Another problem is that there are hidden files in our Linux system, much like the Windows system. In addition to the user's own files, some files are used and modified by the system, or by the application. Hiding them by default is indeed a protection for the "user itself". What if we need to check these hidden files on a Linux system?

Note: with "." The names of the files and directories that begin with are hidden. Similarly, the blue display is the directory, the hidden directory.

Besides, it looks like a mess, doesn't it? We can use the-1 and-a parameters together

Is this a little bit neat, if anyone thinks that in Windows you can display the details of files and directories in a list, we can use the Ls-l

Clear Clear Screen

If you want to see where you are now under which directory, you can use the PWD command, this command is very useful!!! When you don't know where you are right now, you can use it.

For the command of LS you can refer to: http://man.linuxde.net/ls

Use of the Find command:

Explanation: Note the space between,/indicates the root directory,-name represents the name of the file.

Note: This will look very slow because it starts at the root, so try to find it from under one directory later, which can shorten the scope of the search.

Use of the grep command:

Explanation:-n Displays the line number Guozheng indicates the keyword to be queried hello.cpp means to find it in that file.

CD/presentation: Go back to the root directory

Cd.. /indicate: Go back to the top level directory

The CD says: Go back to the directory where the user is located

Requirement: Sometimes I need to save the information I find or statistics to another file and provide it to someone else.

REDIRECT command:

Ls-l > A.bak The contents of the list are written to the file A.bak (overwrite write)

Ls-al >> Aa.bak The contents of the list are appended to the end of the file Aa.bak

Note: This command is useful for saving statistical information to the A.bak file.

Ii. file owners, groups, and other groups in Linux

To explain the problems of users and groups in Linux, let's look at the users and groups in Windows, as shown in:

Well, let's take a look at the concepts of users and groups in Linux.

Brief introduction:

Each user in Linux must belong to a group and cannot be independent of the group . In Linux, each file has the concept of owner, group, and other groups.

1) Owner (2) group (3) other group (4) Change the group where the user is located

    • File owner

Typically, the creator of the file, who created the file, becomes the owner of the file naturally.

You can see the owner of the file with the "Ls–ahl" command.

You can also use "Chown User name File name" To repair the owner of the file.

We use the directory created by the GZ normal user, which belongs to the user by default, and if I want to change the user of the directory, you can use: Chown username file name

    • User Group

When a user creates a file, the group in which the file is located is the group that the user is in. You can see all the groups of files with the "Ls–ahl" command. You can modify the group in which the file resides by using the CHGRP group name file name.

Use: Ls-ahl | More

Modify the group in which the directory resides: Chgrp root mysrc can change the group in which the directory resides.

Now I've changed the group GZ where the MYSRC directory is located to root

    • Other groups

Except for the owner of the file and the user in the group, other users of the system are other groups of files.

    • Change the group where the user resides

When you add a user, you can specify which group to add the user to, and the same root administrative permissions can change the group in which a user is located:

USERMOD–G Group name User name you can use

Usermod–d Directory name User name change the initial directory of the user login

I know you're dizzy. It doesn't matter, let's look at a case: (We want to add the following user to the corresponding group)

Step1: Create a corresponding group using the root identity

How do I see what groups are created? Use: Cat/etc/group

Explanation: Policeman: Name of the group 1001: The reorganization ID number is unique.

Use the same command to create a bandit group.

Step2: Create a user and specify which group the user belongs to

command to use:

USERADD-M User Name

Case: Useradd-m xiaoming "Add User Xiaoming" (Special reminder: This must be added:-M and is lowercase, otherwise the user you are not logged on to create good.) )

passwd user name "Change Password"

Case: passwd xiaoming "Modify Xiaomiing's password"

Userdel User Name "Delete user"

Userdel xiaoming "Delete User Xiaoming"

Userdel-r xiaoming "Delete user and user home directory"

Created by: Arnold Schwarzenegger (Iamback)

View all user information in Linux: CAT/ETC/PASSWD

Explanation: Shitailong: Indicates the user's name; x: Represents the password of the encrypted user; 1003: Represents the user's id;1002: Id;/home/shitailong: The home directory where the user resides

Step3: Assigning passwords

To remember, the default password for these three users is 123456.

STEP4: Testing

Now: I want to move Schwarzenegger (Iamback) to the Bandit group, how to do?

Use: Usermod–g Tufei iamback

Now the Golden Triangle is in the Bandit group.

Third, the management of file permissions

The contents shown in Ls-l are as follows:

-rwxrw-r--1 root root 1213 Feb 2 09:39 ABC

10 characters to determine what different users can do with a file

The first character represents the file (-), directory (d), link (l)

The remaining characters are read (R) per 3 (rwx) write (w) execution (x)

First set of rwx: The permissions of the file owner are read, write, and execute

Second set of rw-: Permissions for users of the same group as the file owner are read, write, but not executed

Third group r--: the permissions of other users who are not in the same group as the file owner are read and cannot be written and the available numbers are represented as: R=4,w=2,x=1 so rwx=4+2+1=7

1 indicates the number of connected files (if the folder is the directory, indicating: the number of files under the directory)

Root user

Root Group

1213 file Size (bytes)

Feb 2 09:39 Last Modified date

ABC file name

Now I'm using Jiesen to log in to create the file:

Example:-rw-r--r--

Now I use the Shitailong user to enter into the Jiesen directory, the results are as follows:

The results can be entered under this directory because the permissions of the Jiesen directory are as follows:

In contrast to the above analysis: Users of other groups have readable permissions to the Jiesen directory.

The use of directory permissions under Linux management, not one user into another user's directory.

Now Jiesen allows Shitailong to enter under its own home directory, and what can I do with writable permissions? As shown in the following:

Note: You cannot use Shitailong to modify Jiesen directory permissions. Only Jiesen and root can be modified.

This is set to be completely public, other groups of users can also go to the directory below, so I want the user itself and the group of the user can enter, other groups of users are not allowed to come in.

Then, I log in with the GZ user to see if I can get into the Jiesen directory, the result is as follows:

Note: This only modifies the folder (directory) permissions, the file permissions under the directory are not modified.

Add:

Commands to change permissions:

chmod changing the permissions of a file or directory

chmod 755 ABC: Give ABC permission rwxr-xr-x

chmod U=RWX,G=RX,O=RX ABC: Same as u= user Rights g= group permissions o= different groups other user rights

chmod u-x,g+w ABC: for ABC to remove user-executed permissions, increase group Write permissions

chmod a+r ABC: Add read permissions to all users

Change owner (chown) and user Group (CHGRP) commands

Chown xiaoming ABC: Change the owner of ABC to Xiaoming

CHGRP Root ABC: Change the group that the ABC belongs to IS root

Chown root./ABC: Change ABC the owner of this directory is root

Chown-r root./ABC: Change the ABC directory and the owner of all files and directories below it is root

It is advisable to practice more than one knock command. Permissions this part is indeed very complex, we can practice, if the problem can not be solved, in the comment area to put forward, I will help you see.

OK, today is about here, the evening continue to update this series of articles, think can, I hope the recommendation ha ~ Your recommendation is my motivation.

Guo Yan

Source: http://www.cnblogs.com/runningsmallguo/

The copyright of this article is owned by the author and the blog Park, welcome reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to give the original link.

. Neter Linux Series II: Linux Files directory and file directory permissions

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.