Detailed description of the file name and file type and file permissions in the Linux system

Source: Internet
Author: User
Tags chmod mkdir readable touch file permissions

Linux file type and vice file name

Always emphasize a concept, that is: Any device under Linux are files, not only that, even the interface of data communication has a proprietary file in charge ~ So, you will? solution, Linux file type is really a lot of ~ In addition to the general file (-) and the directory file (d) mentioned earlier, What other kinds of documents are there?

* Type of File:

We have just mentioned using ' ls-l ' to observe the first column in the 10 characters, the first character is the type of file. In addition to the common general file (-) and catalog file (d), what kinds of file types are there?

* Regular documents (regular file):
Is the type of file that we are generally accessing, the first character is [-], for example, [-rwxrwxrwx], in terms of the attributes shown by Ls-al. In addition, according to the contents of the document, and roughly can be divided into:

o Plain text file (ASCII): This is the largest file type in a Linux system?? It is called a plain text file because it is something that we humans can read directly, such as numbers, letters, and so on. Almost as long as we can use it as a setup file all belong to this type of file. For example, you can release ' cat ~/.BASHRC ' to see the contents of the file. (Cat is the instruction to read the contents of a file)

o binary file (binary): Remember we mentioned in the operation of the software program in ' 0th chapter, Computer Introduction ', our system is actually only known and can execute binary files (binary file)? Yes ~ your Linux executable file (scripts, text-type batch file does not count) is this format ~ For example, just issued the instructions cat is a binary file.

o Data Format file (data): Some programs in the process of operation will read some of the files in a specific format, those specific format files can be referred to as the data file. For example, when a user logs on, our Linux records the logged in to the/var/log/wtmp file, which is a data file that he can read through the last command. But when using cat, it reads garbled ~ because he is a file in a special format.

* Directory (Directory):
is the directory??? Boaster Huan 鍪 Properties Halo [d], for example [drwxrwxrwx].

* Link file (link):
It's like a shortcut to the Windows system! The first property is [l] (lowercase in English l), for example [lrwxrwxrwx];

* Equipment and installation files (device):
Some files related to the system's perimeter and storage are usually concentrated in the/dev directory! They are usually divided into two types:

o Block device file: is some storage data to provide system random access to the peripheral equipment, for example, hard disk and soft disc, etc. is! You can randomly read and write in different blocks of the hard drive, this device is a block device?? ∧ irresolute to kill the pregnant Ligularia? DEV/SDA look, you'll find the first attribute is [B] Oh!

o character (character) device file: That is, some of the peripheral devices, such as keyboard, mouse and so on! These devices feature a ' one-time read ' and cannot truncate the output. For example, you can't let the mouse ' jump ' to another picture, but ' slide ' to another place! The first property is [C].

* Data Interface file (sockets):
Since it is known as a data interface file, this type of file is usually used on the web for information. We can start a program to listen to the requirements of the client, and the client can communicate through the socket for information. The first property is [s], which is most often seen in the/var/run directory.

* Data transfer file (FIFO, pipe):
FIFO is also a special type of file, and his main purpose is to solve the problem of error caused by multiple programs accessing a file at the same time. FIFO is the abbreviation of first-in-first-out. The first property is [P].

In addition to the device file is a very important document in our system, it is best not to modify the outside (usually he will not let you change it!). , another interesting file is the link file. If you often catch your application on the desktop, you should know that there is a ' shortcut ' under Windows. Similarly, you can simply treat the link file under Linux as a shortcut to a file or directory. As for the socket and FIFO file is more difficult to understand, because these two drum and the program (process) is more related, this wait until the future you? After the process, then come back to check it! In addition, you can also check the instructions on the system through the man FIFO and the mans socket.

* Linux file vice file name:

Basically, the Linux file is not called ' vice filename ', we have just talked about, a Linux file can be executed, and his first column of 10 attributes, and the file name is not related to the root. This is not the same idea as Windows. Under Windows, the file name that can be executed is usually. com. exe. bat and so on, and under Linux, as long as you have x in your permissions, for example [-rwx-r-xr-x] That means the file can be executed!

However, it can be executed in the same way that success can be performed. For example, the root directory of the Install.log is a text-only file, if through the modification of permissions to become-rwxrwxrwx after the file can really execute successfully? Of course not ~ because his content has no information to carry out at all. So, this x represents the ability of the file to execute, but whether it succeeds, of course, depends on the contents of the file??? /p>

Nonetheless, we still want to be able to do this by using a file name, so we usually indicate what kind of file it is with the appropriate alternate file name. There are several commonly used vice file names:

* *.sh: Batch file (scripts), because the batch file is written for use with the shell, so the file name is compiled. Sh??? /p>

* *z, *.tar, *.tar.gz, *.zip, *.tgz: Packaged compressed files. This is because the compressed software is gunzip, tar, and so on, because of different compression software, and its associated file name??? /p>

* *.html, *.php: Web related files, representing HTML syntax and PHP syntax of the Web page file?? HTML files can be opened directly using a Web browser, as with. php files, you can browse through the client side of the browser to get the results of the operation of the Web page!

Basically, the file name on the Linux system really just lets you solve the possible use of the file, the real implementation or not still need the specification of the right to do! For example, although there is a file executable file, such as the common/bin/ls this display file properties of the instructions, but if the permissions of the file is modified to be unable to execute, then the LS becomes unable to execute??? /p>

This kind of problem most often occurs in the process of file transfer. For example, you download an executable file on the Web, but you can't do it in your Linux system! Oh! Then it is possible that the attributes of the file have been changed! Do not doubt that, from the network to your Linux system, the file attributes and permissions will indeed be changed Oh!

* Linux file length limit:

Under Linux, when using a preset ext2/ext3 file system, the file name length is limited to:

* The maximum allowable file name of a single file or directory is 255 characters;
* Contains full path name and directory (/) full file name is 4,096 characters.

It's quite a long filename. We want the Linux file name to know what the file is doing at a glance, so the filename is usually very long! People who are accustomed to Windows may not be able to stand it, because file names are usually really long, and for a friend who uses Windows to speed up typing, hmm! It's really disturbing ... However, I have to advise you to improve the training of typing well??? /p>

* Linux file Name restrictions:

Because Linux in the text interface under some of the command operation relationship, in general, you set Linux under the file name, it is best to avoid some special characters better! such as the bottom of these:

* ? > <; &! [ ] | \ ' " ` ( ) { }

Because these symbols in the text interface, is of special significance! In addition, the file name begins with a decimal point '. ' On behalf of this file as ' hidden file ' Oh! At the same time, because of the instruction release, often use to-option and so on options, so you'd better avoid the file file name of the beginning with-or + to name Ah!

Directory and File permissions
Now we know the three identities of the files within the Linux system (owner, groups and others, know that each identity has three kinds of permissions (RWX), has been known to be able to use Chown, CHGRP, chmod to modify these permissions and attributes, of course, the use of ls-l to observe the file is no problem. The first two subsections also discuss the importance of these file permissions for data security. So how do these file permissions differ from common files to directory files? There's a big difference! Let the bird do this young the bottom to speak clearly, understand!

* The importance of the permissions to the file

A file is a place that actually contains data, including generic text files, database content files, binary executables (binary program), and so on. Therefore, the permissions for the file, he is the meaning of this:

* R (Read): Can read the actual content of this file, such as reading text file text content, etc.;
* W (Write): You can edit, add, or modify the contents of the file (but not delete the file);
* X (Execute): The file has permissions that can be executed by the system.

That readable (r) Representative reads the file content is OK? Solution, then executable (x)? You have to be careful here! Because the ability to execute a file under Windows is judged by a ' vice filename ', such as:. exe,. bat,. com, and so on, but under Linux, if our files can be executed, it is determined by the right to have ' x '! There is no absolute relationship with the filename!

What about the last w? When you have W permission on a file, you can have permission to write/edit/Add/Modify the contents of the file, but do not have permission to delete the file itself! For the rwx of the file, mainly for the ' content of the file ', and file file name is not related to the existence of Oh! Because the document records is the actual information!

* The importance of permissions to the directory

The file is where the actual data is stored, so what is the main thing stored in the directory? The main contents of the directory in the record file name list, file name and directory has a strong connection! So what does that R, W, x mean for a directory when it's a directory?

* R (Read contents in directory):

Represents a permission to read a directory structure manifest, so that when you have permission to read a directory, you can query for file name information in that directory. So you can use LS This command to display the contents of the directory list!

* W (Modify contents of directory):

This writable permission is great for the directory! Because he says you have permission to move the directory structure list, which is the following permissions:

o Create new documents and directories;
o Delete files and directories that already exist, regardless of the permissions of the file! )
o Renaming existing files or directories;
o move files, directory locations within the directory.

All in all, the W permission on the directory is related to the file name movement under the directory.

* x (Access directory):

Hey! What is the purpose of the directory's execution permissions? The directory is just a record file name, can not be used to carry out it? That's right! The directory can not be executed, the directory x represents whether the user can enter the directory to become the use of the working directory! The so-called working directory (work directory) is your current directory! For example, when you log on to Linux, your home directory is your current working directory. The instructions for changing directories are ' CD ' (Change directory)??? /p>

The X permission for the directory determines whether the user can enter the directory.

General concept of directory permissions so, let's take a look at a few examples to get you? What is the permissions for a directory??? /p>

Examples:
The permissions for a directory are as follows:

The code is as follows:
drwxr--r--3 root root 4096 June 08:35. SSH

System has an account name called Vbird, this account does not support the root group, please ask Vbird to this directory have what permission? Can I switch to this directory?
For:
Vbird has only r permission for this directory, so vbird can query the list of file names in this directory. Because Vbird does not have X's permission, Vbird cannot switch to this directory! (A very important concept!) )

In the example above, because Vbird has R's permission, because it is r at first glance seems to have access to this directory, it is actually wrong. Can enter a directory, only with the directory's X permissions! In addition, the working directory is very important for the execution of instructions, if you do not have X permissions in a directory, then you cannot switch to the directory, you can not execute any of the instructions in the directory, even if you have the directory of R permissions.

Many friends in the setting up the site will be stuck in a number of permissions set, they open directory data to anyone on the internet, but only the permissions of R, as shown in the example above, result in the Web server software not being able to read files to the directory (up to a maximum of file names). End users are always unable to correctly access the contents of the file (show insufficient permissions!). )。 Note: To open the directory to anyone browsing, you should at least give R and X permissions, but w permissions can not be arbitrarily given! Why can't we just give it to you, let's take a look at the next example:

Examples:
Suppose there is an account name called Dmtsai, and his home directory has [rwx] permissions on/home/dmtsai/,dmtsai for this directory. If there is a file named The_root.data in this directory, the permissions for the file are as follows:

The code is as follows:
-rwx------1 root root 4365 Sep 23:20 the_root.data

What is Dmtsai's permission for this document? Can I delete this file?
For:
As shown above, because Dmtsai is ' others ' for this file, the file is unreadable, cannot be edited, and cannot be executed, which means he cannot change the contents of the file.

But because this file is in his home directory, he has rwx full permissions under this directory, so for the_root.data this ' filename ', he is able to ' delete '! The conclusion is that dmtsai this user can delete the_root.data this file!

Or don't you understand? Do you understand me? It does not matter ~ We have to design a practice, so that you actually play to see, you should be able to compare near into the situation! However, since many of the instructions we have not yet taught, so the following instructions to the first solution, detailed instructions to use we will continue to introduce.

* Create the desired file and directory environment using root identity First

We use root to create a directory named testing in the/tmp directory where everyone can work, with a permission of 744 and the directory owner as root. In addition, in the testing directory in the establishment of an empty file, the filename is also testing. Create a directory with mkdir (make directory), and create an empty file that can be used in touch (described in the next chapter). So the process looks like this:

The code is as follows:
[root@www ~]# cd/tmp <== Switch working directory to/TMP
[Root@www tmp]# mkdir testing <== Create a new directory
[root@www tmp]# chmod 744 testing <== Change permissions
[Root@www tmp]# Touch testing/testing <== Establish empty files
[Root@www tmp]# chmod testing/testing <== Change Permissions
[Root@www tmp]# Ls-ald Testing testing/testing
drwxr--r--2 root root 4096 Sep 16:01 testing
-RW-------1 root 0 Sep 16:01 testing/testing

# Take a closer look, the directory permissions are 744, and the group and users belong to root Oh!
# So under such circumstances, what is the general identity user's permission for this directory/file?

* Read and Write access to the general user? Observation of

In the above example, although the directory is 744 of the permissions set, the general user should be able to have R permissions, but such permissions users can do? If the bird's system contains an account named Vbird, we can change the identity through the ' su-vbird ' command. Look at the bottom of the operation first!

The code is as follows:
[root@www tmp]# su-vbird <== switch identities into Vbird??? br/> [vbird@www ~]$ cd/tmp <== Look, the identity has changed Oh! The prompt character also becomes $!
[Vbird@www tmp]$ ls-l testing/
?--------- ? ? ? ? ? Testing
# because permissions with R can query the file name. But there are not enough permissions (no x), so there's a bunch of question marks.
[Vbird@www tmp]$ CD testing/
-bash:cd:testing/: Permission denied
# because there is no X, so of course there is no permission to enter! There is no echo before the permission description Ah! </p> <p>* What is the situation if the directory belongs to the user itself?

The above exercise we know that only R does allow the user to read the list of file names for the directory, but the details are still not readable, and the directory cannot be turned into a working directory (in the context of CD entry). So if we make the directory the user, will the user be able to delete files under this directory? Below the practice to do a look:

The code is as follows:
[Vbird@www tmp]$ exit <== let Vbird change back to the original root identity Oh!
[Root@www tmp]# chown Vbird Testing <== Modify permissions to allow Vbird to own this directory
[Root@www tmp]# su-vbird <== becomes vbird again to operate
[Vbird@www ~]$ cd/tmp/testing <== can enter the catalogue!
[Vbird@www testing]$ Ls-l
-RW-------1 Root 0 Sep 16:01 testing <== file is not Vbird!
[Vbird@www testing]$ RM testing <== Try to kill this file to see!
Rm:remove write-protected Regular empty file ' testing '? Y
# should be deleted! Is that understood?!

Through this simple step above, you can clearly know that x in the directory is related to ' whether to enter the directory ', as for that W has a fairly important permission, because he can let users delete, update, new file or directory, is a very important parameter Ah!

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.