Questions tagged [null]

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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
34 views

What does it mean if /dev/null is not a character device? [duplicate]

I'm experiencing "weird" behavior on a Linux PC -- I don't know how to qualify the problem exactly, other than that it seems to have something to do with /dev/null, based on the error ...
StoneThrow's user avatar
  • 1,615
1 vote
1 answer
224 views

Error redirection fail with bind - dig

I'm trying to test some nameservers against a domain name. For that, I created a script that reads a list of nameservers and asks for a domain name. Something basic like this: #!/bin/bash domain=$1 [ ...
markfree's user avatar
  • 325
3 votes
4 answers
444 views

Empty string breaks command line

I am having trouble trying to describe my issue. Please bear with me. I have a script that calls a command. I need to optionally include an extra argument in the command line depending on the input ...
Brendan's user avatar
  • 29
0 votes
1 answer
220 views

Trying to rotate logs however tee command fails to return after execution

My logs nohup.out is owned by root user while I m trying to rotate the logs using system which has privileged access using sudo I have written the below script to rotate logs. cat rotatelog.sh cp /var/...
Ashar's user avatar
  • 489
0 votes
1 answer
196 views

Why is /dev/null needed to run asynchronous jobs in busybox sh?

I'm curious why this special device is needed to fork the command and run it asynchronously in the minimal Busybox shell. BusyBox v1.30.1 (Debian 1:1.30.1-4) built-in shell (ash) Enter 'help' for a ...
round-down's user avatar
1 vote
0 answers
177 views

How to suppress php output in one-line chained terminal command

I use the following &&-chained one-line command in Linux terminal (Ubuntu desktop): cd /opt/lampp/htdocs/detailed_payouts && for FILE in *; do dos2unix $FILE; done && php /opt/...
mercurio's user avatar
-1 votes
1 answer
63 views

Can any one explain what the purpose of this "dd" command that writes to /dev/null is?

dd if=/dev/sda7 of=/dev/null bs=1024 skip=276892816 count=420 iflag=direct We are having some issues backing up a Linux server. Anyone, please explain to me what this command does in that case. ...
Deep Saha's user avatar
0 votes
0 answers
532 views

"> $logfile" does not truncate, file size goes to 0 and a second later, is back to full size [duplicate]

I have a script that writes to a logfile like this: $ nohup myscript.sh > myscript.out 2>&1 & when the log file gets very large, I need to truncate it like this: > myscript.out I ...
chiwal's user avatar
  • 1
3 votes
1 answer
742 views

awk with null record separator printing just one file

How does the following code print just a single file? find "$fdir" -type f -name "${fnam}-*.png" -print0 | awk -v RS='\0' -F'[-.]' '{print $(NF-1), $0}' | cat -vet which gives me ...
Vera's user avatar
  • 1,183
0 votes
1 answer
807 views

null characters at the beginning of an ASCII log file

We have an java application that log4j2 to generate log file and have script to stop the process before restart it with another script. There is 5 minutes pause between stop and restart at the ...
lap luu's user avatar
1 vote
0 answers
179 views

How do I set up null-sink and capture to route audio into camilladsp?

I am trying to set up an assistant on my raspberry pi, but I need the audio to route through camilladsp before it's outputted to my DAC. I figured a pulseaudio null-sink and null-sink capture would be ...
Elliott Dyson's user avatar
1 vote
1 answer
130 views

How to empty a file with terminal?

All my sites include a script that saves in a file all the fake google IPs that are not in google IP range. Then with a script once a day I add all the IPs to the firewall. while read line; do sudo ...
alebal's user avatar
  • 111
2 votes
1 answer
632 views

bash mapfile NUL bug?

bash's mapfile seems to be broken when handling NUL separated input. In particular, it isn't handling minus characters (-) correctly, treating the empty string after one as an end-of-line marker. For ...
cas's user avatar
  • 77.7k
0 votes
1 answer
341 views

Why xargs -0 adds an extra blank line?

In the example, why xargs -0 adds an extra blank line, and how to avoid it? $ touch a b c $ find . -print0 ../a./c./b $ find . -print0 | sort --zero-terminated | xargs -0 . ./a ./b ./c $ find . -...
Porcupine's user avatar
  • 1,802
0 votes
1 answer
871 views

Remove all zero bytes from file in Unix

I've got a file of data from a prototype hardware RNG, however, for some reason it's producing a lot of 0x00 bytes. I want to delete all of these 0x00 bytes so I can test if the rest of the data is ...
ScottishTapWater's user avatar
1 vote
1 answer
4k views

If Bash arrays can't contain a null string, how does this array do it?

I've recently discovered that you can't pass a null string to a Bash array. This is tricky, as I'm trying to insert an empty string value into an array. I've noticed that the Bash completion variable ...
Lou's user avatar
  • 205
1 vote
1 answer
332 views

how to write a pgrep pattern that (never) matches a zero byte?

I'd like to kill a process with a long name that ends with foo. Currently my plan is to use pkill (though for testing, to be friendly to the process, I've been checking my patterns with pgrep instead)....
Daniel Wagner's user avatar
2 votes
3 answers
787 views

awk: Exact string match on field not working with NUL as record separator

Given a file with newlines in fields (embedded by double quotes), I tried to use NUL as record separator and then select desired records. For this I have replaced the ends of lines with NUL and then ...
FelixJN's user avatar
  • 13.3k
10 votes
1 answer
4k views

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 ...
PaxPrz's user avatar
  • 255
2 votes
1 answer
3k views

Docker: bash: /dev/null: Permission denied

I use docker to unpack a linux chroot and then execute commands into it, but I get this inside the chroot. echo ciao > /dev/null bash: /dev/null: Permission denied I thought that the null device ...
LtWorf's user avatar
  • 141
6 votes
2 answers
1k views

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 /...
user avatar
0 votes
5 answers
346 views

How to monitor changes in file filled by null bytes?

I have a 10Mb file filled by null bytes. A program is accessing it and changes zeros to specific strings up to the end of the file. I've tried to use tail -F | grep wanted_text | grep -v "...
Gryu's user avatar
  • 819
15 votes
2 answers
2k views

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 ...
John Smith's user avatar
0 votes
1 answer
414 views

How to nullify the /var/log/message file as a normal user

Is it possible to truncate the /var/log/messages file as a normal user? If yes what permissions do we need to mention in sudoers file for this?
Khadeer Ahammad's user avatar
0 votes
1 answer
454 views

command stdout to /dev/null

I have very simple command which generating STDOUT which i want to do /dev/null but somehow it's not working or i am missing something here. $ ldapsearch -Y GSSAPI -b "cn=users,cn=accounts,dc=...
Satish's user avatar
  • 1,632
2 votes
2 answers
2k views

Printing only the value and excluding null

I'm trying to print the json output using jq, But I'm getting null How can I print only access_key and secret_key, but not null? $ cat sample.json | jq '.' { "access_key": "...
Swat's user avatar
  • 177
2 votes
2 answers
215 views

Remove values from NUL separated file

I have an array of values v that I want to remove from the file f. f is NUL delimited. How do I proceed? I tried using sd, but it didn't work. Example: I have this file: # cat -v $attic ^@this is 1....
HappyFace's user avatar
  • 1,543
1 vote
1 answer
2k views

How to assign a zero-length, non-null string

Based on this, amongst many other things I've read, my understanding is that a='' makes a both null and zero-length. But, then, how does one create a zero-length, non-null string? Or, is there no ...
TTT's user avatar
  • 370
25 votes
2 answers
3k views

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 ...
Ruslan's user avatar
  • 3,310
0 votes
0 answers
126 views

Compare file compression methods by sending to /dev/null

I'd like to compare the time to completion for compression algorithms and parameters. I'm confident that the inputs will be set up properly. In order to save space and avoid some variability my ...
Aaron Thomas's user avatar
2 votes
5 answers
826 views

remove all lines with nullbytes/corrupt data

So I recovered a text file from an old hdd, but I failed to completely recover all of the data. The data that wasn't correctly recovered has returned as null bytes. How can I remove every line from ...
user339364's user avatar
26 votes
1 answer
3k views

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 ...
iBug's user avatar
  • 3,468
1 vote
0 answers
390 views

Odd Characters in Log File

I checked my cron log files today for a script that I have scheduled and the saw the following errors/characters: \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\ ...
arnpry's user avatar
  • 125
4 votes
1 answer
1k views

With gnu find, what is the difference between -print0 and -printf "%p\0"

In a terminal I can run... find . -type f -print0 ./testdir/testfile2.txt./testdir/testfile.txt And then... find . -type f -printf "%p\0" ./testdir/testfile2.txt./testdir/testfile.txt They both ...
user605331's user avatar
6 votes
6 answers
8k views

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 ...
Harry's user avatar
  • 812
117 votes
9 answers
25k views

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 ...
Ankur S's user avatar
  • 1,218
1 vote
1 answer
835 views

random “NULL character(s) present” error in exim

Sometimes we are getting NULL character(s) present errors on incoming mail. It looks like this: 2018-03-01 12:26:51.244 [22933] SMTP syntax error in "RCPT TO:" H=mail-wm0-f56.google.com [74.125.82.56]...
Alex Dyukov's user avatar
6 votes
6 answers
7k views

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 ...
iBug's user avatar
  • 3,468
1 vote
2 answers
3k views

Working with /dev/null with cat or cp vs touch

In a tutorial about public key infrastructure the author sets up a database to work with when setting up a Root Certificate Authority: cp /dev/null ca/root-ca/db/root-ca.db cp /dev/null ca/root-ca/db/...
mbigras's user avatar
  • 2,958
0 votes
1 answer
5k views

What happens when you write to /dev/null? What’s the point? [duplicate]

Tried echo "Some text" >> /dev/null then cat null with no output. Can someone explain why this is?
Mas's user avatar
  • 31
7 votes
3 answers
5k views

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 ...
Roger Heathcote's user avatar
6 votes
3 answers
2k views

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 $...
ARX's user avatar
  • 447
4 votes
1 answer
9k views

Can I safely ignore: "warning: command substitution: ignored null byte in input"?

Is it possible to safely ignore the aforementioned error message? Or is it possible to remove the null byte? I tried removing it with tr but I still get the same error message. this is my script: #!/...
jes516's user avatar
  • 803
1 vote
2 answers
18k views

cp large file to /dev/null to reduce size to zero [closed]

I just came across the advice that if you want to get rid of a large file and a process has the file handle open you should copy it to /dev/null and its size will be reduce to zero. How does this ...
user2393256's user avatar
4 votes
2 answers
142 views

Invert matching lines, NUL-separated

I’m writing something that deals with file matches, and I need an inversion operation. I have a list of files (e.g. from find . -type f -print0 | sort -z >lst), and a list of matches (e.g. from ...
mirabilos's user avatar
  • 1,723
2 votes
2 answers
94 views

How can I get FreeBSD `patch` to tolerate null bytes?

The patch of the final line fails on FreeBSD 10.2, but works on GNU: #!/bin/sh echo a > f1 printf '\0' >> f1 echo c >> f1 cp f1 f2 echo d >> f2 diff -au f1 f2 > diff patch <...
Janus Troelsen's user avatar
-1 votes
3 answers
394 views

Null value than rename file

I have a shell to a task but I should handle the null value in this. So in the task i cut the part of a word and i delete or rename the file, but need another if element for null. For example: I ...
KisPogesz's user avatar
10 votes
4 answers
41k views

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 ? ...
alkabary's user avatar
  • 1,469
5 votes
2 answers
21k views

Meaning of `cat /dev/null > file`

In a document created by a former coworker there is this command: cat /dev/null > /var/spool/mail/root It says next to it that it will clean out mailbox. Can someone please explain how/why ...
AllisonC's user avatar
  • 721
44 votes
1 answer
40k views

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 ...
ruakh's user avatar
  • 1,477