Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS: Ubuntu: xclip #156

Open
xvno opened this issue Aug 17, 2021 · 3 comments
Open

OS: Ubuntu: xclip #156

xvno opened this issue Aug 17, 2021 · 3 comments

Comments

@xvno
Copy link
Owner

xvno commented Aug 17, 2021

Refs

@xvno
Copy link
Owner Author

xvno commented Aug 17, 2021

How

xclip is a commandline interface to the X selections (clipboard). This tool helps you to copy the output of any command directly into the clipboard and saves you from manually copying and pasting from the terminal. If you have tried copying from the terminal output, you have already realized how tedious the task is. Imagine, if the output is very long, it will be difficult to copy the output manually. This is where xclip tool can benefit you. You can copy the output of any command using this tool. It also allows you to copy the contents of a file directly into the clipboard as well as print the contents of a selection to the standard out.

Installing xclip
xclip is available as a package for Ubuntu so, it can be installed as below. Open a terminal Ctrl + Alt + T and run:

sudo apt-get install xclip
# Using xclip


# To copy the output of a command into the clipboard, pipe the command into xclip as below:
# Long version
ls -la | xclip -selection clipboard
# Short version
ls -la | xclip -sel clip
# This puts the output of ls -la command into the clipboard, and you can now paste the output into any other program (eg. a text editor) with Ctrl + V outside terminal and Ctrl + Shift + V inside terminal.


# To copy the contents of a file (eg. /etc/apt/sources.list) into the clipboard:
# Long version
xclip -selection clipboard -in /etc/apt/sources.list
# Short version
xclip -sel clip -i /etc/apt/sources.list


# To print the contents of the clipboard:
# Long version
xclip -selection clipboard -out
# Short version
xclip -sel clip -o


# To save the contents of the clipboard to a file (eg. ~/myfile.txt):

# Long version
xclip -selection clipboard -out > ~/myfile.txt
# Short version
xclip -sel clip -o > ~/myfile.txt

@xvno
Copy link
Owner Author

xvno commented Aug 17, 2021

Alias

alias xc="xclip -sel clip"  # copy into clipboard
alias xcat="xclip -sel clip -i" # copy file content into clipboard, `pbcopy < filename`
alias pbcopy="xclip -sel clip -i" # As macOS does
alias xv="xclip -sel clip -o" # output from clipboard

@xvno
Copy link
Owner Author

xvno commented Aug 17, 2021

Usage

# copy file.txt
pbcopy file.txt
# paste
xv

# copy output from a formor command
ls -lh | xc
# paste
xv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant