In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "uhe understands the file name and file type as well as file permissions in the Linux system." interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "uhe understands file names and file types as well as file permissions in the Linux system."
Linux file type and sub-file name
Always emphasize a concept, that is: any device under the Linux is a file, not only that, even the data communication interface also has its own files in charge ~ so, you will understand that there are really many types of files in Linux. Besides the general files (-) and directory files (d) mentioned above, what kinds of files are there?
* types of documents:
We just mentioned the use of'ls-1'to observe that of the ten characters in the first column, the first character is the type of file. In addition to the common general files (-) and directory files (d), what other types of files are there?
* regular documents (regular file):
That is, for the type of file we are accessing, the first character is [-], for example, [- rwxrwxrwx] in terms of the attributes displayed by ls-al. In addition, according to the contents of the document, it can be roughly divided into:
O plain text file (ASCII): this is the most common type of file in the Linux system. It is called plain text file because the content is material that we humans can read directly, such as numbers, letters, and so on. Almost any file that we can use as a setting belongs to this type of file. For example, you can press' cat ~ /. Bashrc'to see the contents of the file. (cat is an instruction to read the contents of a file.)
O binary file (binary): remember when we mentioned in the software program operation in Chapter Zero, introduction to computers, that our system actually only knows and can execute binary files (binary file)? Yes ~ the executable files in your Linux (scripts, text batch files are not counted) are in this format ~ for example, the instruction cat just issued is a binary file.
O data format documents (data): some programs read documents in certain formats during operation, and those documents in a specific format can be called data documents (data file). For example, when a user logs in, our Linux will record the login information in the / var/log/wtmp file, which is a data file, and he can read it through the last command! But when you use cat, you will read the garbled code ~ because it belongs to a special format. Understand?
* Directory (directory):
Is the directory ~ the first attribute is [d], for example, [drwxrwxrwx].
* Link file (link):
It is similar to the shortcut under the Windows system! The first attribute is [l] (lowercase of L), for example, [lrwxrwxrwx]
* equipment and device file (device):
Some files related to the perimeter and storage of the system are usually concentrated in the / dev directory! It is usually divided into two categories:
O block device files: peripherals that store data to provide random access to the system, such as hard disks and floppy disks! You can randomly read and write in different blocks of the hard disk, and this device is the block device. You can check / dev/sda yourself and you will find that the first attribute is [b] Oh!
O-character (character) device file: that is, some serial port peripherals, such as keyboards, mice, etc.! These devices are characterized by 'one-time reading' and cannot truncate the output. For example, you can't let the mouse jump to another picture, but slide to another place! The first attribute is [c].
* data interface file (sockets):
Since it is called a data interface file, of course, this type of file is usually used to receive data on the Internet. We can start a program to listen to the client's request, and the client can communicate through this socket. The first attribute is [s], which is most commonly seen in the / var/run directory.
* data transfer documents (FIFO, pipe):
FIFO is also a special file type, its main purpose is to solve the error problem caused by multiple programs accessing a file at the same time. FIFO is the abbreviation of first-in-first-out. The first attribute is [p].
Except that the equipment file is a very important file in our system, it is best not to modify it at will (usually he won't let you modify it!) Another interesting file is the link file If you often bring applications to the desktop, you should know that there are so-called shortcuts under Windows. Similarly, you can simply think of a link file under linux as a shortcut to a file or directory. As for socket and FIFO files, it is difficult to understand, because these two drums have something to do with the program (process). Wait until you know process in the future, and then come back to check it. In addition, you can also check the instructions on the system through man fifo and man socket!
* Linux file sub-file name:
Basically, there is no so-called 'secondary file name' in Linux files. We have just talked about whether an Linux file can be executed or not, which is related to the ten attributes of its first column and has nothing to do with the file name at all. This concept is different from that of Windows. Under Windows, the file name that can be executed is usually .com .exe. Bat, etc., while under Linux, as long as you have x in your permissions, for example, [- rwx-r-xr-x] means that the file can be executed!
However, being able to be executed is not the same as being able to execute successfully ~ for example, install.log in the root home directory is a plain text file. If you change the permission to-rwxrwxrwx, can this file really execute successfully? Of course not ~ because there is no enforceable information in his content. So, this x represents the executable ability of this file, but whether it can be executed successfully or not depends on the content of the file.
Even so, we still want to know what the file is by the sub-file name, so we usually use the appropriate sub-file name to indicate what kind of file it is. There are several common sub-file names below:
* * .sh: batch file (scripts), because the batch file is written using shell, so the sub-file name is .sh
* * Z, * .tar, * .tar.gz, * .zip, * .tgz: a packaged compressed file. This is because the compression software is gunzip, tar, etc., because of the different compression software, and take its related sub-file name!
* * .html, * .php: webpage related files, which represent HTML syntax and PHP syntax respectively! HTML files can be opened directly using a web browser, while .php files can be viewed on the server side through a browser on the client side to get the calculated web page results.
Basically, the file name on the Linux system is really just to let you know the possible purpose of the file, whether it is really implemented or not still requires permission specifications! For example, although a file is executable, such as the common / bin/ls directive that displays file properties, if the permissions of the file are modified to be unexecutable, then ls becomes unexecutable!
The above problems most often occur in the process of file transfer. For example, you download an executable file on the Internet, but it cannot be executed in your Linux system! He he! Then it is possible that the properties of the file have been changed! There is no doubt that the properties and permissions of files will be changed when they are transferred from the network to your Linux system.
* Linux file length limit:
Under Linux, when using the preset Ext2/Ext3 file system, the file name length for the file is limited to:
* the maximum allowable file name for a single file or directory is 255 characters
* the complete file name containing the full path name and directory (/) is 4096 characters.
It's a pretty long file name! We hope that the file name of Linux can tell what the file is doing at a glance, so the file name is usually very long! People who are used to using Windows may not be able to stand it, because file names are usually really long. For friends who are used to using Windows and lead to poor typing speed, uh-huh! It's really disturbing. However, I have to advise you to strengthen your training in typing.
* restrictions on Linux file names:
Because of the command operation relationship of Linux under the text interface, generally speaking, when you set the file name under Linux, it is better to avoid some special characters! For example, the following:
*? > <; &! [] |\'"`() {}
Because these symbols have a special meaning under the text interface! In addition, the file name begins with the decimal point'.' Represents the file as a 'hidden file'! At the same time, since options such as-option are often used in the issuance of instructions, you'd better avoid naming the file name with-or +.
Directory and file permissions
Now we know the three identities (owner, group and others) of files in the Linux system, and know that each identity has three permissions (rwx). We already know that we can use chown, chgrp, chmod to modify these permissions and attributes, of course, it is no problem to use ls-l to observe files. The importance of these file permissions for data security is also discussed in the first two sections. So how do these file permissions differ between general files and directory files? There's a big difference! Next, let Brother Bird make it clear and clear!
* importance of permissions to files
Documents are places that actually contain data, including general text documents, database content documents, binary executable documents (binary program), and so on. Therefore, the meaning of permissions for files is as follows:
* r (read): you can read the actual contents of this file, such as reading the text contents of a text file, etc.
* w (write): you can edit, add or modify the contents of the file (but not delete the file)
* x (eXecute): this file has permissions that can be executed by the system.
That readable (r) means that reading the contents of the file is well understood, but what about executable (x)? You have to be careful here! Because whether a file has the ability to execute under Windows is judged by the "sub-file name", such as .exe, .bat, .com, etc., but under Linux, whether our file can be executed is determined by whether we have the permission of'x'! It has nothing to do with the file name!
As for the last w, what about this permission? When you have w permission to a file, you can write / edit / add / modify the contents of the file, but you do not have the permission to delete the file itself! For the rwx of a file, it is mainly aimed at the 'content of the file', which has nothing to do with the existence of the file name. Because the document records the actual information!
* importance of permissions to directories
Files are where the actual data are stored, so what is the main storage of the directory? The main content of the directory is to record the list of file names, which are strongly related to the directory. So if it's for a directory, what does that r, w, x mean to a directory?
* r (read contents in directory):
Indicates that you have permission to read a list of directory structures, so when you have permission to read (r) a directory, it means you can query the file name data in that directory. So you can use the ls command to display a list of the contents of the directory!
* w (modify contents of directory):
This writable permission is great for directories! Because he says you have permission to move the directory structure list, that is, the following permissions:
O create new files and directories
O Delete existing files and directories (regardless of the permissions of the file!)
O rename an existing file or directory
O move the files and directory locations in the directory.
In short, the w permission of the directory is related to the movement of the file name under the directory!
* x (access directory):
Hey! What is the purpose of the executive authority of the directory? The directory is just a record of the file name, it can't be used for execution, can it? That's right! The directory cannot be executed, and the x of the directory represents whether the user can enter the directory and become the purpose of the working directory! The so-called working directory (work directory) is your current directory! For example, when you log in to Linux, your home directory is your current working directory. The command to change the directory is' cd' (change directory)!
The x permission of the directory determines whether the user can enter the directory.
The general concept of directory permissions is like this. Let's take a look at some examples to let you know what directory permissions are.
Example:
The permissions for a directory are as follows:
The code is as follows:
Drwxr--r-- 3 root root 4096 Jun 25 08:35 .ssh
The system has an account name of vbird, this account does not support root groups, what permissions does vbird have on this directory? Can I switch to this directory?
A:
Vbird only has r permission for this directory, so vbird can query the list of file names in this directory. Because vbird does not have x permission, vbird cannot switch to this directory! (quite important concept!)
In the above example, because vbird has the permission of r, because r seems to have permission to enter this directory at first glance, but that is wrong. Whether you can enter a directory or not is only related to the x permission of that directory! In addition, the working directory is very important for the execution of instructions. If you do not have x permission in a directory, you cannot change to that directory and execute any instructions in that directory, even if you have the permission of r in that directory.
Many friends will get stuck in some permission settings when setting up a website. they open the directory data to anyone on the Internet to browse, but only open the permission of r, as shown in the example above. As a result, the website server software cannot read files in the directory (you can only see the file name at most). End users are always unable to correctly access the contents of the file (insufficient display permissions!) . Note: if you want to open the directory to anyone to browse, you should at least give r and x permissions, but w permissions should not be given casually! Why can't w be given casually? let's look at the next example:
Example:
Suppose you have an account named dmtsai, and his home directory has [rwx] permission in / home/dmtsai/,dmtsai. 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 19 23:20 the_root.data
What are the permissions of dmtsai on this file? Can I delete this file?
A:
As shown above, because dmtsai is' others''to this file, he cannot read, edit, or execute the file, that is, he cannot change the contents of the file.
But because this file is in his home directory, he has full permissions for rwx in this directory, so for the 'file name' of the_root.data, he can 'delete'! The conclusion is that the user dmtsai can delete the the_root.data file!
Still don't understand? Do you understand or not? It doesn't matter ~ Let's design an exercise so that you can actually play with it, and you should be able to get closer to the situation! However, since we have not yet taught many instructions, some of the following instructions can be understood first, and we will continue to introduce the detailed usage of the instructions later.
* first establish the required file and directory environment with the identity of root
We use the identity of root to create a directory called testing in the / tmp directory where everyone can work, with permissions of 744 and directory owner root. In addition, create an empty file, also named testing, in the testing directory. You can use mkdir (make directory) to create directories and touch to create empty files (described in the next chapter). So the process is as follows:
The code is as follows:
[root@www ~] # cd / tmp
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.