For questions on how programs deal with the NULL character ("\0" or "0x00"), or the special "/dev/null" device to which program output can be redirected so that it disappears.
Questions tagged [null]
54 questions
268
votes
6 answers
redirecting to /dev/null
I'm reading an example bash shell script:
#!/bin/bash
# This script makes a backup of my home directory.
cd /home
# This creates the archive
tar cf /var/tmp/home_franky.tar franky > /dev/null 2>&1
# First remove the old bzip2 file. Redirect…
JohnMerlino
- 5,941
- 11
- 34
- 38
116
votes
9 answers
Why is /dev/null a file? Why isn't its function implemented as a simple program?
I am trying to understanding the concept of special files on Linux. However, having a special file in /dev seems plain silly when its function could be implemented by a handful of lines in C to my knowledge.
Moreover you could use it in pretty much…
Ankur S
- 1,208
- 2
- 7
- 17
43
votes
1 answer
How do I use null bytes in Bash?
I've read that, since file-paths in Bash can contain any character except the null byte (zero-valued byte, $'\0'), that it's best to use the null byte as a separator. For example, if the output of find will be sent to another program, it's…
ruakh
- 1,457
- 1
- 13
- 15
26
votes
1 answer
Why don't reads from /dev/zero count as IO_RBYTES?
I am emptying out a hard drive on some Linux 4.x OS using this command:
sudo sh -c 'pv -pterb /dev/zero > /dev/sda'
And I opened another tty and started sudo htop and noticed this:
PID USER PRI NI CPU% RES SHR IO_RBYTES IO_WBYTES S …
iBug
- 3,428
- 1
- 24
- 57
25
votes
2 answers
Why does tar appear to skip file contents when output file is /dev/null?
I have a directory with over 400 GiB of data in it. I wanted to check that all the files can be read without errors, so a simple way I thought of was to tar it into /dev/null. But instead I see the following behavior:
$ time tar cf /dev/null .
real…
Ruslan
- 3,290
- 3
- 28
- 49
24
votes
3 answers
mv a file to /dev/null breaks dev/null
If I do: touch file; mv file /dev/null as root, /dev/null disappears. ls -lad /dev/null results in no such file or directory. This breaks applications which depend on /dev/null like SSH and can be resolved by doing mknod /dev/null c 1 3; chmod 666…
Gregg Leventhal
- 7,480
- 19
- 65
- 100
15
votes
2 answers
Create virtual block device which writes to /dev/null
I want to test some physical links in a setup. The software tooling that I can use to test this require a block device to read/write from/to. The block devices I have available can't saturate the physical link so I can't fully test it.
I know I can…
John Smith
- 337
- 2
- 8
10
votes
1 answer
Send null byte in unix pipe
I am trying to redirect python generated input to ELF 64-bit executable in bash 5.0.3. I am getting:
> ./bf <<< $(python2 -c "print('c'*6+b'\x00'+'c'*6)")
bash: warning: command substitution: ignored null byte in input
Enter password: Password…
PaxPrz
- 255
- 2
- 10
10
votes
4 answers
Using/reading/writing the null and escape characters
I know that a filename in Linux has no restriction whatsoever except for two characters '/' and '\0'. I know that '/' is prohibited because it is a directory separator but is there any other reason ?
Also on my terminal I can create a file or a…
alkabary
- 1,429
- 5
- 19
- 37
7
votes
3 answers
Using binary data as a parameter in bash - any way to allow nuls?
So I'd like to pass the first 512 bytes of binaryFile.dd as the second parameter to myProgram but bash strips out all the NUL chars. Is there any way to avoid this in bash or am I on a hiding to nothing?
myProgram parameter1 "$(head -c 512…
Roger Heathcote
- 303
- 3
- 9
6
votes
2 answers
Are shells allowed to ignore NUL bytes in scripts?
Because that's what some of them are doing.
> echo echo Hallo, Baby! | iconv -f utf-8 -t utf-16le > /tmp/hallo
> chmod 755 /tmp/hallo
> dash /tmp/hallo
Hallo, Baby!
> bash /tmp/hallo
/tmp/hallo: /tmp/hallo: cannot execute binary file
> (echo '#';…
user313992
6
votes
6 answers
How to use the NUL character as a separator in sed substitute and delete commands?
This is what I tried, when intending to replace /path/to/a with /path/to/b using NUL as the separator/delimiter:
$ cat pathsList| sed -r -e 's\0/path/to/a\0/path/to/b\0g'
sed: -e expression #1, char 27: number option to `s' command may not be…
Harry
- 802
- 2
- 9
- 21
6
votes
6 answers
Remove null bytes from the end of a large file
I just backed up the microSD card from my Raspberry Pi on my PC running a Linux distro using this command:
dd if=/dev/sdx of=file.bin bs=16M
The microSD card is only 3/4 full so I suppose there's a few gigs of null bytes at the end of the…
iBug
- 3,428
- 1
- 24
- 57
6
votes
3 answers
How to prevent word splitting without preventing empty string removal?
I need to pass as a program argument a parameter expansion. The expansion results in a filename with spaces. Therefore, I double-quote it to have the filename as a single word: "$var".
As long as $var contains a filename, the program gets a…
ARX
- 447
- 1
- 4
- 15
6
votes
3 answers
Are there "esoteric" (weird) but standards-compliant C compilers or runtimes?
As we know, the C standard does not specify a lot of details of the implementation, for example value of NULL pointer, order of bits and bytes (endiannes), alignment in structs and of stack parameters, actual organization of memory (I don't think…
user62537
- 61
- 1