Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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
35 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 ...
user avatar
  • 1
2 votes
1 answer
176 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 ...
user avatar
  • 155
0 votes
1 answer
185 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 ...
user avatar
1 vote
0 answers
52 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 ...
user avatar
1 vote
1 answer
85 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 ...
user avatar
  • 111
0 votes
1 answer
157 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 ...
user avatar
  • 66.7k
0 votes
1 answer
118 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 . -...
user avatar
  • 1,374
0 votes
1 answer
308 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 ...
user avatar
1 vote
1 answer
2k 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 ...
user avatar
  • 175
1 vote
1 answer
182 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)....
user avatar
2 votes
3 answers
368 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 ...
user avatar
  • 10.6k
10 votes
1 answer
2k 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 ...
user avatar
  • 255
0 votes
1 answer
2k 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 ...
user avatar
  • 111
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
264 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 "...
user avatar
  • 589
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 ...
user avatar
0 votes
1 answer
132 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?
user avatar
0 votes
1 answer
297 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=...
user avatar
  • 1,530
2 votes
2 answers
784 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": "...
user avatar
  • 177
2 votes
2 answers
113 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....
user avatar
  • 1,287
0 votes
1 answer
710 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 ...
user avatar
  • 310
22 votes
2 answers
2k 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 ...
user avatar
  • 2,949
0 votes
0 answers
76 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 ...
user avatar
2 votes
5 answers
521 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 ...
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 ...
user avatar
  • 2,902
1 vote
0 answers
279 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\ ...
user avatar
  • 115
4 votes
1 answer
758 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 ...
user avatar
2 votes
5 answers
4k 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 ...
user avatar
  • 722
116 votes
9 answers
24k 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 ...
user avatar
  • 1,198
1 vote
1 answer
607 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]...
user avatar
4 votes
6 answers
4k 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 ...
user avatar
  • 2,902
1 vote
2 answers
2k 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/...
user avatar
  • 2,556
0 votes
1 answer
3k 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?
user avatar
  • 41
7 votes
3 answers
4k 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 ...
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 $...
user avatar
  • 407
5 votes
1 answer
8k 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: #!/...
user avatar
  • 723
0 votes
2 answers
14k 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 ...
user avatar
4 votes
2 answers
114 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 ...
user avatar
  • 1,571
2 votes
2 answers
88 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 <...
user avatar
0 votes
3 answers
287 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 ...
user avatar
9 votes
4 answers
34k 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 ? ...
user avatar
  • 1,349
5 votes
2 answers
18k 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 ...
user avatar
  • 551
41 votes
1 answer
34k 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 ...
user avatar
  • 1,407
0 votes
2 answers
1k views

How do I enable &>/dev/null by default for all sh/bash commands?

Is there a way to make &>/dev/null the default behavior in a sh/bash script? I' rather not have to appended this to every command within the console, not an *.sh script. I'm looking to make a ...
user avatar
246 votes
7 answers
591k views

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&...
user avatar
  • 5,401
6 votes
3 answers
742 views

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,...
user avatar
24 votes
3 answers
8k views

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 ...
user avatar