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.

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:



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!

Top Tags



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

Lists unambigously names of all xml elements used in files in current directory

Terminal - Lists unambigously names of all xml elements used in files in current directory
grep -h -o '<[^/!?][^ >]*' * | sort -u | cut -c2-
2009-06-17 00:22:18
User: thebodzio
Functions: cut grep sort
Lists unambigously names of all xml elements used in files in current directory

This set of commands was very convenient for me when I was preparing some xml files for typesetting a book. I wanted to check what styles I had to prepare but coudn't remember all tags that I used. This one saved me from error-prone browsing of all my files. It should be also useful if one tries to process xml files with xsl, when using own xml application.


There is 1 alternative - vote for the best!

Terminal - Alternatives
grep -Eho '<[a-ZA-Z_][a-zA-Z0-9_-:]*' * | sort -u | cut -c2-
2009-08-05 21:54:29
User: inkel
Functions: cut grep sort
Tags: sort grep cut xml

This one will work a little better, the regular expressions it is not 100% accurate for XML parsing but it will suffice any XML valid document for sure.

Know a better way?

If you can do better, submit your command here.

What others think

Just a few small hints ...

1. I think the "-e" option is not needed.

2. Why "$(pwd)/*" and not simply "*"?

3. "sort | uniq" can be abbreviated: "sort -u"

Comment by inof 409 weeks and 3 days ago

Thanks a lot for your advice! You're right in all pointed matters and thanks to you this one-liner became much shorter and elegant. I'm sending you a virtual can/bottle/pint/bathtub (whatever rows your boat) of your favorite beverage :).

Comment by thebodzio 407 weeks and 3 days ago

Actually this will display not only the names but also append any attribute that exists on the element, so it might give you errors. Try running it on a folder with XSLT files.

I'll try to submit a new version of the command if I've time.

Comment by inkel 402 weeks and 3 days ago

True. I've got a TODO note about that with the script.

Comment by thebodzio 399 weeks and 2 days ago

Okee. I've reviewed my entry. It's still quite far from caring about many aspects of xml specification but does the job much better than previous version. First of all it shows only element name not element name _and_ attributes as inkel noticed. It also shows element names that contain characters with diacritic signs (like polish "książka" ? book or "tytuł" ? title). Finally I took "cut -c2-" from inkel's script. @inkel: thanks for your interrest and tip about "cut"! :)

Comment by thebodzio 399 weeks and 2 days ago

Your point of view

You must be signed in to comment.