Use xclip or xsel to manipulate the Linux clipboard.
Command Reference
Using xclip
# 读取剪贴板
xclip -selection clipboard -o
# 写入剪贴板
echo "要复制的内容" | xclip -selection clipboard
# 从文件复制到剪贴板
xclip -selection clipboard < "/path/to/file.txt"
Using xsel (alternative)
# 读取剪贴板
xsel --clipboard --output
# 写入剪贴板
echo "要复制的内容" | xsel --clipboard --input
Installation
# Debian/Ubuntu
sudo apt install xclip
# Fedora
sudo dnf install xclip
Output Specification
- After reading, display the content (truncate long text to the first 500 characters)
- After writing, confirm "Copied to clipboard"