Linux Shell study Note 3

Source: Internet
Author: User

 

File Attribute operations in Lesson 5

File attributes include:

1) Permission

2) Owner

3) Group

 

5.1 file type

5.1.1 determine the file type

To determine the type of a file, you can add the-L option to LS. All types are listed.

For example:

$ LS-L/home/Ranga/. Profile

Output:

-Rwxr-XR-x L Ranga users 2368 Jul 11. Profile *

The first character is a connector (-), indicating that the file is a common file.

For special files, the first character will be one of the following characters

 

Character file type

-Common files

T symbol chain

C character special file

Block B special files

P Named Pipe

Ssocket

D directory folder

 

 

5.1.2 common files

Common File: stores any type of data, which can be plain text, application-specific format, or specific binary that can be executed by the system.

 

Format.

$ File/etc/PHP. ini

Output: ASCII English text

 

5.1.3 Symbolic Link

A symbolic link is a special file that points to another file in the system. (Similar to shortcuts in Windows)

 

1. Create a symbolic chain

Ln-S source destination

The source is the relative or absolute path of the original file, and the destination is the name of the chain.

 

For example:

$ Ln-S/home/httpd/html/users/Ranga/home/Ranga/public_html

 

Common Errors:

1) the target file already exists.

2) the target file is a directory.

 

If the declared target is a directory, ln creates a chain with the same name as the source file in that directory.

For example, if there is a pub directory under the current directory.

$ Ln-S/home/FTP/pub/Ranga pub

Create a chain pub/Ranga, instead of reporting that the target is a directory.

 

 

5.1.4 Device Files

Users can access Linux devices by reading and writing device files. These device files are the access points of the device in the file system.

The device file is usually located in the/dev directory. The two main device files are:

1) special character files

2) special files

 

1. Special Character files

Provides a mechanism for one character to communicate with the device each time. Generally, a character device represents an "original" device.

 

2. Block special files

Block special files provide a mechanism to communicate with the device driver through the file system. These files are called Block devices. Each time a block device transfers one

 

Large data blocks. A typical example of this type of file is a disk and removable media.

For example:

$ LS-L/dev/SDA

Return Value: BRW-r ----- 1 root disk 8, 0 Nov 18/dev/SDA

The first character here is B, indicating that the file is a special block file. Like a special character file, these files have primary and secondary numbers.

 

.

 

5.1.5 Named Pipe

A great feature of UNIX is that users can redirect the output of one program to the input of another program at a very small cost.

For example, the command who! Grep Ranga converts the output of the WHO command into the input of the grep command.

This means that the output of a command is transmitted to another command in a pipeline.

 

 

5.2 owner, group, and permission

Every UNIX file has the following attributes:

1) owner permission

2) Group Permissions

3) Other Permissions

The owner permission determines what operations the object owner can perform on the object.

The Group permission determines what operations a user can perform as a member of the array of files.

Other permissions show the operations that other users can perform on files.

 

You can perform the following operations on a file:

1) read: if you have the read permission, you can browse the file content.

2) Write. If you have the write permission, you can change the file content.

3) execution. If the user has the execution permission, the file can be executed as a program.

 

5.2.1 view Permissions

You can use the LS-l command to display the permissions on files.

Example: $ LS-L/home/Ranga/. Profile

Output:

-Rwxr-XR-x 1 Ranga users 2368 ju1 11 15.57. Profile *

Because the first symbol is '-', this file is a common file. The following three characters show the permissions of the file owner.

The following three characters show the permissions of the file-related groups, and the last three characters show the permissions of other users.

 

Basic permission list:

R. Users can browse the file content.

W. Users can modify the file content.

X execution users can run files like running programs. The directory must have the execution permission.

 

To enter the Directory

 

1. directory permission

The X-bit authorization of a directory determines the access to the directory.

The read permission of the Directory allows you to view the files and properties in the directory.

Directory write permission allows you to add or delete files in the directory.

If you are only granted the execution permission for the directory, you cannot view the files in the directory or add or delete files from the directory. However, you can run

 

Executable files in the row directory.

 

2. SUID and SGID File Permissions

 

 

5.2.2 change file and directory permissions

Use the CHMOD command to change the file and directory permissions.

$ Chmod (WHO) (Action) (permissions)

List of WHO

U owner

G group

O others

A All

 

List actions

+ Add permissions

-Delete Permissions

= Displayed ACL settings

 

List Permissions

R read

W write

X execution

Ssuid or sgid

 

For example: $ chmod A = r *. Grant the read permission of all files in a directory to all users.

$ Chmod go-W. Profile delete any user except the. Profile owner to write this file.

 

-R option, traverse all files and folders in the directory, and set permissions.

 

5.2.3 change owner and group

There are two commands that can be used to change the file owner and group:

1) chown. Change owner

2) chgrp. Change Group

 

1. Change ownership

The CHOWN command changes the ownership of a file.

Chown options User: group files

Chown Ranga:/home/httpd/html/users/Ranga

Change the owner of the given directory to user Ranga.

 

2. Restrictions

Super User Root can change File Ownership infinitely, but there are some restrictions on normal users.

 

3. Change Group Ownership

$ Chown User: authors/home/Ranga/docs/ch5.doc

Change the group of the given file to the user in athors.

 

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.