commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for:
This is shorter and actually much faster than >/dev/null (see sample output for timings)
Plus, it looks like a disappointed face emoticon.
There are 3 alternatives - vote for the best!
If you can do better, submit your command here.
You must be signed in to comment.
I was curious where this was documented. In the Bash man page under "SHELL BUILTIN COMMANDS" : is the first built in command. Here is the description:
: [arguments]
No effect; the command does nothing beyond expanding arguments and performing any specified redirections. A zero exit code is returned.
help ::: :
Null command.
No effect; the command does nothing.
Exit Status:
Always succeeds.
That makes a pipe status error :
ls |: ; echo ${PIPESTATUS[@]}141 0
where >/dev/null makes no error
I tried it and it's much more slower than redirection:
time sh test.sh
real 0m0.342s
user 0m0.205s
sys 0m0.096s
time sh test1.sh
real 0m7.300s
user 0m0.266s
sys 0m1.912s
test.sh:
for i in `seq 1 100`
do
for j in `seq 1 100`
do
echo i >/dev/null
done
done
test1.sh:
for i in `seq 1 100`
do
for j in `seq 1 100`
do
echo i|:
done
done
giaomuf,
I reproduced your results, and the per-invocation overhead does seem to be higher, but I get this when applying the redirection to the script as a whole instead of invoking it from within the script:
time sh test/spew.sh > /dev/nullreal 0m0.285s
user 0m0.148s
sys 0m0.136s
time sh test/spew.sh |:real 0m0.008s
user 0m0.000s
sys 0m0.008s
cat spew3.shfor i in `seq 1 100`
do
for j in `seq 1 100`
do
echo i
done
done
I think this is the usage the author intended, and it does seem to be much faster.
try this:
cat|:now type in some letters. See how they get echoed to the screen. Now hit a newline. What happens?
.
now contrast this with:
cat>/dev/nullwhich will soak up all kinds of control char except ^d
This it not faster. In fact, just slower.
You are using a pipe thus calling fork and running inside a subshell where at the same time >dev/null just use a simple file redirection.
rany:~$ time >/dev/nullreal 0m0.000suser 0m0.000ssys 0m0.000srany:~$ time :|:real 0m0.002suser 0m0.008ssys 0m0.000srany:~$Expanding on sputnick's point, this command is not a good idea, because it can cause the upstream code to terminate prematurely. In the example below, the inline perl script is supposed to create a new file foo after producing some output, but it fails to create the file if it is piped through :. (NB: that the amount of output sent to the screen needs to be sufficiently large to observe this effect. YMMV)
ls fools: foo: No such file or directory
perl -e 'print 0 for 1..10000; open FOO, ">foo"' |:ls fools: foo: No such file or directory
perl -e 'print 0 for 1..10000; open FOO, ">foo"' > /dev/nullls foofoo
time for x in {1..1000} ; do cat /tmp/VAR.log >/dev/null ; donereal 0m2.956suser 0m0.320ssys 0m0.790stime for x in {1..1000} ; do cat /tmp/VAR.log :| ; done-bash: syntax error near unexpected token `;'D'oh...
time for x in {1..1000} ; do cat /tmp/VAR.log |: ; donereal 0m4.903suser 0m0.380ssys 0m1.480sanyway, it seems to take longer for me. Shorter to type though.
This command runs faster because there's a BROKEN PIPE!
In fact |: works that way:
- the : builtin is executed and its stdin is attached to the command stdout
- when the : execution finishes its stdin is closed, and so the stdout of command.
- this causes a BROKEN PIPE resulting in the error of $PIPESTATUS