Hide

What's this?

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/

Get involved!

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.

Hide

Stay in the loop…

Follow the Tweets.

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

Subscribe to the feeds.

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Check if a machine is online with better UI

Terminal - Check if a machine is online with better UI
echo -n "IP Address or Machine Name: "; read IP; ping -c 1 -q $IP >/dev/null 2>&1 && echo -e "\e[00;32mOnline\e[00m" || echo -e "\e[00;31mOffline\e[00m"
2012-02-09 07:00:03
User: crlf
Functions: echo ping read
1
Check if a machine is online with better UI

I have used single packet, and in a silent mode with no display of ping stats. This is with color and UI improvement to the http://www.commandlinefu.com/commands/view/10220/check-if-a-machine-is-online. It is as per the enhancements suggested.

Alternatives

There are 8 alternatives - vote for the best!

Terminal - Alternatives
ping -c 1 -q MACHINE_IP_OR_NAME >/dev/null 2>&1 && echo ONLINE || echo OFFLINE
2012-02-09 06:30:55
User: UnixNeko
Functions: echo ping
Tags: echo IP ping
9

PING

parameters

c 1 limits to 1 pinging attempt

q makes the command quiet (or silent mode)

/dev/null 2>&1 is to remove the display

&& echo ONLINE is executed if previous command is successful (return value 0)

|| echo OFFLINE is executed otherwise (return value of 1 if unreachable or 2 if you're offline yourself).

I personally use this command as an alias with a predefined machine name but there are at least 2 improvements that may be done.

Asking for the machine name or IP

Escaping the output so that it displays ONLINE in green and OFFLINE in red (for instance).

ping1 IPaddr_or_hostname
2012-02-09 17:26:32
User: waibati
Tags: echo IP ping
0

export THISOS="`uname -s`"

if [ "$THISOS" = "SunOS" ]

then

export THISRELEASE="`uname -r`"

ping1() { ping -s $1 56 1 | egrep "^64"; }

elif [ "$THISOS" = "AIX" ]

then

export THISRELEASE="`uname -v`.`uname -r`"

ping1() { ping -w ${2:-1} $1 56 1 | egrep "^64"; }

elif [ "$THISOS" = "Linux" ]

then

export THISRELEASE="`uname -r`"

ping1() { ping -c 1 -w ${2:-1} $1 | egrep "^64"; }

fi

Know a better way?

If you can do better, submit your command here.

Your point of view

You must be signed in to comment.

Related sites and podcasts