Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a script that when executed generates a temp file that i want deleted 10 minutes after the script completes.

I have looked at the "at" command which does what I need, but it requires interactive input. Is there any way to do this non-interactively?

share|improve this question
up vote 2 down vote accepted

From man at:

at and batch read commands from standard input or a specified file which are to be executed at a later time, using /bin/sh.

So just send the command you would type in interactively to at as input:

echo 'rm that.file' | at now+10min
share|improve this answer
that will work, don't know why I didn't think of piping to at. – David Berkan Apr 5 '13 at 11:32
I just remembered a similar problem I had with ftp some years ago which had a solution I could reuse, this also seems to work: at now + 10 min <<'EOF' rm $file EOF – David Berkan Apr 5 '13 at 11:40

An alternative is using the command sleep. For example 'sleep 600 && rm that.file' will delete that.file after 600 seconds ('man sleep' shows a more detailed example).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.