xsel

X11 selection and clipboard manipulation tool. More information: https://manned.org/xsel.

echo 123 | xsel -ib

cat path/to/file | xsel -ib

xsel -ob

xsel -ob > path/to/file

xsel -cb

xsel -op