Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

3 votes
2 answers
302 views
Programs to visually verify the placement of null bytes by grep
I have been using the grep command with `--null`. grep --null -r -n -- "$pstr" "$pdir" The man page for my version of `grep` (on Mac OS Sequoia) says: > --null Prints a zero-byte after the file name. To identify exactly where the NULL byte (\0) is introduced in the output of a grep command (especial...
I have been using the grep command with --null. grep --null -r -n -- "$pstr" "$pdir" The man page for my version of grep (on Mac OS Sequoia) says: > --null Prints a zero-byte after the file name. To identify exactly where the NULL byte (\0) is introduced in the output of a grep command (especially with --null), I need to run some tools that can display non-printing and control characters in a visible or unambiguous way. What specific program can I use to identify and thus verify exactly where the NULL byte \0 is being introduced by grep without having to blindly rely upon the description in the grep documentation. All I can see is that without --null, the command gives something like: ./opcon.rc:1392:## For GLOB, the IF clause requires the Test Operator == ./opcon.rc:1393:## For REGX, the IF clause requires the Test Operator =~ ./opcon.rc:1401:## The Case Condition clause requires Shell Glob Patterns With --null, it looks like: ./opcon.rc1392:## For GLOB, the IF clause requires the Test Operator == ./opcon.rc1393:## For REGX, the IF clause requires the Test Operator =~ ./opcon.rc1401:## The Case Condition clause requires Shell Glob Patterns It got rid of the :, but it's not obvious what else it did.
Filangieri (179 rep)
Jun 9, 2025, 09:02 PM • Last activity: Jun 10, 2025, 10:08 PM
6 votes
7 answers
10377 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 27: number option to `s' command may not be zero **My wanting to go for `NUL`:** `NUL` and `/`...
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 zero **My wanting to go for NUL:** NUL and / are the only characters that are disallowed on ext4fs, and / is already used heavily as the pathname separator. Also, I want to avoid quoting and unquoting my data just to be able to used sed. If NUL can't be used as a delimiter (let's say), I'll be okay with any workaround better than quoting and unquoting of my data. $ sed --version sed (GNU sed) 4.4
Harry (824 rep)
Jul 31, 2018, 03:31 AM • Last activity: Jan 29, 2025, 10:36 AM
1 votes
1 answers
157 views
exim error: NUL character(s) present (shown as '?')
I'm getting the `NUL character(s) present` error on `exim`, similar to [this post][1], but since that post is too old, I'm following [Charles Davis suggestion][2] to create a new question. ``` $ tail -f /var/log/exim4/mainlog 2024-07-12 22:43:38 SMTP syntax error in "\026\003\001\002?\001?\001\374\0...
I'm getting the NUL character(s) present error on exim, similar to this post , but since that post is too old, I'm following Charles Davis suggestion to create a new question.
$ tail -f /var/log/exim4/mainlog

2024-07-12 22:43:38 SMTP syntax error in "\026\003\001\002?\001?\001\374\003\003"\365\bZ\327b\277\373\261\032\246\217\275R\314b\201b\351\253k\304\001\3343/256/243/005/215U/301/207/311/227N/306e2+/216/226/307/361?0/023/002/023/003/023/001/300+/300/?/236/314/251/314/250/300" H=localhost [::1] NUL character(s) present (shown as '?')'>\\213fn\263N\303\244 \256'z\226o\305eE\231.:\234>3\256\243\005\215U\301\207\311\227N\306e2+\216\226\307\361?0\023\002\023\003\023\001\300+\300/?\236\314\251\314\250\300" H=localhost [::1] NUL character(s) present (shown as '?')
2024-07-12 22:43:38 SMTP syntax error in "\300\024?9\300        \300\023?3?\234?5?/\3000\300,?=?j?8?2?\377\001?\001\203???\016?\f??     localhost?\v?\004\003?\001\002?" H=localhost [::1] NUL character(s) present (shown as '?')
2024-07-12 22:43:38 SMTP syntax error in "?\f?" H=localhost [::1] NUL character(s) present (shown as '?')
2024-07-12 22:43:38 SMTP syntax error in "?\035?\027?\036?\031?\030?#???\005?\005\001?????\026???\027???\r?*?(\004\003\005\003\006\003\b\007\b\b\b      \b" H=localhost [::1] NUL character(s) present (shown as '?')
2024-07-12 22:43:38 SMTP call from localhost [::1] dropped: too many syntax or protocol errors (last command was "?\035?\027?\036?\031?\030?#???\005?\005\001?????\026???\027???\r?*?(\004\003\005\003\006\003\b\007\b\b\b      \b", NULL)
Exim: 4.94.2-7+deb11u3.  version 4.94.2 #2 built 09-Jul-2024 09:01:33
Distro: Debian GNU/Linux 11 (bullseye)
Kernel: 5.15.83-1-pve
On terminal this works fine echo 'hi!' | mail -s "Sent from $(hostname) at $(date +"%F %T")" mail@example.com The problem arise when sending emails from a web app installed on the host (Koha ). How could I debug the issue to find out if the web app is sending invalid strings?
Pablo A (3196 rep)
Jul 15, 2024, 02:41 PM • Last activity: Jul 17, 2024, 12:41 PM
2 votes
4 answers
1699 views
How to POSIX-ly ignore "warning: command substitution: ignored null byte in input"?
Today, I was working with my Raspberry Pi 4 with Debian 12 Bookworm, and I found it odd, that some system text files, namely I needed these two: ```none /sys/firmware/devicetree/base/model /sys/firmware/devicetree/base/serial-number ``` were, upon reading and storing in a variable in `bash` like thi...
Today, I was working with my Raspberry Pi 4 with Debian 12 Bookworm, and I found it odd, that some system text files, namely I needed these two:
/sys/firmware/devicetree/base/model
/sys/firmware/devicetree/base/serial-number
were, upon reading and storing in a variable in bash like this:
rpi_model_name=$(cat /sys/firmware/devicetree/base/model)
rpi_serial_number=$(cat /sys/firmware/devicetree/base/serial-number)
producing the following warning
warning: command substitution: ignored null byte in input
I tried to get rid of the warning by redirecting stderr to /dev/null; for instance:
rpi_model_name=$(cat /sys/firmware/devicetree/base/model 2>/dev/null)
or
rpi_model_name=$(cat /sys/firmware/devicetree/base/model) 2>/dev/null
but we still get that annoying warning:
-bash: warning: command substitution: ignored null byte in input
I just have two shells installed, bash and dash. While dash behaves _normal_ as in without that warning; bash appears to be more _mouthful_ about this. So, at this point, I can't be sure if other shells _spit_ this or some similar warning too. My goal is to suppress this warning for all shells. I do not care about its origin or value, I just want it gone. The solution must be written POSIX-ly for portability.
Vlastimil Burián (30505 rep)
Jul 6, 2024, 07:47 PM • Last activity: Jul 15, 2024, 06:20 PM
2 votes
1 answers
1102 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]:59392 I=[185.78.30.71]:25 NULL character(s) present (shown as '?') 2018-03-01 13:07:10.371 [471...
Sometimes we are getting **NULL character(s) present** errors on incoming mail. It looks like this: 2018-03-01 12:26:51.244 SMTP syntax error in "RCPT TO:" H=mail-wm0-f56.google.com [74.125.82.56]:59392 I=[185.78.30.71]:25 NULL character(s) present (shown as '?') 2018-03-01 13:07:10.371 SMTP syntax error in "RCPT TO:" H=mail-vk0-f59.google.com [209.85.213.59]:34762 I=[185.78.30.71]:25 NULL character(s) present (shown as '?') 2018-03-04 16:48:37.084 SMTP syntax error in "??EHLO 102jamz.com" H=[78.90.185.253]:50824 I=[185.78.30.71]:25 NULL character(s) present (shown as '?') 2018-03-04 17:00:30.333 SMTP syntax error in "??EHLO 1stglobal.com" H=[168.103.12.254]:43198 I=[5.101.158.68]:25 NULL character(s) present (shown as '?') 2018-03-05 11:11:42.758 SMTP syntax error in "D?TA" H=mail-pf0-f176.google.com [209.85.192.176]:42851 I=[185.78.30.71]:25 NULL character(s) present (shown as '?') We have had successful transfers from hosts with these errors. The error only happens sometimes. It has different commands (ehlo / rcpt to / data ), different hosts. At the same time there are no errors in dmesg, so it has no correlation with hardware error. Some TCP fails? Don't know, it looks like "we miss 1 byte in big package", is it real case? Having 4 mail servers for incoming and 4/4 gets this error in some time. exim 4.90.1 linux kernel 4.7.10 exim under docker enviroment. docker 1.8.3, build f4bf5c7
Alex Dyukov (21 rep)
Mar 7, 2018, 11:24 PM • Last activity: Jul 13, 2024, 01:59 AM
6 votes
2 answers
19000 views
How do I make Bash not drop NUL bytes on input from command substitution?
I have this Linux shell command: echo $(python3 -c 'print("Test"+"\0"+"M"*18)') | nc -u [IP] [PORT] My intention is to pipe the output of the `print` statement to the netcat command. The netcat command creates a socket to some service that essentially returns an stdout of the string passed in. The p...
I have this Linux shell command: echo $(python3 -c 'print("Test"+"\0"+"M"*18)') | nc -u [IP] [PORT] My intention is to pipe the output of the print statement to the netcat command. The netcat command creates a socket to some service that essentially returns an stdout of the string passed in. The problem here is that when I try to run this command, I get this message: -bash: warning: command substitution: ignored null byte in input; and my null byte \0 gets ignored. But I don't want the null byte to be ignored. How do I tell the system to NOT ignored my null byte and take in the input exactly as I've specified. I have done some Google searches but honestly speaking they haven't helped much. Also, any link to some great article is much appreciated. -------------------------------------------------------------------------- **EDIT** Using printf worked. Ordinarily passing
-c 'print("Test"+"\0"+"M"*18)'
also worked. Valued @cas explanation. I guess I might be sticking to printf given it's faster (though speed isn't particularly a concern in my case). Thanks to all those who contributed :-).
Joker (199 rep)
Dec 24, 2021, 09:41 PM • Last activity: Jul 6, 2024, 05:35 PM
25 votes
2 answers
3747 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 following behavior: $ time tar cf /dev/null . real 0m4.387s user 0m3.462s sys 0m0.185s $ time tar...
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 0m4.387s user 0m3.462s sys 0m0.185s $ time tar cf - . > /dev/null real 0m3.130s user 0m3.091s sys 0m0.035s $ time tar cf - . | cat > /dev/null ^C real 10m32.985s user 0m1.942s sys 0m33.764s The third command above was forcibly stopped by Ctrl+C after having run for quite long already. Moreover, while the first two commands were working, activity indicator of the storage device containing . was nearly always idle. With the third command the indicator is constantly lit up, meaning extreme busyness. So it seems that, when tar is able to find out that its output file is /dev/null, i.e. when /dev/null is directly opened to have the file handle which tar writes to, file body appears skipped. (Adding v option to tar does print all the files in the directory being tar'red.) So I wonder, why is this so? Is it some kind of optimization? If yes, then why would tar even want to do such a dubious optimization for such a special case? I'm using GNU tar 1.26 with glibc 2.27 on Linux 4.14.105 amd64.
Ruslan (3429 rep)
Apr 14, 2019, 06:27 AM • Last activity: Aug 10, 2023, 07:19 AM
-1 votes
3 answers
413 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 have word "pear" and I cut it all with this and the filename null: echo $fname | perl -p -e 's/:pear://g'...
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 have word "pear" and I cut it all with this and the filename null: echo $fname | perl -p -e 's/:pear://g' I should rename now to "nullfile".
KisPogesz (1 rep)
Sep 25, 2015, 08:57 AM • Last activity: May 23, 2023, 06:00 PM
1 votes
1 answers
555 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 [ -z $domain ] && read -p "DOMAIN NAME: " domain namefile="./nameserver" echo "RESULT - NAMESERVER DOM...
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 [ -z $domain ] && read -p "DOMAIN NAME: " domain namefile="./nameserver" echo "RESULT - NAMESERVER DOMAIN IP" for host in $(cat "$namefile"); do IPADD=$(dig +short "$host" "$domain" A 2> /dev/null) [[ ! -z $IPADD ]] && result="OK" || result="FAIL" echo "$result - Nameserver: $host - Domain: $domain - IP answer: $IPADD" done The issue I'm having is that, when Dig fails, it is not redirecting errors to null. Thus, the $IPADD variable receives a wrong value. # CORRECT nameserver # dig +short @8.8.8.8 google.com A 2> /dev/null 142.250.218.206 --- # WRONG nameserver # dig +short @8.8.8.80 google.com A 2> /dev/null ;; connection timed out; no servers could be reached If I test it with a wrong nameserver address, I still get an error message, like shown above. As I understand, when redirecting to null, it should **not** display that error message. Any idea? Thank you.
markfree (425 rep)
Nov 7, 2022, 11:55 PM • Last activity: Nov 9, 2022, 03:25 PM
3 votes
4 answers
1020 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 file. I tried this: ``` case "$model" in CNRM-CM6-1|CNRM-ESM2-1) trim_op="-selindexbox,2,361,2,293" ;;...
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 file. I tried this:
case "$model" in
    CNRM-CM6-1|CNRM-ESM2-1)
        trim_op="-selindexbox,2,361,2,293"
    ;;
    EC-Earth3)
        trim_op="-selindexbox,2,361,2,291"
    ;;
    IPSL-CM6A-LR)
        trim_op="-selindexbox,2,361,2,331"
    ;;
    MPI-ESM1-2-HR)
        trim_op="-selindexbox,2,801,3,403"
    ;;
    MPI-ESM1-2-LR)
        trim_op="-selindexbox,2,255,2,219"
    ;;
    NorESM2-LM)
        trim_op="-selindexbox,2,359,2,383"
    ;;
    *)
        trim_op=""
    ;;
esac

cdo -O remapcon,"$target_grid" "$trim_op" "$input_file" "$output_file"
but bash chokes on the empty word. What is the proper way of doing such a thing in bash? What I ended up doing was:
if [[ -z $trim_op ]] ; then
    cdo -O remapcon,"$target_grid" "$input_file" "$output_file"
else
    cdo -O remapcon,"$target_grid" "$trim_op" "$input_file" "$output_file"
fi
I am feeling quite ignorant right now. Is there a name for this? Every search I make turns up *getop(s)* which is not what I am looking for.
Brendan (29 rep)
Oct 24, 2022, 12:43 PM • Last activity: Oct 31, 2022, 10:44 AM
0 votes
1 answers
431 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/www/html/nohup.out /var/www/html/nohup.out_$(date "+%Y.%b.%d-%H.%M.%S"); sudo tee /var/www/...
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/www/html/nohup.out /var/www/html/nohup.out_$(date "+%Y.%b.%d-%H.%M.%S"); sudo tee /var/www/html/nohup.out; The issue is when I run rotatelog.sh it does the job but the control does not return to the command line terminal. i tried > /var/www/html/nohup.out but I get Permission denied error. How can I get the logs rotated and return to the command-line?
Ashar (527 rep)
Oct 22, 2022, 03:39 PM • Last activity: Oct 22, 2022, 05:51 PM
0 votes
1 answers
322 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 list of built-in commands. /bin/sh: can't access tty; job control turned off / # / # echo Hello && sle...
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 list of built-in commands. /bin/sh: can't access tty; job control turned off / # / # echo Hello && sleep 2s && echo World & /bin/sh: / # can't open '/dev/null': No such file or directory / # / # mknod /dev/null c 1 3 && chmod 666 /dev/null / # echo Hello && sleep 2s && echo World & / # Hello World / #
round-down (37 rep)
Oct 4, 2022, 01:31 PM • Last activity: Oct 4, 2022, 01:51 PM
1 votes
0 answers
369 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/lampp/htdocs/mydeal-join-columns-2.php && cd /opt/lampp/htdocs/xero-bills && csvstack * > xero-bills-csvstacked.csv && cd...
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/lampp/htdocs/mydeal-join-columns-2.php && cd /opt/lampp/htdocs/xero-bills && csvstack * > xero-bills-csvstacked.csv && cd /opt/lampp/htdocs/xero-invoices && csvstack * > xero-inv-csvstacked.csv However, I don't actually want to see the messy output of php in terminal. I've tried various approaches, such as
php filename.php >/dev/null 2>&1 &
As given in this Q&A: https://stackoverflow.com/a/6989340/9095603 However, it totally breaks the one-liner and causes the command to exit prematurely. I am not invested in the above approach at all - I just need any simple approach which will allow me to run the one-liner and suppress the terminal output of the php execution.
mercurio (11 rep)
Oct 1, 2022, 12:09 PM
1 votes
0 answers
246 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 the best/easiest way to do this. (I tried also loopback previously but that was a lot more of a mes...
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 the best/easiest way to do this. (I tried also loopback previously but that was a lot more of a mess). I have set up the null and it is set to the default output, all I need to do now is configure camilladsp to accept the null-sink capture as a capture device, but it is asking for it to be of type: Alsa, File, or Stdin. Any idea how to sort this out, or have an alternative idea for routing the audio through camilladsp? Many thanks, Elliott
Elliott Dyson (11 rep)
Jul 24, 2021, 03:05 PM • Last activity: Aug 2, 2022, 10:31 PM
3 votes
1 answers
886 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 example: ``` bash #!/bin/bash mkdir /tmp/junk cd /tmp/junk touch a.txt b.txt c.txt d-e-f.txt dec...
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 example:
bash
#!/bin/bash

mkdir /tmp/junk
cd /tmp/junk

touch a.txt b.txt c.txt d-e-f.txt
declare -a files

echo "mapfile using default \\n delimiter"
mapfile -t  files  -d The  first  character  of delim is used to terminate each input line, rather than newline.  **If delim is the empty string, mapfile will terminate a line when it reads a NUL character**.


  

bash version is 5.1.8(1)-release:
none $ bash --version GNU bash, version 5.1.8(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
---

##### Update

Even weirder, it seems to be mangling existing elements of the array (as shown above) if it already exists, but not even creating it if it doesn't.
bash $ unset files $ mapfile -t -d'' files < <(find . -maxdepth 1 -type f -name '*.txt' -print0) $ typeset -p files -bash: typeset: files: not found ```
cas (81932 rep)
Jun 6, 2021, 09:28 AM • Last activity: Jul 3, 2022, 02:24 AM
-1 votes
1 answers
119 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. Thank you in advance...
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. Thank you in advance...
Deep Saha (1 rep)
May 30, 2022, 05:53 AM • Last activity: May 30, 2022, 06:02 AM
6 votes
6 answers
9847 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 few gigs of null bytes at the end of the tremendous file. I am very sure I don't need that. How can I...
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 tremendous file. I am very sure I don't need that. How can I strip those null bytes from the end efficiently so that I can later restore it with this command? cat file.bin /dev/zero | dd of=/dev/sdx bs=16M
iBug (3638 rep)
Jan 13, 2018, 08:37 AM • Last activity: May 5, 2022, 06:05 AM
11 votes
4 answers
46190 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** ? Also on my terminal I can create a file or a directory with the name `\0`. So I wonder **h...
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 directory with the name \0. So I wonder **how to write the null character correctly** because obviously it shouldn't allow me to have a filename with null in it mkdir '\0' will create a directory named \0 One more question, If I want to include $ in my filename, I can use the backslash mkdir \$myfile will create a directory named $myfile However, I can do the same if I surround the dollar sign with single quotes and double quotes mkdir \$myfile is the same as mkdir '$'myfile is the same as mkdir "$"myfile is the same as mkdir '$myfile' is the same as mkdir "$myfile" So my question is, **Are the single and double quotes a substitution for the escape backslash character?** **Also what other characters need escaping in bash besides $, (space) and backslash ?**
alkabary (1539 rep)
Aug 17, 2015, 11:12 PM • Last activity: Apr 29, 2022, 04:51 AM
0 votes
0 answers
697 views
"> $logfile" does not truncate, file size goes to 0 and a second later, is back to full size
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 see the size go to 0 briefly but immediately jumps back to full size again. $ ls -ald myscript.out -rw-rw-r-- 1 vmware vm...
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 see the size go to 0 briefly but immediately jumps back to full size again. $ ls -ald myscript.out -rw-rw-r-- 1 vmware vmware 14285855 Apr 11 04:33 myscript.out $ > myscript.out $ ls -ald myscript.out -rw-rw-r-- 1 vmware vmware 0 Apr 11 04:33 myscript.out $ ls -ald myscript.out -rw-rw-r-- 1 vmware vmware 14298778 Apr 11 04:33 myscript.out How can I truncate it so the size goes to zero and starts growing again from zero? I have tried many other alternatives but nothing works. Same thing, size goes to 0, then back to full size. true > myscript.out : > myscript.out echo -n > myscript.out cp /dev/null myscript.out truncate -s 0 myscript.out dd if=/dev/null of=myscript.out
chiwal (1 rep)
Apr 11, 2022, 09:41 AM • Last activity: Apr 11, 2022, 09:50 AM
305 votes
6 answers
788895 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>&1 # First remove the old bzip2 file. Redirect errors because this generates some if the archive # does no...
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 errors because this generates some if the archive # does not exist. Then create a new compressed file. rm /var/tmp/home_franky.tar.bz2 2> /dev/null bzip2 /var/tmp/home_franky.tar # Copy the file to another host - we have ssh keys for making this work without intervention. scp /var/tmp/home_franky.tar.bz2 bordeaux:/opt/backup/franky > /dev/null 2>&1 # Create a timestamp in a logfile. date >> /home/franky/log/home_backup.log echo backup succeeded >> /home/franky/log/home_backup.log I'm trying to understand the use of /dev/null 2>&1 here. At first, I thought this script uses /dev/null in order to gracefully ignore errors, without causing the script to crash (kind of like try catch exception handling in programming languages). Because I don't see how using tar to compress a directory into a tar file could possibly cause any type of errors.
JohnMerlino (6491 rep)
Mar 14, 2014, 04:20 AM • Last activity: Apr 2, 2022, 05:25 PM
Showing page 1 of 20 total questions