📋

Using Clipboard Commands in Terminal

Mar 30, 2025

Lecture Notes: Copy and Paste in Terminal

Overview

  • Presenter: Chuck
  • Topic: Using clipboard commands in terminal
  • Platform: Applicable for Mac, Linux, and Windows (using WSL)
  • Tools Explored: pbcopy, pbpaste

Key Concepts

Clipboard Commands

  • Mac Users:
    • Commands pbcopy and pbpaste are available by default.
    • Can be used to copy content directly to clipboard and paste anywhere.
  • Linux/Windows (WSL) Users:
    • By default, pbcopy and pbpaste do not exist.
    • Need to install a tool (Excel CLI tool) to replicate this functionality.

Steps for Linux/Windows Users

Installing Excel

  1. Open Terminal
    • For Linux: Launch Terminal
    • For Windows: Launch WSL Terminal
  2. Install Excel:
    • Command: sudo apt install xsel

Using Excel for Clipboard

  • Copy to Clipboard:
    • Example: uname -r | xsel --input --clipboard
  • Paste from Clipboard:
    • Example: xsel --output --clipboard

Creating Aliases

  • Purpose: Simplify commands
  • Steps to Create Aliases:
    1. Open Bash RC file: nano ~/.bashrc
    2. Add aliases:
      • alias pbcopy='xsel --input --clipboard'
      • alias pbpaste='xsel --output --clipboard'
    3. Save and exit: Ctrl + X, Y, Enter
    4. Refresh terminal: source ~/.bashrc
  • Test Aliases:
    • Copy: echo "Hello" | pbcopy
    • Paste: pbpaste

Remote Server Clipboard Use

Preconditions

  • Scenarios Supported:
    • Linux server logging into another Linux server
    • WSL logging into a Linux server
  • Scenarios Not Supported:
    • Windows logging into a Linux server

Setup for Remote Server

  1. Install Excel on Remote Server:
    • Command: sudo apt install xsel
  2. Enable X11 Forwarding:
    • Check setting: cat /etc/ssh/sshd_config | grep X11
    • Ensure X11Forwarding is set to yes
  3. Setup Aliases on Remote:
    • Same as local setup, edit ~/.bashrc on remote server

Connecting to Remote with X11 Forwarding

  • Command: ssh -X user@remote-server

Other Notes

  • Five Minute Fridays: Weekly short tutorials
  • Engagement: Encouragement to like, comment, subscribe
  • Community: Join Network Chuck Academy for more learning opportunities

Personal Reflections

  • Daily Use: Presenter uses these commands for daily tasks
  • Feedback: Encourages users to share tips and suggestions

Conclusion

  • Lecture Summary: Practical guide to using clipboard commands in terminal across different platforms.
  • Call to Action: Join Network Chuck Academy for more insights.