Osinachi Chukwujama
Osi on Tech

Follow

Osi on Tech

Follow
How to Copy To Clipboard in Terminal

How to Copy To Clipboard in Terminal

Osinachi Chukwujama 's photo
Osinachi Chukwujama
·Jan 10, 2021·

2 min read

Play this article

Use the x-clip package to copy the content of a file to your clipboard from your the terminal. We'll go over the steps to achieve this.

Steps

  1. Create a file lorem.txt and populate it with lorem-ipsum
    cat > lorem.txt << EOF
    Lorem ipsum dolor sit amet consectetur adipisicing elit. Incidunt debitis magnam
    provident nam cum alias nisi suscipit perspiciatis veritatis? Assumenda.
    EOF
    
  2. Install xclip
    sudo apt install xclip
    
  3. Select the file using xclip -sel c < filename
    xclip -sel c < lorem.txt
    
    -sel refers to selection and c refers to clipboard. You can run xclip -h for more info.
  4. Check the content of your clipboard
    Lorem ipsum dolor sit amet consectetur adipisicing elit. Incidunt debitis magnam
    provident nam cum alias nisi suscipit perspiciatis veritatis? Assumenda.
    

For more tutorials and tips like this, subscribe to my newsletter. Thanks for reading. Adios.

 
Share this