bash-script如何将空剪贴板视为守护进程或cron-job?

时间:2021-11-25 16:20:49

Am not sure if this is correct or can be done better. For any suggestion feel free to post here. thx in advance.

我不确定这是否正确或可以做得更好。如有任何建议,请随时在此发布。提前thx。

Want to code a bash-script (Linux) which empties - after 30 days past by - the content of clipboard.

想要编写一个bash-script(Linux),它会在过去30天之后清空 - 剪贴板的内容。

Have tried to simply pipe the content of clipboard to directory of /dev/zero - but this does not work because "no permission" or "permission denied". How can I pipe into /dev/zero instead of using command rm ?

试图简单地将剪贴板的内容传递到/ dev / zero的目录 - 但这不起作用,因为“没有权限”或“权限被拒绝”。如何管道进入/ dev / zero而不是使用命令rm?

here the code:

这里的代码:

#!/bin/bash
while [ 1 ]
do
find /usr/bin/xclip -selection "primary" -type f -mtime +30 -exec rm -- {} \;
done
return

while 1 with do and done will be substituted by code for daemon or cron-job.

而带有do和done的1将被守护进程或cron-job的代码替换。

The directory of clipboard in this snippet refers to Ubuntu.

此代码段中的剪贴板目录是指Ubuntu。

1 个解决方案

#1


1  

You mixed up /dev/null and /dev/zero. The first is a sink to swallow everything you pipe in (and in case you read from it returns EOF at once), the other is a device outputting any number of zero bytes as long as you read from it. You are not allowed to write to /dev/zero as it is only supposed to be read from.

你混合了/ dev / null和/ dev / zero。第一个是用于吞下你所管道的所有内容的接收器(如果你从中读取它,则立即返回EOF),另一个是输出任意数量零字节的设备,只要你从中读取即可。您不能写入/ dev / zero,因为它只能被读取。

For your task of emptying the X selection I propose this:

对于清空X选择的任务,我建议:

xclip < /dev/null

#1


1  

You mixed up /dev/null and /dev/zero. The first is a sink to swallow everything you pipe in (and in case you read from it returns EOF at once), the other is a device outputting any number of zero bytes as long as you read from it. You are not allowed to write to /dev/zero as it is only supposed to be read from.

你混合了/ dev / null和/ dev / zero。第一个是用于吞下你所管道的所有内容的接收器(如果你从中读取它,则立即返回EOF),另一个是输出任意数量零字节的设备,只要你从中读取即可。您不能写入/ dev / zero,因为它只能被读取。

For your task of emptying the X selection I propose this:

对于清空X选择的任务,我建议:

xclip < /dev/null