Standard output input device stdin
Detailed analysis of Linux shell data redirection (input redirection and output redirection). They correspond to several special file descriptors, FD0,FD1,FD2 (Stdin,stdout,stderr)
Such as:
[Email protected] shell]$ Cat>teststdin</dev/stdin
Test
#ctrl +d
#cat从/dev/stdin get the data and then the standard output, the input to the Teststdin file
[email protected] shell]$ cat Teststdin
Test
[Email protected] shell]$ Cat>teststdin
Test
#ctrl +d
#不指定输入, the default input device is/dev/stdinn
/dev/stdin means a keyboard device.
[email protected] shell]$ cat test.sh >/dev/stdout |grep ' echo '
echo "Very good!";
echo "good!";
echo "pass!";
echo "No pass!"
#/dev/stdout point is the standard output, so redirect the data to it and eventually send it to the screen (FD1)
[email protected] shell]$ cat test.sh |grep ' echo '
echo "Very good!";
echo "good!";
echo "pass!";
echo "No pass!";
[email protected] shell]$ cat test.sh >/dev/stderr |grep ' echo '
#!/bin/sh
scores=40;
if [[$scores-GT 90]]; Then
echo "Very good!";
elif [[$scores-GT 80]]; Then
echo "good!";
elif [[$scores-GT 60]]; Then
echo "pass!";
Else
echo "No pass!";
Fi
#/dev/stderr refers to the error output, which is output to the screen by default, but its contents cannot be piped to grep and the pipeline can only pass standard output
/dev/null Equipment
is a black hole device that discards everything written to it, and an empty device is often used to discard unwanted output streams. Remember when using Windows, there was a similar device: NUL, as with this function. Any data written to the device will be discarded. Reading the data from this inside returns is empty. Send some unused content to this device frequently, discarding unwanted data.
Such as:
[Email protected] shell]$ Cat/dev/null
[email protected] shell]$ cat test.sh >/dev/null
#读该设备为空, the data written to the device is discarded.
/dev/zero Equipment
In the Unix-like operating system,/dev/zero is a special file that, when you read it, provides unlimited null characters (null, ASCII NUL, 0x00). One typical usage is to overwrite information with a stream of characters it provides, and another common use is to produce a blank file of a specific size.
Such as:
[[email protected] shell]$ dd If=/dev/zero of=testzero count=1024 bs=1024
1024+0 Records in
1024+0 Records out
1048576 bytes (1.0 MB) copied, 0.0107194 seconds, 97.8 MB/s
#创建一个大小为1M文件, the file is a block of 1024 bytes, altogether 1024 blocks (just 1M), populated with/dev/zero file content. Output created to: Testzero file
[[email protected] shell] $DD if=/dev/zero of=/dev/disk partition
#这个命令一定不要随便用, a bit like the Smash file tool inside Windows. However, it fills the entire partition with \0x00. This data is not recoverable.
[[email protected] shell] $cat/dev/zero>testinputzero
#这个命令也不能随便使用咯,/dev/zero device A special effect is that if you read it, a dead loop will output an infinite \x00, so you will create a file filled with \x00. If you do not limit the user's disk quotas. It will drain the entire disk space.
In the Linux resource quota limit, if there is no current user's disk space utilization, or memory usage. An ordinary user can fill the entire disk with one of the above methods. You can also pass the while (true) {fork ...} Class program that starts an infinite thread and consumes the entire system memory.
/dev/full Equipment
In Unix-like systems,/dev/full (Sheung Moon Device) is a special device file that always returns no space (error code of ENOSPC) to the device when writing to it, and reads like/dev/zero, returning an infinite number of NULL characters (NULL, ASCII NUL, 0x00). This device is often used to test the behavior of a program when it encounters a disk with no remaining space errors.
Such as:
[Email protected] shell]$ echo ' Chengmo ' >/dev/full
-bash:echo:write Error: There is no space on the device
[[email protected] shell]$ echo $?
#命令执行返回错误
/dev/random [Urandom]
In Unix-like operating systems,/dev/random is a special device file that can be used as a random number generator or as a pseudo-random number generator. It allows programs to access background noise from device drivers or other sources. Commonly used as a random number generator. Specific reference: Linux shell Implementation of random number of methods (DATE,RANDOM,UUID)
/dev/fd Record user-opened file descriptors
[Email protected] shell]$ ls/dev/fd/
0 1 2 3
Detailed reference:
Linux shell data Redirection (input redirection and output redirection) detailed analysis file descriptor description.
/dev/tcp[udp]/host/port
Reading this type of device, a tcp[upd] connection will be created that connects to the host port. Open a socket communication interface.
For detailed use, refer to:
Linux shell script implements TCP/UPD protocol communication (redirected app)
/dev/loop
In Unix-like operating systems, loop devices can be used to mount loop files as block devices.
Such as:
[[email protected] shell] $mount-O loop example.img/home/chengmo/img
#将img镜像文件挂载到/home/chengmo/img directory, with this device, we do not need to be able to read the virtual disk format files through the virtual optical drive.
Linux/dev Special Equipment and use