rsync --version
gives lots of info but I just want to grab the first line
rsync version 3.1.1
How to do this? I tried to pipe into grep but I can't
There are lots of ways to slice this pie. If you want the whole first line, you can use any of these:
rsync --version | head -n 1
rsync --version | awk NR==1
rsync --version | sed -n 1p
rsync --version | grep '^rsync *version'
If you want just the version number without the rest of the line, that's not much harder, but it depends which part of the line you want. On my Mac, the version line reads rsync version 2.6.9 protocol version 29
, and a naïve grab would likely yield the 29
- presumably not what you want. Either of the following will output just the 2.6.9
by itself:
rsync --version | awk 'NR==1 {print $3}'
rsync --version | sed -n '1s/^rsync *version \([0-9.]*\).*$/\1/p'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With