# tr(1): fill image with ones



## JohnnySorocil (Apr 2, 2018)

I'm trying to fill binary file with all 1s.

```
dd if=/dev/zero bs=1M count=2 | /usr/bin/tr '\000' '\377' > file1 && hexdump file1
2+0 records in
2+0 records out
2097152 bytes transferred in 0.129117 secs (16242243 bytes/sec)
0000000 bfc3 bfc3 bfc3 bfc3 bfc3 bfc3 bfc3 bfc3
*
0400000
```

As far I understand the problem '377' in octal representation should be 0xFF in hex.
tr(1) from /compat/linux seems to be working as expected:

```
dd if=/dev/zero bs=1M count=2 | /usr/compat/linux/usr/bin/tr '\000' '\377' > file2 && hexdump file2
2+0 records in
2+0 records out
2097152 bytes transferred in 0.008285 secs (253130009 bytes/sec)
0000000 ffff ffff ffff ffff ffff ffff ffff ffff
*
0200000
```


----------



## tobik@ (Apr 2, 2018)

tr(1) is affected by locale settings in the environment, so set them to the default if you want reproducible behavior:

```
$ dd if=/dev/zero bs=1M count=2 | env LC_ALL=C /usr/bin/tr '\000' '\377' > file1 && hexdump file1
2+0 records in
2+0 records out
2097152 bytes transferred in 0.070207 secs (29870864 bytes/sec)
0000000 ffff ffff ffff ffff ffff ffff ffff ffff
*
0200000
```



JohnnySorocil said:


> tr(1) from /compat/linux seems to be working as expected:


GNU utilities are available in sysutils/coreutils with a g prefix (i.e. `gtr`) so you don't necessarily have to go through linux(4) to run them on FreeBSD.


----------



## JohnnySorocil (Apr 2, 2018)

tobik@ said:


> tr(1) is affected by locale settings in the environment, so set them to the default if you want reproducible behavior:
> 
> ```
> $ dd if=/dev/zero bs=1M count=2 | env LC_ALL=C /usr/bin/tr '\000' '\377' > file1 && hexdump file1
> ```



Interesting. I didn't know that. Looks like I should read the whole man pages more carefully 
Thanks!



> GNU utilities are available in sysutils/coreutils with a g prefix (i.e. `gtr`) so you don't necessarily have to go through linux(4) to run them on FreeBSD.


Yes, that's more appropriate way, but in my defense, linux(4) subsystem was already installed for CUPS filter


----------

