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.


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.

Universal configuration monitoring and system of record for IT.
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

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

find an unused unprivileged TCP port

Terminal - find an unused unprivileged TCP port
netstat -atn | perl -0777 -ne [email protected] = /tcp.*?\:(\d+)\s+/imsg ; for $port (32768..61000) {if(!grep(/^$port$/, @ports)) { print $port; last } }'
2010-12-14 20:44:37
User: bashrc
Functions: last netstat perl
1
find an unused unprivileged TCP port

Not really better - just different ;)

There's probably a really simple solution out there somewhere...

Alternatives

There are 10 alternatives - vote for the best!

Terminal - Alternatives
netstat -atn | awk ' /tcp/ {printf("%s\n",substr($4,index($4,":")+1,length($4) )) }' | sed -e "s/://g" | sort -rnu | awk '{array [$1] = $1} END {i=32768; again=1; while (again == 1) {if (array[i] == i) {i=i+1} else {print i; again=0}}}'
2009-03-27 20:38:43
User: mpb
Functions: awk netstat sed sort
4

Some commands (such as netcat) have a port option but how can you know which ports are unused?

(netstat -atn | awk '{printf "%s\n%s\n", $4, $4}' | grep -oE '[0-9]*$'; seq 32768 61000) | sort -n | uniq -u | head -n 1
netstat -atn | perl -ane 'if ( $F[3] =~ /(\d+)$/ ) { $x{$1}=1 } END{ print( (grep {!$x{$_}} 32768..61000)[0] . "\n" )}'
netstat -tan | awk '$1 == "tcp" && $4 ~ /:/ { port=$4; sub(/^[^:]+:/, "", port); used[int(port)] = 1; } END { for (p = 32768; p <= 61000; ++p) if (! (p in used)) { print p; exit(0); }; exit(1); }'
2012-01-26 20:42:56
User: wirawan0
Functions: awk netstat
0

This is also perl-less, and only uses AWK as its postprocessor. Tested with GAWK and MAWK.

port=32768; while netstat -atn | grep -q :$port; do port=$(expr $port + 1); done; echo $port
2013-08-29 17:55:55
User: presto8
Functions: echo expr grep netstat
0

Should work with sh, bash, etc.

Know a better way?

If you can do better, submit your command here.

What others think

Our A bottle of champagne Preference, Where the High-class influences Financial savings Traditional Custom Handbags regarding 90% off of, it\'s high time! My Champagne TasteWhere the luxurious is with the Savingsits Time! At My own Champagne Preference, the luxury is with the personal savings having authentic artist handbags for 90% off! The Bubbly Flavor is undoubtedly an interesting brand-new on the internet dollar auction that has traditional designer handbags, components as well as top quality department shop on line in a choice of a cent market or perhaps a get it now solution. A few of the awesome items from that any amount of money sell consist of traditional developer handbags, gift certificates as well as other extras via such popular in addition to famous brands because Prada,, Fendi, Saks and also Bloomingdales. At this specific online cent auction website, offers are purchased in advance with regard to.50-.Ninety nine pennies just about every. This additional bidding payment means that exceptional public sale offers are positioned by simply serious customers http://www.hermesbeltsbirkinkellybag.co.uk/ just. All deals can start $0.10 without any hold. The particular sell selling price boosts by simply two cents whenever a wager is defined by the prospective buyer. Furthermore, the public auction minutter raises by way of a the least 10 seconds with every put money, allowing almost all customers the ability to place a put money just like they can currently have within a classic market. In the event the public sale timer actually reaches no, the last bidder makes nearly 90% over retail price in the auctioned merchandise. No prospective buyer simply leaves our own cent public sale empty passed. A new get it right now choices are provided to all those buyers who missing the any amount of money auction nevertheless desire to purchase one individuals legitimate custom made handbags, on line or another great solutions with a adjusted price. While using get it currently solution, the item is provided on sale add up to the particular list price on the merchandise without worrying about valuation on the actual offers placed by that particular prospective buyer from our own on-line cent market. At Our Sparkling wine Flavor, the vision would be to give the customers while using greatest authentic developer handbags and other items whilst offering top grade customer care. Just about all things on offer at this on-line cent public auction are generally bound to always be completely new as well as totally real products. Each item acquired on our penny auction website is shipped with warranty in addition to reliability docs so that you can stress the deal with high quality.

Comment by stephanieg915 1 week ago

Vacation is a fantastic time for some sort of vacation cruise and a vessel journey is a superb time and energy to flavor brand-new smells. That may seem like a new step for you to non-cruisers, however people who board cruise lines realize that many delivers get on the machine outlets with high quality along with specialized items. It is not rare for the vacation cruise ship retail outlet for you to investment lots of superb scents. And precisely what better time for it to case brand-new aromas than you are on a spead boat journey family vacation? Even so there are additional details to have perfume on the cruise filling.Developer Europe will certainly become respected about September 5, 2013 for the David M. Koch Movies, Lincoln Centre, The big apple because of the This Premium Local authority of The Gallery with the Manner pattern Initiate of Engineering (Suit). This Couture Council is going to be approving Kors while using 2013 Couture Local authority Prize with regard to Virtuosity of favor development.The most favored porcelain assume girls using this collection contains a impressive mother-of-pearl contact that's commonly studded together with uric acid so as to add far more curiosity these types of superb timepieces. A portion of the most luxurious wrist watches via the series consist of your MK Flower Silver Watch and also the MK White-colored Ceramic Wrist watches with regard to Woman along with New mother of Bead Switch in addition to Gold Glitz.It may perhaps distress chances are you'll which the primary nearly all well-liked wedding party insurance policy insurance policy coverage say occurs when a marriage go shopping the vast majority of unexpected profits smashed and also your beloved partner emerges a married relationship ceremony outfit. Provided wedding ceremony clothing is this kind of a vital and also gentle component of wedding ceremony, it's really individual typically a good customary component associated with fearfulness for anyone in which acquire wedding insurance.Every piece from the Location This year Assortment could be used very easily, satisfied and also glamorously through the woman on the road. No surprise are at the top of every single women's checklist to be a vogue top.Presently, bags have ended right up becoming vital type add-ons. Apart from being sophisticated, handbags are likewise extremely handy. Many beneficial tools could possibly be kept. Mostly females desire to carry fashionable bags. Various firms help to make fairly popular bags right now. Between likely the coolest bags tend to be bronze hamilton sizable company logo trademark bag. Most of these handbags are usually superior in addition to go far about the minute. A number of people make use of MK Handbags presently.In 1994, Gianni Versace made a limited edition number of jewelry wrist watches, jumping through effort involving the well known developer Franck Muller, exactly who founded and made the assortment in Geneva. Versace is assigned to sophistication, complexity and concentrate upon distinct, and that is shown into their watch variety.With a sluggish start December, individuals point out"Delighted Holiday! Jesus is the reason for that time! Enthusiasm was developed from The holiday season. This kind of child birthed at Xmas each of our long lasting trust turned out to be your http://www.hermesbeltsbirkinkellybag.co.uk/ child regarding The almighty, in who Our god used a lot admiration and also chance to assure we might possibly be happy as part of his existence. Trade the reveals this shows that you are interest to other people. Now will you be all set to get a Gifts, I've got some ideas I prefer to give out. Shopping on the web is a wonderful word of advice for people who will not need to venture out in to the looking hurry correct well before and so on The holiday season Eve. Having a wide selection of presenting tips along with presents from which to choose to all price varies, shopping on-line is undoubtedly an excellent alternate this specific Holiday.

Comment by stephanieg915 6 days ago

www.canadagoosefemmehomme2016.fr/snow-mantra-canada-goose_155.html

www.canadagoosefemmehomme2016.fr/canada-goose-new-york-price_202.html

www.canadagoosefemmehomme2016.fr/avis-sur-canada-goose_334.html

www.canadagoosefemmehomme2016.fr/marque-doudoune-canada-goose_74.html

www.canadagoosefemmehomme2016.fr/canada-goose-bomber-chilliwack_119.html

www.canadagoosefemmehomme2016.fr/bonnet-canada-goose_289.html

www.canadagoosefemmehomme2016.fr/canada-goose-graphite_389.html

www.canadagoosefemmehomme2016.fr/canada-goose-homme-parka_111.html

www.canadagoosefemmehomme2016.fr/canada-goose-toronto_259.html

www.canadagoosefemmehomme2016.fr/canada-goose-chateau_300.html

www.canadagoosefemmehomme2016.fr/doudoune-canada-goose-occasion_150.html

www.canadagoosefemmehomme2016.fr/canada-goose-citadel_470.html

www.canadagoosefemmehomme2016.fr/canada-goose-parka-expedition-homme_355.html

www.canadagoosefemmehomme2016.fr/doudoune-femme-canada-goose-pas-cher_407.html

www.canadagoosefemmehomme2016.fr/canada-goose-chilliwak_109.html

www.canadagoosefemmehomme2016.fr/canada-goose-nantes_367.html

www.canadagoosefemmehomme2016.fr/gants-canada-goose_312.html

www.canadagoosefemmehomme2016.fr/canada-goose-parka-langford_176.html

www.canadagoosefemmehomme2016.fr/veste-canada-goose-solde_198.html

www.canadagoosefemmehomme2016.fr/canada-goose-accessoires_183.html

www.canadagoosefemmehomme2016.fr/ou-trouver-canada-goose_232.html

www.canadagoosefemmehomme2016.fr/prix-d-une-canada-goose_130.html

www.canadagoosefemmehomme2016.fr/canada-goose-achat_221.html

Comment by sguerra376 3 days ago

www.canadagoosefemmehomme2016.fr/doudoune-canada-goose-homme-pas-cher_426.html

www.canadagoosefemmehomme2016.fr/canada-goose-inc_430.html

www.canadagoosefemmehomme2016.fr/parka-banff-canada-goose_417.html

www.canadagoosefemmehomme2016.fr/canada-goose-montpellier_353.html

www.canadagoosefemmehomme2016.fr/manteau-canada-goose-pas-cher_42.html

www.canadagoosefemmehomme2016.fr/canada-goose-bleu_63.html

www.canadagoosefemmehomme2016.fr/parka-canada-goose-chateau_400.html

www.canadagoosefemmehomme2016.fr/canada-goose-accessoires_183.html

www.canadagoosefemmehomme2016.fr/manteau-comme-canada-goose_226.html

www.canadagoosefemmehomme2016.fr/canada-goose-sans-fourrure_311.html

www.canadagoosefemmehomme2016.fr/canada-goose-occasion-femme_282.html

www.canadagoosefemmehomme2016.fr/une-canada-goose_222.html

www.canadagoosefemmehomme2016.fr/canada-goose-huron-bomber_437.html

www.canadagoosefemmehomme2016.fr/canada-goose-pour-enfant_217.html

www.canadagoosefemmehomme2016.fr/victoria-parka-canada-goose_338.html

www.canadagoosefemmehomme2016.fr/acheter-canada-goose-montreal_351.html

www.canadagoosefemmehomme2016.fr/canada-goose-violette_121.html

www.canadagoosefemmehomme2016.fr/site-canada-goose_352.html

www.canadagoosefemmehomme2016.fr/canada-goose-kaki_251.html

www.canadagoosefemmehomme2016.fr/canada-goose-kensington-parka-femme_448.html

www.canadagoosefemmehomme2016.fr/heatherton-canada-goose_484.html

www.canadagoosefemmehomme2016.fr/canada-goose-luxembourg_51.html

www.canadagoosefemmehomme2016.fr/canada-goose-couleur_471.html

www.canadagoosefemmehomme2016.fr/canada-goose-vs-pjs_443.html

www.canadagoosefemmehomme2016.fr/nouvelle-canada-goose_193.html

Comment by sguerra376 2 days ago

http://www.canadagoosefemmehomme2016.fr/doudoune-canada-goose-femme-pas-cher_65.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-noir-homme_384.html

http://www.canadagoosefemmehomme2016.fr/achat-canada-goose-en-ligne_153.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-vs-pjs_443.html

http://www.canadagoosefemmehomme2016.fr/casquette-canada-goose_134.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-doudoune-sans-manche-homme_291.html

http://www.canadagoosefemmehomme2016.fr/manteau-canada-goose-homme-pas-cher_341.html

http://www.canadagoosefemmehomme2016.fr/branta-canada-goose_271.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-parka-homme_339.html

http://www.canadagoosefemmehomme2016.fr/usine-canada-goose_85.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-parka-banff-homme_403.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-chilliwack-bomber-pas-cher_465.html

http://www.canadagoosefemmehomme2016.fr/chaussure-canada-goose_230.html

http://www.canadagoosefemmehomme2016.fr/doudoune-canada-goose-solde_316.html

http://www.canadagoosefemmehomme2016.fr/doudoune-canada-goose-site-officiel_188.html

http://www.canadagoosefemmehomme2016.fr/manteau-femme-canada-goose_248.html

http://www.canadagoosefemmehomme2016.fr/ou-acheter-une-canada-goose_313.html

http://www.canadagoosefemmehomme2016.fr/vrai-canada-goose-pas-cher_40.html

http://www.canadagoosefemmehomme2016.fr/pas-cher-canadian-goose_219.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-destockage_165.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-vrai_249.html

http://www.canadagoosefemmehomme2016.fr/femme-canadian-goose_104.html

http://www.canadagoosefemmehomme2016.fr/manteau-homme-canada-goose_82.html

http://www.canadagoosefemmehomme2016.fr/parajumpers-canada-goose_203.html

Comment by sguerra376 2 days ago

www.canadagoosefemmehomme2016.fr/prix-d-une-doudoune-canada-goose_390.html

www.canadagoosefemmehomme2016.fr/blouson-canada-goose-homme_467.html

www.canadagoosefemmehomme2016.fr/canada-goose-femme-pas-cher_139.html

www.canadagoosefemmehomme2016.fr/canada-goose-point-de-vente_371.html

www.canadagoosefemmehomme2016.fr/kensington-canada-goose_234.html

www.canadagoosefemmehomme2016.fr/canada-goose-chilliwack-bomber-pas-cher_465.html

www.canadagoosefemmehomme2016.fr/canada-goose-chateau_300.html

www.canadagoosefemmehomme2016.fr/canada-goose-manteau-femme_178.html

www.canadagoosefemmehomme2016.fr/homme-canadian-goose_180.html

www.canadagoosefemmehomme2016.fr/doudoune-longue-canada-goose_447.html

www.canadagoosefemmehomme2016.fr/canada-goose-homme-noir_115.html

www.canadagoosefemmehomme2016.fr/canada-goose-pour-enfant_217.html

www.canadagoosefemmehomme2016.fr/canada-goose-boutique-paris_167.html

www.canadagoosefemmehomme2016.fr/canada-goose-femme-montebello_90.html

www.canadagoosefemmehomme2016.fr/canada-goose-hybridge-hoody_382.html

www.canadagoosefemmehomme2016.fr/livigno-canada-goose_72.html

www.canadagoosefemmehomme2016.fr/manteau-comme-canada-goose_226.html

www.canadagoosefemmehomme2016.fr/survetement-canada-goose_356.html

www.canadagoosefemmehomme2016.fr/canada-goose-grise-homme_468.html

www.canadagoosefemmehomme2016.fr/fourrure-canada-goose_70.html

www.canadagoosefemmehomme2016.fr/parka-canada-goose-langford_425.html

www.canadagoosefemmehomme2016.fr/kensington-parka-canada-goose_257.html

www.canadagoosefemmehomme2016.fr/langford-canada-goose_290.html

www.canadagoosefemmehomme2016.fr/canada-goose-grande-taille_92.html

www.canadagoosefemmehomme2016.fr/canada-goose-modele-victoria_409.html

Comment by sguerra376 2 days ago

Your point of view

You must be signed in to comment.