Wednesday, December 8, 2010

Pipe to clipboard in bash on ubuntu

Say you wanted the output of a command like ls to be copied directly into the clipboard for pasting into your gui windows. Use xclip:
sudo apt-get install xclip
Then
ls | xclip -selection clipboard
will copy the output of ls into the clipboard.

I use an alias in my .bashrc for it:
alias c='xclip -selection clipboard'
So the command becomes:
ls | c

Quickly changing your .bashrc file

I use aliases all the time and am always adding more shortcuts for my terminal experience to the .bashrc file. So it's only natural that I made a convenient alias for doing exactly that.

Add this line to your .bashrc file:
alias vib='vi ~/.bashrc && source ~/.bashrc'

Then type source ~/.bashrc and the change will have been made.

So whenever you want to change your .bashrc file and have it come into effect for the current terminal:
vib
which will edit .bashrc and will run source on it automatically when you finish editing.