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

Selecting a random file/folder of a folder

Terminal - Selecting a random file/folder of a folder
shuf -n1 -e *
2011-03-23 03:52:56
User: seungwon
11
Selecting a random file/folder of a folder

I used only shuf command.

Alternatives

There are 4 alternatives - vote for the best!

Terminal - Alternatives
ls -1 | shuf -n 1
2011-03-13 22:14:57
User: quincymd
Functions: ls
Tags: bash random
2

random file from files in directory

find . | shuf -n1
2011-04-01 22:57:01
Functions: find
Tags: bash random
2

Also looks in subfolders

a=(*); echo ${a[$((RANDOM % ${#a[@]}))]}
2011-03-18 13:24:52
User: putnamhill
Functions: echo
Tags: bash random
-1

Here's a bash version using an array.

for i in *; do echo "$i"; done | shuf -n1
2011-03-17 17:48:42
User: johnraff
Functions: echo
Tags: bash random
-2

Choose random file from current folder. Avoids using ls.

ls -1 | awk 'BEGIN{srand()} {x[NR] = $0} END{print "Selected", x[1 + int(rand() * NR)]}'
2011-03-13 20:05:06
User: saibbot
Functions: awk ls
Tags: awk random
-3

I use this command to select a random movie from my movie collection..

Know a better way?

If you can do better, submit your command here.

What others think

Nice. Got to be the most concise so far.

Comment by quincymd 304 weeks and 4 days ago

Brilliant! I was doing: find . -maxdepth 1|sort -R|head -n1

much much better your way!

Comment by j_melis 304 weeks and 3 days ago

Wow! That's why they say to read the manual... Very nice.

Comment by johnraff 304 weeks and 2 days ago

Can someone explain to me why this is useful?

Any use case?

Comment by Neo23x0 303 weeks and 6 days ago

This is a nice use of the "-e" but be careful that you know the max number of files in the directory. You can get a "Argument list too long" error with this one. The alternative #8090 works even with a large number of files:

ls|shuf -n1

and it's actually shorter if you remove the superfluous "-1" on the ls, as noted in the comments. I was surprised to find the version with the pipe was faster on my system starting at about 4000 files.

Comment by splante 263 weeks and 4 days ago

Females are unable to do without handbags lately. As contemporary society is actually developing now days, madness of women handbags is different a whole lot. During the early days to weeks, girls handbags are simply just only bags that are mainly carried on special occasions. The good news is, it might be a necessity of latest contemporary society. Nowadays, these types of bags are produced wealthy in technological know-how. Cell phone, tote and kinds of facial foundation backpacks are maintained of these bags. Those who are office goers females, in addition they hold handbags to keep essential books, files etcetera. therefore, it is really extremely important for ladies to hold handbags exterior. The truth http://www.hermesbeltsbirkinkellybag.co.uk/ is they want to meet the preference of girls. They've got changed their own styles of handbags every now and then. Your increasing characteristics regarding handbags are earning this more useful. Not only this, smaller measurement handbags will also be utilized in holding leisure time pastime, substantial measurement or above sizing handbags get to be the craze connected with style. Many esteemed brand names are creating ladies handbags. They experimented with help to make appealing handbags using valuable features. Handbags may be harmonized based on the affair as well as festivities which are likely to show up at. Proper handbags will assist you to take your entire critical forms and the wonderful regarding wedding ceremony as well as unique events which will match up people functions way too. You will discover vast assortment of handbags can be purchased in industry. You can buy different colors, models as well as components to discover the perfect form of handbag with you. Typically the most popular handbags are the type that are made from buckskin.Though, handbags are not only utilized for fashion purpose. The majority of them usually are should regarding business girls. They need to bring significant files, company tech material which means that the particular handbags should be created useful. It is finally led to a tremendous range of classy still practical bags from the the surface of the developers. There are several common manufacturers connected with handbags that are genuinely popular within market. These are typically handbags, Prada as well as bags. The different kinds of most of these branded women handbags are actually really appealing and chic. In recent years, the company handbag can be getting to brand new elevations. It's the best practice to access manner industry. To get many important specifics of females handbags, you can go ahead and take aid of web. There are several internet sites through which one can get depth specifics of this. The truth is you can buy these kinds of bags by means of buying online. There are plenty of searching web-sites are offered where you should buy these kinds of stylish bags.

Comment by stephanieg915 5 days ago

Old-fashioned developer handbags aren't the luxurious that just this famous people can pay for. Every woman needs to have no less than one handbag showing a vintage custom made label. Buying antique custom handbags is often a incredible technique of broadening your current handbag series. If you are remaining in Quarterly report, you'll find a variety of stores presenting antique developer handbags Questionnaire.A handbag is central to the addition of which does the trendy and classy appearance of a girl. This will serve not only as a possible object to have the basics, however can also be a trend affirmation. It may be best to decide if the style bag will probably be utilised often or maybe you happen to be more interested in purchasing the http://www.hermesbeltsbirkinkellybag.co.uk/ pre-loved designer bag to be a collectable. In case you are clothed on an event, look will probably be imperfect to an degree, and not using a custom handbag, including Alfredia Dior motorola clutch. It is often asserted your handbag affirms a lot about the style of human being you are. In fact, having a vintage luxury bag could possibly determine your style as well as your societal ranking.When you happen to be emptying your bank account in these types of antique, high end custom made handbags, make certain you choose the right. You need to buy from some sort of well-known vendor. The dealer must be able to response your entire questions and have a good name for staying truthful and also good. In addition, by no means obtain most things that is actually fatigued or maybe tarnished. Many wear and tear is really a offered simply because it might create charm for the classic high-class bag. But a lot of bag damage might make your handbag search employed.A lady hauling extra designer handbag, that's vintage in the era and style, talks a great deal of the woman's cultural standing. In reality, retro artist synthetic leather handbags communicate on your sociable standing inside many persuasive means. It is very important make sure that artist handbags Modern australia are usually in equilibrium along with your ensemble. It indicates your classic, luxury developer handbag moves nicely along with your clothing. Retro extravagance bags are known for their durability along with awesome designs, that is certainly the rationale in their immense recognition amongst women of all ages.If you need to get some of the best antique custom handbags Australia at best marketplace prices, pay a visit to avoir.web.au.

Comment by stephanieg915 5 days ago

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

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

http://www.canadagoosefemmehomme2016.fr/canada-goose-longue-homme_301.html

http://www.canadagoosefemmehomme2016.fr/magasin-d-usine-canada-goose_331.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-pas-cher-paris_354.html

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

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

http://www.canadagoosefemmehomme2016.fr/manteau-canada-goose-a-vendre_450.html

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

http://www.canadagoosefemmehomme2016.fr/ontario-canada-goose_96.html

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

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

http://www.canadagoosefemmehomme2016.fr/canada-goose-france-site-officiel_307.html

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

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

http://www.canadagoosefemmehomme2016.fr/prix-canada-goose_398.html

http://www.canadagoosefemmehomme2016.fr/vetement-goose-canada_345.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-printemps-haussmann_323.html

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

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

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

Comment by sguerra376 3 days ago

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

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

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

www.canadagoosefemmehomme2016.fr/canada-goose-ou-parajumpers_414.html

www.canadagoosefemmehomme2016.fr/canada-goose-parka-trillium-femme_429.html

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

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

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

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

www.canadagoosefemmehomme2016.fr/canada-canada-goose_246.html

www.canadagoosefemmehomme2016.fr/canada-goose-montebello-parka_81.html

www.canadagoosefemmehomme2016.fr/canada-goose-boutique-en-ligne_184.html

www.canadagoosefemmehomme2016.fr/rideau-canada-goose_303.html

www.canadagoosefemmehomme2016.fr/palliser-canada-goose_261.html

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

www.canadagoosefemmehomme2016.fr/canada-goose-magasin-paris_280.html

www.canadagoosefemmehomme2016.fr/doudoune-canada-goose-homme-prix_243.html

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

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

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

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

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

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

Comment by sguerra376 3 days ago

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

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

http://www.canadagoosefemmehomme2016.fr/canada-canada-goose_246.html

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

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

http://www.canadagoosefemmehomme2016.fr/canada-goose-femme-rouge_59.html

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

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

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

http://www.canadagoosefemmehomme2016.fr/destockage-canada-goose_286.html

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

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

http://www.canadagoosefemmehomme2016.fr/vetement-goose-canada_345.html

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

http://www.canadagoosefemmehomme2016.fr/canada-goose-��-paris_227.html

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

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

http://www.canadagoosefemmehomme2016.fr/canada-goose-au-canada-prix_54.html

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

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

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

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

Comment by sguerra376 2 days ago

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

http://www.canadagoosefemmehomme2016.fr/canada-goose-montebello-prix_254.html

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

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

http://www.canadagoosefemmehomme2016.fr/acheter-canada-goose-pas-cher_124.html

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

http://www.canadagoosefemmehomme2016.fr/magasin-canada-goose_93.html

http://www.canadagoosefemmehomme2016.fr/pantalon-canada-goose_315.html

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

http://www.canadagoosefemmehomme2016.fr/chapeau-canada-goose_238.html

http://www.canadagoosefemmehomme2016.fr/entrepot-canada-goose_158.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-solaris-parka_375.html

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

http://www.canadagoosefemmehomme2016.fr/ecusson-canada-goose_168.html

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

http://www.canadagoosefemmehomme2016.fr/soldes-canada-goose_137.html

http://www.canadagoosefemmehomme2016.fr/taille-canada-goose_79.html

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

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

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

http://www.canadagoosefemmehomme2016.fr/boutique-canada-goose-montreal_456.html

http://www.canadagoosefemmehomme2016.fr/solaris-parka-canada-goose_110.html

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

http://www.canadagoosefemmehomme2016.fr/canada-goose-femme-rouge_59.html

http://www.canadagoosefemmehomme2016.fr/canada-goose-france-site-officiel_307.html

http://www.canadagoosefemmehomme2016.fr/magasin-canada-goose-a-paris_387.html

Comment by sguerra376 1 day ago

www.canadagoosefemmehomme2016.fr/boutique-canada-goose_378.html

www.canadagoosefemmehomme2016.fr/doudoune-canada-goose_330.html

www.canadagoosefemmehomme2016.fr/canada-goose-site-fiable_136.html

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

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

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

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

www.canadagoosefemmehomme2016.fr/bomber-canada-goose_240.html

www.canadagoosefemmehomme2016.fr/canada-goose-france-site-officiel_307.html

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

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

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

www.canadagoosefemmehomme2016.fr/doudoune-canadian-goose_205.html

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

www.canadagoosefemmehomme2016.fr/borden-canada-goose_442.html

www.canadagoosefemmehomme2016.fr/doudoune-canada-goose-femme-occasion_164.html

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

www.canadagoosefemmehomme2016.fr/logo-canada-goose_138.html

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

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

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

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

www.canadagoosefemmehomme2016.fr/constable-canada-goose_67.html

www.canadagoosefemmehomme2016.fr/canada-goose-victoria-pas-cher_211.html

www.canadagoosefemmehomme2016.fr/site-officiel-canada-goose_432.html

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

Comment by sguerra376 1 day ago

Your point of view

You must be signed in to comment.