Skip to main content

Command Palette

Search for a command to run...

How to Copy To Clipboard in Terminal

Updated
2 min read
How to Copy To Clipboard in Terminal
O

Hi there 👋🏾. I'm a software engineer that enjoys building stuff and talking about them. I also tinker a bit with hardware and robotics using Arduino and ROS.

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.

More from this blog

O

Osinachi's base

66 posts

Hi there, I'm a software engineer that enjoys building stuff and talking about them. I also tinker a bit with hardware and robotics using Arduino and ROS.