# redirect output to file



## srchi (Mar 3, 2021)

I need to redirect output of 

`dd if=/dev/zero of=/dev/null bs=512 count=4096`

to file

I tried
`dd if=/dev/zero of=/dev/null bs=512 count=4096 > file`
printing empty file

`dd if=/dev/zero of=/dev/null bs=512 count=4096 > file 2>&1`
getting ambigious output


----------



## SirDice (Mar 3, 2021)

The way redirection works depends on the shell you're using. Judging by the error on the second command, where you used the bourne shell syntax, you're on the csh(1). The dd(1) command prints to stderr, not stdout. That's why the first redirection didn't output anything to the file. 

`dd if=/dev/zero of=/dev/null bs=512 count=4096 >& file`


```
> name
       >! name
       >& name
       >&! name
               The file name is used as standard output.  If the file does not
               exist then it is created; if the file exists, it is truncated,
               its previous contents being lost.

               If the shell variable noclobber is set, then the file must not
               exist or be a character special file (e.g., a terminal or
               `/dev/null') or an error results.  This helps prevent
               accidental destruction of files.  In this case the `!' forms
               can be used to suppress this check.  If notempty is given in
               noclobber, `>' is allowed on empty files; if ask is set, an
               interacive confirmation is presented, rather than an error.

               The forms involving `&' route the diagnostic output into the
               specified file as well as the standard output.  name is
               expanded in the same way as `<' input filenames are.
```


----------



## zirias@ (Mar 3, 2021)

Which output, and what do you mean by "ambiguous"?

If the intent was just to fill a file with zero-bytes, there's no need to redirect anything, just use `of=yourfile`.


----------



## SirDice (Mar 3, 2021)

Zirias said:


> and what do you mean by "ambiguous"?


If you use the bourne shell style output redirection `2>&1 > file` on csh(1) you get an `Ambiguous output redirect` message.

```
dice@williscorto:~ % echo $SHELL
/bin/tcsh
dice@williscorto:~ % echo some test 2>&1 > test
Ambiguous output redirect.
```

The reason is that this gets interpreted as `> file1 > file2`, so you get two redirections of stdout to different files. Hence the ambiguity.


----------



## srchi (Mar 3, 2021)

i need to check each disk writing speed, any command?


----------



## SirDice (Mar 3, 2021)

srchi said:


> i need to check each disk writing speed, any command?


benchmarks/bonnie++ or benchmarks/bonnie


----------



## srchi (Mar 4, 2021)

ive ran below command on HDD(local machine),SSD and NVM disks(digital ocean server). but getting same result which is rotation rate is unknown. any reason?


```
root@mfsbsd:~ # diskinfo -v ada0
ada0
    512             # sectorsize
    17179869184     # mediasize in bytes (16G)
    33554432        # mediasize in sectors
    0               # stripesize
    0               # stripeoffset
    33288           # Cylinders according to firmware.
    16              # Heads according to firmware.
    63              # Sectors according to firmware.
    VBOX HARDDISK    # Disk descr.
    VB9cefb55e-f72b70cf    # Disk ident.
    No              # TRIM/UNMAP support
    Unknown         # Rotation rate in RPM
    Not_Zoned       # Zone Mode
```


----------



## SirDice (Mar 4, 2021)

srchi said:


> But getting same result which is rotation rate is unknown. any reason?


It's a virtual disk (VBOX HARDDISK). Same as https://forums.freebsd.org/threads/identify-type-of-disk.79137/#post-497251


----------



## ralphbsz (Mar 5, 2021)

On a local disk on a real physical machine, "diskinfo -v" gives me reasonable answers. I would not use it though, since it is just a wrapper around the real information that comes from the disk. Instead, I would use "camcontrol identify" or "camcontrol inquiry", which gives you the SCSI/SATA standard answer.

On a virtual disk (for example a cloud or hosting provider), the rotation rate question probably makes no sense. The disk you see is constructed from a variety of hardwares, and probably involves a disk server (a dedicated computer), using multiple layers of storage device (reflective memory, SSD, perhaps even fast NVRAM such as 3DXpoint, fast disk, slow disk).

If you want to know the performance of your disk, you can use various disk benchmarks. SirDice already pointed you at Bonnie, which gives a very crude overall rating. FIO is a bit more detailed and scientific. No canned benchmark, however, will ever reflect your actual workload. People who are serious about this have their own benchmark suites (and some of those leak out on the internet). But the best benchmark is actually running your application in a controlled way.


----------



## Mjölnir (Mar 5, 2021)

srchi said:


> i need to check each disk writing speed, any command?


Use `dd ... -status=progress` or let your command get executed by dpv(1) or pv(1) (the latter has to be installed 1st).


----------



## Mjölnir (Mar 5, 2021)

benchmarks/fio was already mentioned by ralphbsz, and there's also benchmarks/filebench; both can be configured to simulate a particular workload to some degree.  OTT, don't stop to RTFM of the tools you use, e.g. dd(1) & the Handbook.  It's much stuff, it takes time to settle, but eventually it will pay off.  You can use ports-mgmt/psearch or ports-mgmt/portfind to search for ports(7) based on keywords.


----------

