6

I saw some postinst script

    # setting wget options
    :> wgetrc
    echo "noclobber = off" >> wgetrc
    echo "dir_prefix = ." >> wgetrc
    echo "dirstruct = off" >> wgetrc
    echo "verbose = on" >> wgetrc
    echo "progress = dot:default" >> wgetrc
    echo "tries = 2" >> wgetrc

What does the :> do here ?

Mat
  • 51,578
  • 10
  • 158
  • 140
daisy
  • 53,527
  • 78
  • 236
  • 383
  • 3
    See also [What purpose does the colon builtin serve?](http://unix.stackexchange.com/questions/31673/what-purpose-does-the-colon-builtin-serve) – Michael Mrozek Apr 28 '12 at 03:27

1 Answers1

12

Nulls out the file called "wgetrc" in the current directory. As in creates an empty file "wgetrc" if one doesn't exist or overwrites one with nothing if it does.

Equivalent to the following:

cat /dev/null > wgetrc
Kevin
  • 40,087
  • 16
  • 88
  • 112
  • 4
    Just to clear any possible ambiguity, "nulls out" and "overwriting with nothing" does not mean that "null" characters (hex 00) are written to the space the file was using.. It only tells the filesystem to "mark" that file as having no data in it... Also. you do not need the `:` at all... `>file` is enough. – Peter.O Apr 28 '12 at 05:30
  • 3
    @Peter.O: There are a few cases where `>file` will not have the same affect as `:>file`. In particular some interactive shells (zsh by default, bash with options) will interpret that as a time to ask the user for input rather than using null. If you want your code to be portable between interactive and script environments (so it works the same copy/pasted as in a script for example) using `:>file` is safer. Otherwise, your point about 'nulls out' is well given. – Caleb Apr 28 '12 at 14:55