A linux command a day (24): Linux file types and extensions

Linux file types and Linux file file names represent two different concepts. We create through general applications such as file.txt, file.tar.gz, although these files need to be opened by different programs, but if they are measured in Linux file types, most of them are regular files (also known as ordinary files). document).
1.
File types Common file types in Linux are: ordinary files, directory files, character device files and block device files, symbolic link files, etc. Now we will give a brief description.
1. Ordinary file
We use ls -lh to view the attributes of a file, we can see that there are similar to -rwxrwxrwx, it is worth noting that the first symbol is - , such a file is an ordinary file in Linux. These files are generally created with some related applications, such as image tools, document tools, archive tools... ...... or cp tools and so on. The way to delete such files is to use the rm command. In addition, according to the content of the file, it can be roughly divided into:
1>. Plain text file (ASCII): #p#page title#e#
This is the most common file type in Linux systems, and it is called a plain text file because the content For us humans can directly read data, such as numbers, letters and so on. Almost every file we can use as a setting belongs to this file type. For example, you can use the command: cat ~/.bashrc to see the contents of this file. (cat is an instruction to read out the contents of a file).
2>. Binary file (binary): The
Linux system actually only recognizes and can execute binary file (binary file). Executable files in Linux (scripts, text batch files are not counted) are files in this format. The command cat just used is a binary file.
3>. Data format file (data):
Some programs will read files in certain specific formats during operation, and those files in specific formats can be called data files. For example, when a user logs in #p#page title#e#, our Linux will record the logged data in the file /var/log/wtmp, which is a data file, which can be accessed through last Read this command! But when using cat, it will read garbled characters ~ because it belongs to a special format file?

2. Directory file
When we execute in a directory, we see that there is something like drwxr-xr-x, such a file is a directory, and a directory is a special file in Linux. Note that its first character is d. The command to create a directory can use the mkdir command, or the cp command, which can copy a directory to another directory. Delete with the rm or rmdir command.

3. Character device or block device file
If you enter the /dev directory and list the files, you will see something like the following:
[root@localhost ~]# ls -al /dev/tty
crw-rw-rw- 1 root tty 5, 0 11-03 15:11 /dev/tty
[root@localhost ~]# ls -la /dev/sda1#p#page title#e#
brw-r----- 1 root disk 8, 1 11- 03 07:11 /dev/sda1
We see that the attribute of /dev/tty is crw-rw-rw-, notice that the first character in front is c, which means the character device file. Such as serial devices such as cats. We see that the attribute of /dev/sda1 is brw-r-----, notice that the first character in front is b, which means block device, such as hard disk, CD-ROM and other devices.
This type of file is created with mknode and deleted with rm. Currently in the latest Linux distributions, we generally do not need to create device files ourselves. Because these files are associated with the kernel.
Some files related to system peripherals and storage are usually concentrated in the /dev directory! Usually divided into two types:
block (block) device files:
some interface devices that store data to provide random access to the system, for example, hard disks and floppy disks! You can read and write randomly in different blocks of the hard disk, this kind of device is a group device! You can check /dev/sda by yourself, and you will find that the first attribute is [b]!
Character (character) device file:
that is, some serial port interface devices, such as keyboard, mouse, etc.! The characteristic of these devices is that they are read once and cannot truncate the output. For example, you can't make the mouse jump to another screen, but swipe to another place! The first attribute is [ c ]. #p#Page title#e#

4. Data interface file (sockets):
Data interface file (or: socket interface file), this type of file is usually used to undertake data on the network. We can start a program to monitor the client's request, and the client can communicate data through this socket. The first attribute is [ s ], which is the file type most commonly seen in the /var/run directory.
For example: When we start the MySQL server, a mysql.sock file will be generated.
[root@localhost ~]# ls -lh /var/lib/mysql/mysql.sock
srwxrwxrwx 1 mysql mysql 0 04-19 11:12 /var/lib/mysql/mysql.sock
Note the first attribute of this file The character is s.

5. Symbolic link file:
When we look at the file properties, we will see something like lrwxrwxrwx, note that the first character is l, this type of file is a link file. is the new filename via ln -s sourcefilename. The above is an example, indicating that setup.log is a soft link file of install.log. How to understand it? This is somewhat similar to shortcuts in the Windows operating system. #p#Page title#e#
Example of how to create a symbolic link file:
[root@localhost test]# ls -lh log2012.log
-rw-r--r-- 1 root root 296K 11-13 06:03 log2012.log
[root@localhost test]# ln -s log2012.log linklog.log
[root@localhost test]# ls -lh *.log
lrwxrwxrwx 1 root root 11 11-22 06:58 linklog.log -> log2012.log
-rw -r--r-- 1 root root 296K 11-13 06:03 log2012.log

6. Data transmission file (FIFO, pipe):
FIFO is also a special file type, its main purpose is to solve multiple programs at the same time Errors caused by accessing a file. FIFO is short for first-in-first-out. The first attribute is [p]. #p#Pagination title#e#

2. Linux file extension
1. Extension type
Basically, Linux files have no so-called extension. Whether a Linux file can be executed or not is related to the ten attributes in its first column, and has nothing to do with the file name at all. This concept is different from the case of Windows! Under Windows, the file extension 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 this file can be executed.

However, being able to be executed is different from being able to be executed successfully. For example, the install.log in the root home directory is a plain text file. If the permission is changed to -rwxrwxrwx, can this file be executed successfully? ? Of course not ~ because his content has no executable data at all. So, this x means that the file has the ability to be executable, but whether it can be executed successfully depends on the content of the file.
Even so, we still hope to know what the file is by the extension. So, usually we still use the appropriate extension to indicate what kind of file is. There are several common extensions below:
*.sh : Script or batch file (scripts), because the batch file is written using the shell, so the extension is compiled into .sh
#p#page title#e#
*Z, * .tar, *.tar.gz, *.zip, *.tgz: Packed compressed files. This is because the compression software is gunzip, tar, etc., because of different compression software, whichever is related to the extension!
*.html, *.php: Web page related files, representing HTML syntax and PHP syntax respectively. The .html file can be opened directly with a web browser. As for the .php file, it can be browsed on the server side through the browser on the client side to get the calculated web page results.
Basically, a filename on a Linux system really just gives you an idea of ​​what the file might be used for, and the actual execution still requires a specification of permissions. For example, although there is a file that is executable, such as the common command /bin/ls that displays file attributes, if the permissions of this file are modified so that it cannot be executed, then ls will become unexecutable.
The above problem occurs most often during file transfers. For example, you download an executable file on the Internet, but it cannot be executed in your Linux system! Ha ha! Then it is possible that the attributes of the file have been changed. There is no doubt that the attributes and permissions of files will indeed be changed from the network to your Linux system.

2. Linux file #p# page title #e# name length limit:
Under Linux, when using the default Ext2/Ext3 file system, the file name length limit is:
the maximum allowable file name of a single file or directory is 255 characters
A full filename including the full pathname and directory (/)
is long filename! We hope that the file name of Linux can know what the file is doing at a glance, so the file name is usually very long.

3. Character limitation of Linux file name:
Due to some command operations 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 special meaning under the literal interface. In addition, the beginning of the file name is a decimal point#p#page title# e#"." means that the file is a hidden file! At the same time, because options such as -option are often used in the command, you'd better avoid naming the file name with - or + at the beginning.


Reprinted in: http://www.itxuexiwang.com/a/liunxjishu/2016/0307/270.html?1457430001

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327072053&siteId=291194637