Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 ?

share|improve this question
3  
add comment

1 Answer

up vote 11 down vote accepted

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
share|improve this answer
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 5: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
add comment

Your Answer

 
discard

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.