xclip
xclip은 표준 입력이나 파일을 X11 selection에 저장하고 selection 내용을 표준 출력으로 읽는 CLI 도구다. 일반적인 desktop copy/paste에는 CLIPBOARD selection을 명시한다.
Installation
sudo apt install xclip # Debian, Ubuntu sudo dnf install xclip # Fedora, RHEL 계열 sudo pacman -S xclip # Arch Linux
Usage
xclip [OPTION] [FILE]...
xclip -selection clipboard -inxclip -selection clipboard -outxclip -selection primary|clipboard|secondary
Selection
primary: X11의 기본 selection이다. 일반적으로 mouse drag로 선택하고 middle-click으로 붙여 넣는다.clipboard: 일반적인 Ctrl+Ctrl, Ctrl+V 흐름에 사용하는 selection이다.secondary: 드물게 사용하는 보조 selection이다.
xclip의 기본 selection은 primary이므로 일반 clipboard 자동화에서는 -selection clipboard를 생략하지 않는다.
Options
-i,-in: 표준 입력 또는 지정한 파일을 selection에 넣는다. 기본 동작이다.-o,-out: selection을 표준 출력으로 보낸다.-selection TYPE:primary,secondary,clipboard,buffer-cut을 선택한다.-l,-loops COUNT: 지정 횟수의 selection 요청을 처리한 뒤 종료한다.-d,-display DISPLAY: 연결할 X display를 지정한다.-rmlastnl: 마지막 newline이 있으면 제거한다.-target TARGET: 사용할 target atom을 지정한다.-noutf8: UTF-8 대신 이전 Unicode 처리 방식을 사용한다.-silent,-quiet,-verbose: background/foreground 및 진단 출력 수준을 조절한다.
Examples
Text copy/paste
printf '%s' 'Message' | xclip -selection clipboard -in xclip -selection clipboard -out
File content
xclip -selection clipboard -in notes.txt xclip -selection clipboard -out > clipboard.txt
PRIMARY를 CLIPBOARD로 복사
xclip -selection primary -out | xclip -selection clipboard -in
Environment
xclip은 X11 client이므로 유효한 DISPLAY와 X server 인증이 필요하다. Wayland-only 또는 headless SSH 환경에서는 wl-clipboard나 OSC 52를 사용한다.
Help
Usage: xclip [OPTION] [FILE]...
Access an X server selection for reading or writing.
-i, -in read text into X selection from standard input or files
(default)
-o, -out prints the selection to standard out (generally for
piping to a file or program)
-l, -loops number of selection requests to wait for before exiting
-d, -display X display to connect to (eg localhost:0")
-h, -help usage information
-selection selection to access ("primary", "secondary", "clipboard" or "buffer-cut")
-noutf8 don't treat text as utf-8, use old unicode
-target use the given target atom
-rmlastnl remove the last newline charater if present
-version version information
-silent errors only, run in background (default)
-quiet run in foreground, show what's happening
-verbose running commentary
Report bugs to <[email protected]>
+
See Also
History
- codex:: 2026-07-19 기존 xclip 명령과 help를 보존하고 X11 selection, 설치, 예제, 환경 제약을 정리했다.