Jadual Kandungan
What are pbcopy and pbpaste Commands?
What are xclip and xsel Commands?
Install xclip and xsel in Linux
Create Aliases for pbcopy and pbpaste
Use Pbcopy and Pbpaste Commands on Linux
Frequently Asked Questions
Conclusion
Rumah Tutorial sistem LINUX Cara Menggunakan Perintah PBCopy dan PBPaste di Linux

Cara Menggunakan Perintah PBCopy dan PBPaste di Linux

Mar 22, 2025 am 10:08 AM

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!"
Salin selepas log masuk

Paste the contents of the clipboard into a new file:

pbpaste > mynewfile.txt
Salin selepas log masuk

Copy the output of the command ls to the clipboard:

ls | pbcopy
Salin selepas log masuk

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
Salin selepas log masuk

On Fedora:

$ sudo dnf install xclip xsel
Salin selepas log masuk

On Debian, Ubuntu, Linux Mint:

$ sudo apt install xclip xsel
Salin selepas log masuk

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
Salin selepas log masuk

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

alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'
Salin selepas log masuk

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'
Salin selepas log masuk

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
Salin selepas log masuk

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

$ source ~/.zshrc
Salin selepas log masuk

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
Salin selepas log masuk

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!
Salin selepas log masuk

Cara Menggunakan Perintah PBCopy dan PBPaste di Linux

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!
Salin selepas log masuk

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

$ pbcopy < file.txt
Salin selepas log masuk

Now, the contents of the file is available in the clipboard as long as you updated it with another file's contents.

To retrieve the contents from clipboard, simply type:

<strong>$ pbpaste</strong> 
Welcome To OSTechNix!
Salin selepas log masuk

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
Salin selepas log masuk

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

$ pbpaste
Salin selepas log masuk

Cara Menggunakan Perintah PBCopy dan PBPaste di Linux

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

Atas ialah kandungan terperinci Cara Menggunakan Perintah PBCopy dan PBPaste di Linux. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn

Alat AI Hot

Undresser.AI Undress

Undresser.AI Undress

Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover

AI Clothes Remover

Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool

Undress AI Tool

Gambar buka pakaian secara percuma

Clothoff.io

Clothoff.io

Penyingkiran pakaian AI

Video Face Swap

Video Face Swap

Tukar muka dalam mana-mana video dengan mudah menggunakan alat tukar muka AI percuma kami!

Artikel Panas

<🎜>: Bubble Gum Simulator Infinity - Cara Mendapatkan dan Menggunakan Kekunci Diraja
3 minggu yang lalu By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Sistem Fusion, dijelaskan
3 minggu yang lalu By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers of the Witch Tree - Cara Membuka Kunci Cangkuk Bergelut
3 minggu yang lalu By 尊渡假赌尊渡假赌尊渡假赌

Alat panas

Notepad++7.3.1

Notepad++7.3.1

Editor kod yang mudah digunakan dan percuma

SublimeText3 versi Cina

SublimeText3 versi Cina

Versi Cina, sangat mudah digunakan

Hantar Studio 13.0.1

Hantar Studio 13.0.1

Persekitaran pembangunan bersepadu PHP yang berkuasa

Dreamweaver CS6

Dreamweaver CS6

Alat pembangunan web visual

SublimeText3 versi Mac

SublimeText3 versi Mac

Perisian penyuntingan kod peringkat Tuhan (SublimeText3)

Topik panas

Tutorial Java
1665
14
Tutorial PHP
1270
29
Tutorial C#
1249
24
Adakah Internet berjalan di Linux? Adakah Internet berjalan di Linux? Apr 14, 2025 am 12:03 AM

Internet tidak bergantung pada sistem operasi tunggal, tetapi Linux memainkan peranan penting di dalamnya. Linux digunakan secara meluas dalam pelayan dan peranti rangkaian dan popular untuk kestabilan, keselamatan dan skalabiliti.

Apakah operasi Linux? Apakah operasi Linux? Apr 13, 2025 am 12:20 AM

Inti sistem pengendalian Linux adalah antara muka baris arahannya, yang boleh melakukan pelbagai operasi melalui baris arahan. 1. Operasi Fail dan Direktori Gunakan LS, CD, MKDIR, RM dan arahan lain untuk menguruskan fail dan direktori. 2. Pengguna dan Pengurusan Kebenaran Memastikan keselamatan sistem dan peruntukan sumber melalui UserAdd, Passwd, CHMOD dan arahan lain. 3. Pengurusan proses menggunakan PS, membunuh dan arahan lain untuk memantau dan mengawal proses sistem. 4. Operasi rangkaian termasuk PING, IFCONFIG, SSH dan arahan lain untuk mengkonfigurasi dan menguruskan sambungan rangkaian. 5. Pemantauan sistem dan penyelenggaraan sistem seperti TOP, DF, DU untuk memahami status operasi sistem dan penggunaan sumber.

Apakah gaji Pentadbir Linux? Apakah gaji Pentadbir Linux? Apr 17, 2025 am 12:24 AM

Purata gaji tahunan pentadbir Linux ialah $ 75,000 hingga $ 95,000 di Amerika Syarikat dan € 40,000 hingga € 60,000 di Eropah. Untuk meningkatkan gaji, anda boleh: 1. Secara berterusan mempelajari teknologi baru, seperti pengkomputeran awan dan teknologi kontena; 2. Mengumpulkan pengalaman projek dan menubuhkan portfolio; 3. Mewujudkan rangkaian profesional dan mengembangkan rangkaian anda.

Apakah tugas utama pentadbir sistem Linux? Apakah tugas utama pentadbir sistem Linux? Apr 19, 2025 am 12:23 AM

Tugas utama pentadbir sistem Linux termasuk pemantauan sistem dan penalaan prestasi, pengurusan pengguna, pengurusan pakej perisian, pengurusan keselamatan dan sandaran, penyelesaian masalah dan resolusi, pengoptimuman prestasi dan amalan terbaik. 1. Gunakan alat atas, HTOP dan lain -lain untuk memantau prestasi sistem dan menyesuaikannya. 2. Menguruskan akaun pengguna dan keizinan melalui arahan USERADD dan arahan lain. 3. Gunakan APT dan YUM untuk menguruskan pakej perisian untuk memastikan kemas kini sistem dan keselamatan. 4. Konfigurasi firewall, memantau log, dan lakukan sandaran data untuk memastikan keselamatan sistem. 5. menyelesaikan masalah dan menyelesaikan melalui analisis log dan penggunaan alat. 6. Mengoptimumkan parameter kernel dan konfigurasi aplikasi, dan ikuti amalan terbaik untuk meningkatkan prestasi sistem dan kestabilan.

Meningkatkan Produktiviti dengan Pintasan Perintah Custom Menggunakan Linux Aliases Meningkatkan Produktiviti dengan Pintasan Perintah Custom Menggunakan Linux Aliases Apr 12, 2025 am 11:43 AM

Pengenalan Linux adalah sistem operasi yang kuat yang disukai oleh pemaju, pentadbir sistem, dan pengguna kuasa kerana fleksibiliti dan kecekapannya. Walau bagaimanapun, kerap menggunakan arahan panjang dan kompleks boleh membosankan dan er

Apakah tujuan utama Linux? Apakah tujuan utama Linux? Apr 16, 2025 am 12:19 AM

Penggunaan utama Linux termasuk: 1. Sistem Operasi Pelayan, 2. Sistem Terbenam, 3. Linux cemerlang dalam bidang ini, menyediakan kestabilan, keselamatan dan alat pembangunan yang cekap.

Apa yang sebenarnya Linux? Apa yang sebenarnya Linux? Apr 12, 2025 am 12:20 AM

Linux sesuai untuk pelayan, persekitaran pembangunan, dan sistem tertanam. 1. Sebagai sistem pengendalian pelayan, Linux stabil dan cekap, dan sering digunakan untuk menggunakan aplikasi konkurasi tinggi. 2. Sebagai persekitaran pembangunan, Linux menyediakan alat arahan dan sistem pengurusan pakej yang cekap untuk meningkatkan kecekapan pembangunan. 3. Dalam sistem tertanam, Linux ringan dan disesuaikan, sesuai untuk persekitaran dengan sumber yang terhad.

Apakah perbezaan sokongan virtualisasi antara Linux dan Windows? Apakah perbezaan sokongan virtualisasi antara Linux dan Windows? Apr 22, 2025 pm 06:09 PM

Perbezaan utama antara Linux dan Windows dalam sokongan virtualisasi adalah: 1) Linux menyediakan KVM dan XEN, dengan prestasi dan fleksibiliti yang luar biasa, sesuai untuk persekitaran penyesuaian yang tinggi; 2) Windows menyokong virtualisasi melalui Hyper-V, dengan antara muka yang mesra, dan disepadukan dengan ekosistem Microsoft, sesuai untuk perusahaan yang bergantung pada perisian Microsoft.

See all articles