Site icon moneyslow.com

mac下剪贴板的两个神奇神器命令pbcopy和pbpaste

mac技巧

mac技巧

Copying and pasting on macOS
On macOS, there are two commands - pbcopy and pbpaste which leverage the system’s clipboard.
The pbcopy command puts input into the clipboard.
把内容放到剪贴板:
pbcopy "some text"

Piping output works surprisingly well:
ps aux | pbcopy
If you want to print the clipboard’s content all you need to do is run pbpaste.
Let’s say you want to copy and execute the file’s content. Of course, you may just use source file.sh but for the sake of this tutorial let’s assume that scenario.
First, create a file:
cat > file.sh <<EOF
echo "hello world"
EOF
Then you can copy its content with pbcopy:
把一个shell文件放到剪贴板
pbcopy < file.sh

The last step is to execute the clipboard’s content:
骚操作:执行剪贴板里的shell脚本
pbpaste | zsh
Copying and pasting on Linux 在Linux的用法,自己建个命令链接:
You can create pbcopy and pbpaste commands on Linux. All you need to do is to add those two lines to the ~/.bashrc file and restart your terminal:
alias pbcopy=’xsel --clipboard --input’
alias pbpaste=’xsel --clipboard --output’
And… that’s it! I hope that those two commands will enhance your experience with the CLI.

以下是个例子:

filename=`echo $RANDOM`
echo "filename is $filename"
pbpaste > $filename.html && scp -i /local_key/id_ecdsa $filename.html upload@remote_IP_address:/root/
grep "<title>" $filename.html
Exit mobile version