Take the 2-minute tour ×

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

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

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 ?

here the code:

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

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

The directory of clipboard in this snippet refers to Ubuntu.

share|improve this question
What is the event from which on you start counting the thirty days? –  Alfe Nov 13 '13 at 12:07

1 Answer 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.

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

xclip < /dev/null
share|improve this answer
thx for answer. I tried that with /dev/null already too - and terminal spit out here too "permission denied" or "no permission". –  dschinn1001 Nov 13 '13 at 20:56
I guess one should investigate which aspect causes that "permission denied" problem. Does cat /dev/null also give an error message? Does : | xclip? What are the permission bits of /dev/null? Are you sure your script file has the executable permission bit set? –  Alfe Nov 14 '13 at 8:56
thx for hints. I will check it. –  dschinn1001 Nov 16 '13 at 20:00

Your Answer


