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.
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 modifies the output of ls so that the file size has commas every three digits. It makes room for the commas by destructively eating any characters to the left of the size, which is probably okay since that's just the "group".
Note that I did not write this, I merely cleaned it up and shortened it with extended regular expressions. The original shell script, entitled "sl", came with this description:
: For tired eyes (sigh), do an ls -lF plus whatever other flags you give
: but expand the file size with commas every 3 digits. Really helps me
: distinguish megabytes from hundreds of kbytes...
: Corey Satten, firstname.lastname@example.org, 11/8/89
Of course, some may suggest that fancy new "human friendly" options, like "ls -Shrl", have made Corey's script obsolete. They are probably right. Yet, at times, still I find it handy. The new-fangled "human-readable" numbers can be annoying when I have to glance at the letter at the end to figure out what order of magnitude is even being talked about. (There's a big difference between 386M and 386P!). But with this nifty script, the number itself acts like a histogram, a quick visual indicator of "bigness" for tired eyes. :-)
When booting a VM through OpenStack and managed through cloudinit, the hosts file gets to write a line simiar to
127.0.1.1 ns0.novalocal ns0
This command proven useful while installing a configuration manager such as Salt Stack (or Puppet, or Ansible) and getting node name
credit shall fall to this for non-gzipped version:
Works great on Mac OSX.
This function tests the hostname:port from any url to see if it is accepting connections.
It uses netcat with a 5s timeout, if a port number is not part of the url passed to it, then default port 80 is tested.
Thx Mass1 for the sharing
Print the IP address and the Mac address in the same line
Similar to the following:
curl -I <URL>
but curl -I performs a HEAD request, which can yield different results.
Calculate the date of Sysadmin day (last Friday of July) of any given year
change the path where you are, when is executed, is usefule when you've got folders to classify something like a tags, you've got devel/dist, android/ios, etc. like:
You can change between devel/project folder to dist/project without leave project.
If somebody has a better idea to do that without replace command.
It requires https://jqplay.org/, that comes with brew: brew install jq
Replace "APIKEY" with your public apikey
Before: :key => 'value'
After: key: 'value'
I have only tested this a little, so please don't run this on anything important unless you have version control or other backups!
Change lang from ru to something else.
Curl version - Mac OS etc, any system w/o wget.
btrfs checksum errors console report.
Not better, but more lightweight (sed instead of perl).
Above command is reduced due to length restriction of less than 256 characters and entity encoding of "Save" command on this page. This is complete command (best without entity encoding):
echo -e '\x2Helo folks\t!\r' | sed "y/\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9\xA\xB\xC\xD\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20/␀␁␂␃␄␅␆␇␈␉␊␋␌␍␎␏␐␑␒␓␔␕␖␗␘␙␚␛␜␝␞␟␠/"
Using the $PIPESTATUS array you can get the results of a command in a sequence of commands piped together. The command above returns the result of grep -o "bob", which is exit result of 1 since no match was made.
Mac OSX friendly version of google function
Useful if you don't have at hand the ability to automatically create a booklet, but still want to.
F is the number of pages to print. It *must* be a multiple of 4; append extra blank pages if needed.
In evince, these are the steps to print it, adapted from https://help.gnome.org/users/evince/stable/duplex-npage.html.en :
1) Click File ▸ Print.
2) Choose the General tab.
Under Range, choose Pages.
Type the numbers of the pages in this order (this is what this one-liner does for you):
n, 1, 2, n-1, n-2, 3, 4, n-3, n-4, 5, 6, n-5, n-6, 7, 8, n-7, n-8, 9, 10, n-9, n-10, 11, 12, n-11...
...until you have typed n-number of pages.
3) Choose the Page Setup tab.
- Assuming a duplex printer:
Under Layout, in the Two-side menu, select Short Edge (Flip).
- If you can only print on one side, you have to print twice, one for the odd pages and one for the even pages.
In the Pages per side option, select 2.
In the Page ordering menu, select Left to right.
4) Click Print.
translate some text
Change lang from ru to something else.
When you run a lot of containers the built in docker ps output becomes unreadable. This command formats the output to be easier on the eyes.
Requires q (https://github.com/harelba/q) text as data.