About nixCraft

Topics

BASH shell: How to create empty temporary files quickly

Posted by Vivek Gite [Last updated: May 15, 2007]

Use the any one of the following command to create empty files. The first command is special as it use the redirection operator >, the redirection refers to the standard output. So you are creating a new file or destroying existing file:

$ > /tmp/filename
$ touch > /tmp/newfilename
$ echo "" > /tmp/filename

Tell us how we're doing: Please answer a few questions about your experience to help us improve nixCraft.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. Nathan Says:

    The first command works fine. It creates a neat and empty file.

    Second command does not work, “touch” is a command the file is the only parameter. It should not use a redirect as shown above.

    touch /tmp/newfilename

    Since this is a command it also works consistently no matter what shell interpreter someone might be using.

    The third one is missing a -n on the echo to prevent the newline from being sent to the file making it less than empty.

    echo -n “” > /tmp/filename

  2. me Says:

    use “mktemp /tmp/tempfile.XXXXXXXXX” to make a secure tempory file and avoid exploits

  3. artiomix Says:

    mktemp! wow! Some time ago I wrote my own utility which do the same as mktemp.. shit

  4. pooran mal Says:

    how we create a empty shell??

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.