From 5cc49561f8646eb9274305d6290cd92431741e23 Mon Sep 17 00:00:00 2001 From: geekpi Date: Mon, 13 Aug 2018 08:54:39 +0800 Subject: [PATCH] translated --- ...se Pbcopy And Pbpaste Commands On Linux.md | 138 ------------------ ...se Pbcopy And Pbpaste Commands On Linux.md | 138 ++++++++++++++++++ 2 files changed, 138 insertions(+), 138 deletions(-) delete mode 100644 sources/tech/20180731 How To Use Pbcopy And Pbpaste Commands On Linux.md create mode 100644 translated/tech/20180731 How To Use Pbcopy And Pbpaste Commands On Linux.md diff --git a/sources/tech/20180731 How To Use Pbcopy And Pbpaste Commands On Linux.md b/sources/tech/20180731 How To Use Pbcopy And Pbpaste Commands On Linux.md deleted file mode 100644 index 0b6c423a81..0000000000 --- a/sources/tech/20180731 How To Use Pbcopy And Pbpaste Commands On Linux.md +++ /dev/null @@ -1,138 +0,0 @@ -translating---geekpi - -How To Use Pbcopy And Pbpaste Commands On Linux -====== - -![](https://www.ostechnix.com/wp-content/uploads/2018/07/Pbcopy-And-Pbpaste-Commands-720x340.png) - -Since Linux and Mac OS X are *Nix based systems, many commands would work on both platforms. However, some commands may not available in on both platforms, for example **pbcopy** and **pbpaste**. These commands are exclusively available only on Mac OS X platform. The Pbcopy command will copy the standard input into clipboard. You can then paste the clipboard contents using Pbpaste command wherever you want. Of course, there could be some Linux alternatives to the above commands, for example **Xclip**. The Xclip will do exactly same as Pbcopy. But, the distro-hoppers who switched to Linux from Mac OS would miss this command-pair and still prefer to use them. No worries! This brief tutorial describes how to use Pbcopy and Pbpaste commands on Linux. - -### Install Xclip / Xsel - -Like I already said, Pbcopy and Pbpaste commands are not available in Linux. However, we can replicate the functionality of pbcopy and pbpaste commands using Xclip and/or Xsel commands via shell aliasing. Both Xclip and Xsel packages available in the default repositories of most Linux distributions. Please note that you need not to install both utilities. Just install any one of the above utilities. - -To install them on Arch Linux and its derivatives, run: -``` -$ sudo pacman xclip xsel - -``` - -On Fedora: -``` -$ sudo dnf xclip xsel - -``` - -On Debian, Ubuntu, Linux Mint: -``` -$ sudo apt install xclip xsel - -``` - -Once installed, you need create aliases for pbcopy and pbpaste commands. To do so, edit your **~/.bashrc** file: -``` -$ vi ~/.bashrc - -``` - -If you want to use Xclip, paste the following lines: -``` -alias pbcopy='xclip -selection clipboard' -alias pbpaste='xclip -selection clipboard -o' - -``` - -If you want to use xsel, paste the following lines in your ~/.bashrc file. -``` -alias pbcopy='xsel --clipboard --input' -alias pbpaste='xsel --clipboard --output' - -``` - -Save and close the file. - -Next, run the following command to update the changes in ~/.bashrc file. -``` -$ source ~/.bashrc - -``` - -The ZSH users paste the above lines in **~/.zshrc** file. - -### Use Pbcopy And Pbpaste Commands On Linux - -Let us see some examples. - -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! - -``` - -![](https://www.ostechnix.com/wp-content/uploads/2018/07/pbcopy-and-pbpaste-commands-in-action.png) - -Here are some other use cases. - -I have a file named **file.txt** with the following contents. -``` -$ cat file.txt -Welcome To OSTechNix! - -``` - -You can directly copy the contents of a file into a clipboard as shown below. -``` -$ pbcopy < file.txt - -``` - -Now, the contents of the file is available in the clipboard as long as you updated with another file’s contents. - -To retrieve the contents from clipboard, simply type: -``` -$ pbpaste -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 - -``` - -![](https://www.ostechnix.com/wp-content/uploads/2018/07/pbcopy-and-pbpaste-commands-2.png) - -There is much more you can do with Pbcopy and Pbpaste commands. I hope you now got a basic idea about these commands. - -And, that’s all for now. More good stuffs to come. Stay tuned! - -Cheers! - - - --------------------------------------------------------------------------------- - -via: https://www.ostechnix.com/how-to-use-pbcopy-and-pbpaste-commands-on-linux/ - -作者:[SK][a] -选题:[lujun9972](https://github.com/lujun9972) -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.ostechnix.com/author/sk/ diff --git a/translated/tech/20180731 How To Use Pbcopy And Pbpaste Commands On Linux.md b/translated/tech/20180731 How To Use Pbcopy And Pbpaste Commands On Linux.md new file mode 100644 index 0000000000..7cb12466f3 --- /dev/null +++ b/translated/tech/20180731 How To Use Pbcopy And Pbpaste Commands On Linux.md @@ -0,0 +1,138 @@ +如何在 Linux 上使用 Pbcopy 和 Pbpaste 命令 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/07/Pbcopy-And-Pbpaste-Commands-720x340.png) + +由于 Linux 和 Mac OS X 是基于 *Nix 的系统,因此许多命令可以在两个平台上运行。但是,某些命令可能在两个平台上都没有,比如 **pbcopy** 和 **pbpast**。这些命令仅在 Mac OS X 平台上可用。Pbcopy 命令将标准输入复制到剪贴板。然后,你可以在任何地方使用 Pbpaste 命令粘贴剪贴板内容。当然,上述命令可能有一些 Linux 替代品,例如 **Xclip**。 Xclip 与 Pbcopy 完全相同。但是,从 Mac OS 切换到 Linux 的发行版的人将会错过这两个命令,但仍然更喜欢使用它们。别担心!这个简短的教程描述了如何在 Linux 上使用 Pbcopy 和 Pbpaste 命令。 + +### 安装 Xclip / Xsel + +就像我已经说过的那样,Linux 中没有 Pbcopy 和 Pbpaste 命令。但是,我们可以通过 shell 别名使用 Xclip 和/或 Xsel 命令复制 pbcopy 和 pbpaste 命令的功能。Xclip 和 Xsel 包存在于大多数 Linux 发行版的默认存储库中。请注意,你无需安装这两个程序。只需安装上述任何一个程序即可。 + +要在 Arch Linux 及其衍生产版上安装它们,请运行: +``` +$ sudo pacman xclip xsel + +``` + +在 Fedora 上: +``` +$ sudo dnf xclip xsel + +``` + +在 Debian、Ubuntu、Linux Mint 上: +``` +$ sudo apt install xclip xsel + +``` + +Once installed, you need create aliases for pbcopy and pbpaste commands. To do so, edit your **~/.bashrc** file: +安装后,你需要为 pbcopy 和 pbpaste 命令创建别名。为此,请编辑 **~/.bashrc**: +``` +$ vi ~/.bashrc + +``` + +如果要使用 Xclip,请粘贴以下行: +``` +alias pbcopy='xclip -selection clipboard' +alias pbpaste='xclip -selection clipboard -o' + +``` + +如果要使用 xsel,请在 ~/.bashrc 中粘贴以下行。 +``` +alias pbcopy='xsel --clipboard --input' +alias pbpaste='xsel --clipboard --output' + +``` + +保存并关闭文件。 + +接下来,运行以下命令以更新 ~/.bashrc 中的更改。 + +``` +$ source ~/.bashrc + +``` + +ZSH 用户将上述行粘贴到 **~/.zshrc** 中。 + +### 在 Linux 上使用 Pbcopy 和 Pbpaste 命令 + +让我们看一些例子。 + +pbcopy 命令将文本从 stdin 复制到剪贴板缓冲区。例如,看看下面的例子。 +``` +$ echo "Welcome To OSTechNix!" | pbcopy + +``` + +上面的命令会将文本 “Welcome to OSTechNix” 复制到剪贴板中。你可以稍后访问此内容并使用如下所示的 Pbpaste 命令将其粘贴到任何位置。 +``` +$ echo `pbpaste` +Welcome To OSTechNix! + +``` + +![](https://www.ostechnix.com/wp-content/uploads/2018/07/pbcopy-and-pbpaste-commands-in-action.png) + +以下是一些其他例子。 + +我有一个名为 **file.txt*** 的文件,其中包含以下内容。 +``` +$ cat file.txt +Welcome To OSTechNix! + +``` + +你可以直接将文件内容复制到剪贴板中,如下所示。 +``` +$ pbcopy < file.txt + +``` + +现在,只要你用其他文件的内容更新了剪切板,那么剪切板中的内容就可用了。 + +要从剪贴板检索内容,只需输入: +``` +$ pbpaste +Welcome To OSTechNix! + +``` + +你还可以使用管道字符将任何 Linux 命令的输出发送到剪贴板。看看下面的例子。 +``` +$ ps aux | pbcopy + +``` + +现在,输入 “pbpaste” 命令以显示剪贴板中 “ps aux” 命令的输出。 +``` +$ pbpaste + +``` + +![](https://www.ostechnix.com/wp-content/uploads/2018/07/pbcopy-and-pbpaste-commands-2.png) + +使用 Pbcopy 和 Pbpaste 命令可以做更多的事情。我希望你现在对这些命令有一个基本的想法。 + +就是这些了。还有更好的东西。敬请关注! + +干杯! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-use-pbcopy-and-pbpaste-commands-on-linux/ + +作者:[SK][a] +选题:[lujun9972](https://github.com/lujun9972) +译者:[geekpi](https://github.com/geekpi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/