Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand and identify file types in Linux

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Preface

As we all know, everything in Linux is a file, including hard drives and graphics cards. When navigating in Linux, most of the files are normal files and directory files. But there are other types, corresponding to five different types of functions. Therefore, it is important in many ways to understand the file types in Linux.

If you don't believe it, just browse through the full text and you'll see how important it is. If you can't understand the file type, you can't make any changes without fear.

If you make some wrong changes that will damage your file system, please be careful when you do it. Files are very important in Linux systems because all devices and daemons are stored as files.

How many types are available in Linux?

As far as I know, there are seven types of files in Linux, which are divided into three main categories. The details are as follows.

Ordinary document

Catalog file

Special files (this class has 5 file types)

Link file

Character device file

Socket file

Name a pipe file

Block file

Refer to the table below for a better understanding of the file types in Linux.

Symbolic meaning-ordinary file. The long list begins with an underscore. D directory file. The long list begins with the letter d. L link the file. The long list begins with the letter l. C character device file. The long list begins with the letter c. SSocket file. The long list begins with the letter s. P name the pipe file. The long list begins with the letter p. B block file. The long list begins with the letter b.

Method 1: manually identify file types in Linux

If you know Linux well, you can easily identify file types with the above table.

How to view ordinary files in Linux?

Use the following command in Linux to view normal files. Normal files can appear anywhere in the Linux file system. The color of ordinary documents is "white".

# ls-la | grep ^-- rw-. 1 mageshm mageshm 1394 Jan 18 15:59 .bash _ history-rw-r--r--. 1 mageshm mageshm 18 May 11 2012 .bash _ logout-rw-r--r--. 1 mageshm mageshm 176 May 11 2012 .bash _ profile-rw-r--r--. 1 mageshm mageshm 124 May 11 2012 .bashrc-rw-r--r--. 1 root root 26 Dec 27 17:55 liks-rw-r--r--. 1 root root 104857600 Jan 31 2006 test100.dat-rw-r--r--. 1 root root 104874307 Dec 30 2012 test100.zip-rw-r--r--. 1 root root 11536384 Dec 30 2012 test10.zip-rw-r--r--. 1 root root 61 Dec 27 19:05 test2-bzip2.txt-rw-r--r--. 1 root root 61 Dec 31 14:24 test3-bzip2.txt-rw-r--r--. 1 root root 60 Dec 27 19:01 test-bzip2.txt

How to view catalog files in Linux?

Use the following command in Linux to view the directory file. Directory files can appear anywhere in the Linux file system. The color of the directory file is "blue".

# ls-la | grep ^ ddrwxr-xr-x. 3 mageshm mageshm 4096 Dec 31 14:24 links/drwxrwxr-x. 2 mageshm mageshm 4096 Nov 16 15:44 perl5/drwxr-xr-x. 2 mageshm mageshm 4096 Nov 16 15:37 public_ftp/drwxr-xr-x. 3 mageshm mageshm 4096 Nov 16 15:37 public_html/

How do I view linked files in Linux?

Use the following command in Linux to view the linked file. Linked files can appear anywhere in the Linux file system. There are two types of linked files available, soft links and hard links. The color of the linked file is "light emerald".

# ls-la | grep ^ llrwxrwxrwx. 1 root root 31 Dec 7 15:11 s-link-file-> / links/soft-link/test-soft-linklrwxrwxrwx. 1 root root 38 Dec 7 15:12 s-link-folder-> / links/soft-link/test-soft-link-folder

How to view character device files in Linux?

Use the following command in Linux to view the character device file. Character device files appear only in specific locations. It appears in the directory / dev. The color of the character device file is "yellow".

# ls-la | grep ^ c # ls-la | grep ^ ccrw-. 1 root root 5, 1 Jan 28 14:05 consolecrw-rw----. 1 root root 10, 61 Jan 28 14:05 cpu_dma_latencycrw-rw----. 1 root root 10, 62 Jan 28 14:05 crashcrw-rw----. 1 root root 29, 0 Jan 28 14:05 fb0crw-rw-rw-. 1 root root 1, 7 Jan 28 14:05 fullcrw-rw-rw-. 1 root root 10, 229 Jan 28 14:05 fuse

How to view block files in Linux?

Use the following command in Linux to view the block file. Block files appear only in specific locations. It appears in the directory / dev. The color of the block file is "yellow".

# ls-la | grep ^ bbrw-rw----. 1 root disk 7, 0 Jan 28 14:05 loop0brw-rw----. 1 root disk 7, 1 Jan 28 14:05 loop1brw-rw----. 1 root disk 7, 2 Jan 28 14:05 loop2brw-rw----. 1 root disk 7, 3 Jan 28 14:05 loop3brw-rw----. 1 root disk 7, 4 Jan 28 14:05 loop4

How do I view Socket files in Linux?

Use the following command in Linux to view the Socket file. Socket files can appear anywhere. The color of the Scoket file is pink. LCTT translation note: here and below, the original description of the location where Socket files and named pipe files can appear is incorrect and has been modified. )

# ls-la | grep ^ ssrw-rw-rw- 1root root0 Jan 5 16:36system_bus_socket

How do I view named pipe files in Linux?

Use the following command in Linux to view the named pipe file. Named pipe files can appear anywhere. The color of the named pipe file is "yellow".

# ls-la | grep ^ pprw-. 1 root root 0 Jan 28 14:06 replication-notify-fifo | prw-. 1 root root 0 Jan 28 14:06 stats-mail |

Method 2: how to use the file command to identify file types in Linux

The file command in Linux allows us to determine different file types. There are three test sets, and three sets of tests are conducted in this order: the file system test, the magic byte test, and the language test used to identify file types.

How to use the file command to view ordinary files in Linux

Simply type the file command on your terminal and follow the normal file. The file command will read the contents of the file provided and display the type of file exactly.

This is why we see different results for each ordinary file. Refer to the different results of the common files below.

# file 2daygeek_access.log2daygeek_access.log:ASCII text, with very long lines # file powertop.htmlpowertop.html:HTML document,ASCII text, with very long lines # file 2g-test2g-test:JSON data # file powertop.txtpowertop.txt:HTML document,UTF-8 Unicode text, with very long lines # file 2g-test-05-01-2019.tar.gz2g-test-05-01-2019.tar.gz:gzip compressed data, last modified: Sat Jan 5 18:22:20 2019, from Unix,original size 450560

How do I use the file command to view directory files in Linux?

Simply type the file command on your terminal and follow the directory. See the results below.

# file Pictures/Pictures/:directory

How do I use the file command to view linked files in Linux?

Simply type the file command on your terminal and follow the link file. See the results below.

# file loglog:symbolic link to/run/systemd/journal/dev-log

How do I use the file command to view character device files in Linux?

Simply enter the file command on your terminal and follow the character device file. See the results below.

# file vcsuvcsu:character special (7excel 64)

How do I use the file command to view block files in Linux?

Simply type the file command on your terminal and follow the block file. See the results below.

# file sda1sda1:block special (8excel 1)

How do I use the file command to view Socket files in Linux?

Simply enter the file command on your terminal and follow the Socket file. See the results below.

# file system_bus_socketsystem_bus_socket:socket

How do I use the file command to view named pipe files in Linux?

Simply enter the file command on your terminal and follow the named pipe file. See the results below.

# file pipe-testpipe-test:fifo (named pipe)

Method 3: how to use the stat command to identify file types in Linux?

The stat command allows us to check the file type or file system status. This utility provides more information than the file command. It displays a great deal of information about the file, such as size, block size, IO block size, Inode value, links, file permissions, UID, GID, file access / update and modification time and other details.

How do I use the stat command to view normal files in Linux?

Simply type the stat command on your terminal and follow the normal file. See the results below.

# stat 2daygeek_access.log File: 2daygeek_access.log Size: 14406929 Blocks: 28144 IO Block: 4096 regular fileDevice: 10301h/66305d Inode: 1727555 Links: 1Access: Uid: (1000 / daygeek) Gid: (1000 / daygeek) Access: 2019-01-03 430328867 + 0530Modify: 2019-01-03 14 purge 05purl 26.460328868 + 0530Change: 2019-01-03 14purl 05purl 26.460328868 + 2019-01-03 14purl 05purl 26.460328868 + 0530 Birth:-

How do I use the stat command to view directory files in Linux?

Simply enter the stat command on your terminal and follow the directory file. See the results below.

# stat Pictures/ File: Pictures/ Size: 4096 Blocks: 8 IO Block: 4096 directoryDevice: 10301h/66305d Inode: 1703982 Links: 3Access: (0755/drwxr-xr-x) Uid: (1000 / daygeek) Gid: (1000 / daygeek) Access: 2018-11-24 003 22 Gid 11.090000828 + 0530Modify: 2019-01-05 18 purl 27purl 01.546958817 + 0530Change: 2019-01-05 18Fringe 2701.546958817 + 0530 Birth:-

How do I use the stat command to view linked files in Linux?

Simply type the stat command on your terminal and follow the link file. See the results below.

# stat / dev/log File: / dev/log-> / run/systemd/journal/dev-log Size: 28 Blocks: 0 IO Block: 4096 symbolic linkDevice: 6h/6d Inode: 278 Links: 1Access: (0777/lrwxrwxrwx) Uid: (0 / root) Gid: (0 / root) Access: 2019-01-05 16 rides 31.0333447 + 0530Modify: 2019-01-05 1636 rides 30.766666768 + 0530Change: 2019-01-05 16 rides 30.766666768 + 0530 Birth:-

How do I use the stat command to view character device files in Linux?

Simply enter the stat command on your terminal and follow the character device file. See the results below.

# stat / dev/vcsu File: / dev/vcsu Size: 0 Blocks: 0 IO Block: 4096 character special fileDevice: 6h/6d Inode: 16 Links: 1 Device type: 7 Magic 40 access: (0660 Gid Gid: (5 / tty) Access: 2019-01-05 16 Gid 31.056666781 + 0530Modify: 2019-01-05 16RV 36RV 31.056666781 + 0530Change: 2019-01-05 16RWR 31.056666781 + 0530 Birth:-

How do I use the stat command to view block files in Linux?

Simply type the stat command on your terminal and follow the block file. See the results below.

# stat / dev/sda1 File: / dev/sda1 Size: 0 Blocks: 0 IO Block: 4096 block special fileDevice: 6h/6d Inode: 250 Links: 1 Device type: 8 Device type 1access: (0660 Gid) Gid: (994 / disk) Access: 2019-01-05 16 Gid 3631.596666806 + 0530Modify: 2019-01-05 16RV 3631.596666806 + 0530Change: 2019-01-05 16VR 36mer 31.596666806 + 0530 Birth:-

How do I use the stat command to view Socket files in Linux?

Simply enter the stat command on your terminal and follow the Socket file. See the results below.

# stat / var/run/dbus/system_bus_socket File: / var/run/dbus/system_bus_socket Size: 0 Blocks: 0 IO Block: 4096 socketDevice: 15h/21d Inode: 576 Links: 1Access: (0666According to Srwmerr RWML RW -) Uid: (0 / root) Gid: (0 / root) Access: 2019-01-05 16 Gid 36331 333 3482 + 0530Modify: 2019-01-05 16 Switzerland 3631 810000149 + 0530Change: 2019 -01-05 16 Birth 36R 31.810000149 + 0530:-

How do I use the stat command to view named pipe files in Linux?

Simply enter the stat command on your terminal and follow the named pipe file. See the results below.

# stat pipe-test File: pipe-test Size: 0 Blocks: 0 IO Block: 4096 fifoDevice: 10301h/66305d Inode: 1705583 Links: 1Access: (0644 daygeek) Gid: (1000 / daygeek) Gid: (1000 / daygeek) Access: 2019-01-06 0200 daygeek 3.040394731 + 0530Modify: 2019-01-06 0200 daygeek 03.040394731 + 0530Change: 2019-01-06 02purl 03.040394731

Summary

The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report