찾다
시스템 튜토리얼리눅스Linux에서 pbcopy 및 pbpaste 명령을 사용하는 방법

Since Linux and Mac OS X are Unix-based systems, many commands will work on both platforms. However, some commands are unique and might not be available on both platforms, for example pbcopy and pbpaste commands. These commands are exclusively available only on macOS platform.

Those who have switched from macOS to Linux might feel the absence of this command pair and would likely prefer to continue using them in Linux system. Worry not! If you've moved from macOS to Linux and are missing the pbcopy and pbpaste, I have a solution for you to bring similar functionality to Linux.

In this brief tutorial, I will explain how to replicate the functionalities of pbcopy and pbpaste and use Pbcopy and Pbpaste commands on a Linux system.

Table of Contents

What are pbcopy and pbpaste Commands?

Pbcopy and Pbpaste are two command-line utilities on macOS that allow you to copy and paste text to and from the clipboard. They are similar to the familiar keyboard shortcuts ⌘+C and ⌘+V, but they can be used from within the terminal.

The pbcopy command will copy the standard input into clipboard. You can then paste the clipboard contents using pbpaste command wherever you want.

Here are some examples of how to use pbcopy and pbpaste:

Copy the text "Hello world!" to the clipboard:

pbcopy echo "Welcome to OSTechNix blog!"

Paste the contents of the clipboard into a new file:

pbpaste > mynewfile.txt

Copy the output of the command ls to the clipboard:

ls | pbcopy

While pbcopy and pbpaste are specifically available on macOS systems, there are a number of Linux alternatives to pbcopy and pbpaste, such as xclip and xsel.

Heads Up: The symbol ⌘, also known as the looped square, is the symbol for the command key on Apple keyboards.

What are xclip and xsel Commands?

Xclip is a command line interface to X selections i.e. Clipboard. Xclip reads the data from one or more files and makes the data available as an X selection for pasting the data into X applications.

Xsel is also a command line X11 selection and clipboard manipulation tool. It is used to access X clipboard and selection buffers in Linux and Unix-like operating systems.

For more details on xclip and xsel usage in Linux, please refer the following guide.

How To Access Clipboard Contents Using Xclip and Xsel In Linux

Using xclip or xsel programs, we can easily imitate the functionality of pbcopy and pbpaste commands in Linux.

Install xclip and xsel in Linux

Both xclip and xsel packages available in the default repositories of most Linux distributions. Please note that you don't have to install both utilities. Just install any one of the above utilities.

To install them on Arch Linux and its derivatives, run:

$ sudo pacman -S xclip xsel

On Fedora:

$ sudo dnf install xclip xsel

On Debian, Ubuntu, Linux Mint:

$ sudo apt install xclip xsel

Once installed, you need to create aliases for pbcopy and pbpaste commands.

Create Aliases for pbcopy and pbpaste

We can replicate the functionality of pbcopy and pbpaste commands using xclip and/or xsel commands via shell aliasing. Let us see how to do that!

1. Edit your ~/.bashrc file:

$ vi ~/.bashrc

2. If you want to use xclip, paste the following lines:

alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'

3. If you want to use xsel, paste the following lines in your ~/.bashrc file.

alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'

4. After adding the above lines, press ESC and :wq to save and close the file.

5. Next, run the following command to update the changes in ~/.bashrc file.

$ source ~/.bashrc

6. The ZSH users paste the above lines in ~/.zshrc file and update the changes using command:

$ source ~/.zshrc

Use Pbcopy and Pbpaste Commands on Linux

As mentioned already. the pbcopy command will copy the text from stdin into clipboard buffer. For example, have a look at the following example.

$ echo "Welcome To OSTechNix!" | pbcopy

The above command will copy the text "Welcome To OSTechNix" into clipboard. You can access this content later and paste them anywhere you want using pbpaste command like below.

$ echo `pbpaste`
Welcome To OSTechNix!

Linux에서 pbcopy 및 pbpaste 명령을 사용하는 방법

Here are some other use cases.

I have a file named file.txt with the following contents.

<strong>$ cat file.txt</strong> 
Welcome To OSTechNix!

You can directly copy the contents of a file into a clipboard as shown below.

$ pbcopy <p>Now, the contents of the file is available in the clipboard as long as you updated it with another file's contents.</p><p>To retrieve the contents from clipboard, simply type:</p><pre class="brush:php;toolbar:false"><strong>$ pbpaste</strong> 
Welcome To OSTechNix!

You can also send the output of any Linux command to clip board using pipeline character. Have a look at the following example.

$ ps aux | pbcopy

Now, type "pbpaste" command at any time to display the output of "ps aux" command from the clipboard.

$ pbpaste

Linux에서 pbcopy 및 pbpaste 명령을 사용하는 방법

There is much more you can do with Pbcopy and Pbpaste commands. I hope you now got the basic idea about these commands.

Frequently Asked Questions

FAQ: Using Xclip and Xsel in Linux as Alternatives to pbcopy and pbpaste.

Q: What are pbcopy and pbpaste, and why are they not available on Linux?

A: pbcopy and pbpaste are commands on macOS for copying and pasting text via the command line. They are unavailable on Linux. These commands are specific to macOS.

Q: What are Xclip and Xsel?

A: Xclip and Xsel are Linux command-line tools that replicate the functionality of pbcopy and pbpaste. They enable efficient copying and pasting of text between the command line and clipboard.

Q: How do I install Xclip and Xsel on my Linux system?

A: You can install Xclip and Xsel using your package manager. For example, on Debian-based systems like Ubuntu, you can use sudo apt-get install xclip xsel.

Q: How do I copy text to the clipboard using Xclip?

A: To copy text from a file to the clipboard, use: cat file.txt | xclip -selection clipboard.

Q: How do I paste text from the clipboard using Xclip?

A: To paste text from the clipboard to the terminal, use: xclip -selection clipboard -o.

Q: Can I use Xclip and Xsel on macOS?

A: Yes, you can, but they are most commonly used on Linux systems. macOS already provides the native pbcopy and pbpaste commands.

Q: Are the commands for Xclip and Xsel the same as pbcopy and pbpaste?

A: No, the commands are different, but they serve similar purposes. Xclip and Xsel have their own syntax for copying and pasting text.

Q: Can I use Xclip and Xsel for tasks beyond simple copying and pasting?

A: Yes, you can use them in scripting and automation for more complex tasks involving clipboard content.

Q: Are there any other alternatives to Xclip and Xsel for Linux?

A: While Xclip and Xsel are popular choices, you might also consider other tools like wl-clipboard and clipman. They are exclusively developed for Wayland systems.

Q: Do Xclip and Xsel work across different Linux distributions?

A: Yes, Xclip and Xsel are widely supported and work across various Linux distributions.

Conclusion

To sum it up, even though pbcopy and pbpaste commands are handy for controlling clipboard on Mac computers, Linux users can accomplish similar tasks using tools like Xclip and Xsel. These tools let you handle clipboard content smoothly in Linux, making it easy to work with text. So, while the names of the commands may change, the main idea of improving how you work with text stays the same whether you're using macOS or Linux.

Related Read:

  • How To Manage Clipboard From Command Line In Linux
  • How To Manage Clipboard Contents With CopyQ In Linux
  • Access Clipboard Contents Using Xclip and Xsel In Linux
  • Copy File Contents Into Clipboard Without Displaying Them In Linux

위 내용은 Linux에서 pbcopy 및 pbpaste 명령을 사용하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
사용 방법 ' 다음 ' Linux에서 awk로 명령 - 6 부사용 방법 ' 다음 ' Linux에서 awk로 명령 - 6 부May 15, 2025 am 10:43 AM

AWK 시리즈의 여섯 번째 할부에서 우리는 중복 처리 단계를 건너 뛰어 스크립트 실행의 효율성을 향상시키는 데 도움이되는 다음 명령을 탐색 할 것입니다. 다음 명령은 무엇입니까?

Linux에서 파일을 효율적으로 전송하는 방법Linux에서 파일을 효율적으로 전송하는 방법May 15, 2025 am 10:42 AM

Linux 시스템에서 파일을 전송하는 것은 특히 로컬 또는 원격 시스템 간의 네트워크 전송과 관련하여 모든 시스템 관리자가 마스터 해야하는 일반적인 작업입니다. Linux는이 작업을 수행하기 위해 일반적으로 사용되는 두 가지 도구 인 SCP (Secure Replication) 및 RSYNC를 제공합니다. 둘 다 로컬 또는 원격 기계간에 파일을 전송하는 안전하고 편리한 방법을 제공합니다. 이 기사는 SCP 및 RSYNC 명령을 사용하여 로컬 및 원격 파일 전송을 포함하여 파일을 전송하는 방법을 자세히 설명합니다. Linux SCP 명령의 SCP (Secure Copy Protocol)는 SSH (Secure Shell)을 통해 두 호스트 간의 파일 및 디렉토리를 안전하게 복사하는 데 사용되는 명령 줄 프로그램입니다. 이는 인터넷을 통해 파일이 전송되면의 수를 의미합니다.

10 가지 가장 인기있는 Linux 데스크탑 환경10 가지 가장 인기있는 Linux 데스크탑 환경May 15, 2025 am 10:35 AM

Windows 및 Mac OS X와 ​​달리 Linux의 매혹적인 기능 중 하나는 다양한 데스크탑 환경을 지원하는 것입니다. 이를 통해 데스크탑 사용자는 컴퓨팅 요구 사항에 따라 가장 적합하고 적합한 데스크탑 환경을 선택할 수 있습니다.

Linux Desktop에 Libreoffice 24.8을 설치하는 방법Linux Desktop에 Libreoffice 24.8을 설치하는 방법May 15, 2025 am 10:15 AM

Libreoffice는 Linux, Windows 및 Mac 플랫폼을 위해 강력하고 오픈 소스 사무실 제품군으로 두드러집니다. 단어 문서, 스프레드 시트, 프레젠테이션, 도면, 계산 및 수학을 처리하기위한 다양한 기능을 자랑합니다.

Linux에서 Office Docs 만 사용하여 PDF 파일 작업 방법Linux에서 Office Docs 만 사용하여 PDF 파일 작업 방법May 15, 2025 am 09:58 AM

PDF 파일을 관리하는 Linux 사용자는 다양한 프로그램을 사용할 수 있습니다. 구체적으로, 다양한 기능을 위해 설계된 수많은 특수 PDF 도구가 있습니다. 예를 들어, 파일을 읽기 위해 PDF 뷰어를 설치하거나 PDF EDI를 설치할 수 있습니다.

awk 및 stdin을 사용하여 명령 출력을 필터링하는 방법awk 및 stdin을 사용하여 명령 출력을 필터링하는 방법May 15, 2025 am 09:53 AM

AWK 명령 시리즈의 이전 세그먼트에서 우리의 초점은 주로 파일의 입력을 읽는 데있었습니다. 그러나 stdin에서 입력을 읽어야한다면 AWK 시리즈의 7 부에서는 O의 출력을 사용할 수있는 몇 가지 예를 살펴 보겠습니다.

CLIFM- Linux의 번개 빠른 터미널 파일 관리자CLIFM- Linux의 번개 빠른 터미널 파일 관리자May 15, 2025 am 09:45 AM

Clifm은 쉘과 같은 인터페이스의 기초에 설계된 독특하고 믿을 수 없을 정도로 신속한 지휘관 파일 관리자로 두드러집니다. 즉, 사용자가 이미 익숙한 명령을 사용하여 파일 시스템에 참여할 수 있음을 의미합니다.

Linux Mint 21.3에서 Linux Mint 22로 업그레이드하는 방법Linux Mint 21.3에서 Linux Mint 22로 업그레이드하는 방법May 15, 2025 am 09:44 AM

Linux Mint 22 Wilma의 새로운 설치를 수행하지 않으려면 이전 버전에서 업그레이드 할 수있는 옵션이 있습니다.이 안내서에서는 Linux Mint 21.3 (21.x 시리즈의 최신 릴리스 릴리스)에서 업그레이드하는 프로세스를 자세히 설명합니다.

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

맨티스BT

맨티스BT

Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

DVWA

DVWA

DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

안전한 시험 브라우저

안전한 시험 브라우저

안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

SecList

SecList

SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.