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

What are the special files under Linux

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article analyzes "What are the special files under Linux". The content is detailed and easy to understand. Friends interested in "what are the special files under Linux" can read it slowly and deeply along with the ideas of Xiaobian. I hope it can help everyone after reading. Let's learn more about "What are the special files under Linux" together with Xiaobian.

We all know that everything under Linux is a file, mainly

ordinary file d directory l symbolic link s socket b block device c character device p pipe

These kinds of documents.

The prefix characters here can be observed with the ls command:

$ ls -l test.log-rw-r--r-- 1 root root 33 Nov 17 17:03 test.log

It starts with-, so it's a normal file.

$ ls -al /dev/nullcrw-rw-rw- 1 root root 1, 3 Sep 11 20:33 /dev/null

Its result is preceded by c, so it is a character device.

The document briefly introduces several character device files, which can provide good help when we test the function.

/dev/null

/dev/null can receive unlimited data, you can think of it as a black hole, so if we need to discard some terminal output, we can redirect it here:

$ echo "shouwangxiansheng" > /dev/null

So if you have data you don't need, feel free to write it here.

/dev/full

It reads a continuous stream of NUL bytes when reading, and returns full disk space when writing,

The latter is helpful when testing your program, i.e. testing the disk-full scenario:

$ echo "bianchengzhuji" > /dev/full-bash: echo: write error: No space left on device

/dev/zero

Similar to/dev/null, writing to it discards all data, but reading it produces a stream of NUL (zero-valued) bytes.

$ cat /dev/zero |od -x 0000000 0000 0000 0000 0000 0000 0000 0000 0000

/dev/random

/dev/random can provide a random stream of data, which guarantees randomness of the data, but causes waiting when reading, for example

$ cat /dev/random | od -x0000000 2b07 daac 42f4 e1fd fb62 2098 870e e0af0000020 3022 2099 e5da 4e1c d6db 548b a979 12170000040 3777 bb6a 957d 1279 ab29 e8a4 6a36 ecca0000060 39ec 2285 126c 30ea ea67 1526 5e4a 2dd9

The data doesn't appear until a while later, but for ease of viewing, we'll use the od command to view its hex content.

/dev/urandom

As the name suggests, it was used to generate random data. It is generated quickly, but the data is not as random as/dev/random

cat /dev/urandom | od -x0547560 f43e 696a 8936 2b27 36c8 4446 2802 1d470547600 b8af 249d aae9 edbf 8971 b1d1 0c73 3e2d0547620 237b 9a81 6348 cb2a 1972 4486 028a 35730547640 1690 c388 64e1 aec1 d5f4 1964 bbb9 192f0547660 f242 7194 51ba 62a3 fc13 ff53 fb50 e3d80547700 ef32 3658 b335 75ee 62de 4096 6468 c9790547720 01b9 c233 878d 12fc 5cfa 5691 89e1 e1f9

/dev/pts

/dev/pts is the directory where console device files created after remote login (telnet,ssh, etc.) are located. What's the point? For example, you open a terminal and get the current pts:

$ tty/dev/pts/0

Then you open another one and type:

$ echo "hahahaha">/dev/pts/0

You'll notice that the content has been printed to the previous terminal.

Usually we run a program whose printf prints on the current terminal.

In fact, there are many special files under/dev, but I won't introduce them one by one. The above special files can help us develop or test under certain circumstances.

Linux is a free-to-use and freely distributed UNIX-like operating system, is a POSIX-based multi-user, multitasking, multi-threaded and multi-CPU operating system, using Linux to run major Unix tools, applications and network protocols.

What are the special files under Linux to share here, I hope the above content can make everyone improve. If you want to learn more, please pay more attention to the updates of Xiaobian. Thank you for your attention to the website!

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: 230

*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

Development

Wechat

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

12
Report