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.
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:
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:
If your contact information was entered when your user account was created (it gets added to /etc/passwd) then this gets that info and creates a QR code for you automatically
Randomizes a file. The opposite of sort is sort -R!
The same with colors
more idiomatic version of the same, using the flip-flop-operator; also printing lines with '//'-style comments
This is a naive way of finding source code comments in source code files that use C-like comments: // and /*...*/
Using tail to follow and standard perl to count and print the lps when lines are written to the logfile.
Recursively delete empty directories. Use with care.
This uses Perl's rename utility (you may have to call it as prename on your box) and won't choke on spaces or other characters in filenames. It will also zero pad a number even in filenames like "vacation-4.jpg".
This is from perldoc -q random.*line, which says:
This has a significant advantage in space over reading the whole file in. You can find a proof of this method in The Art of Computer Programming, Volume 2, Section 3.4.2, by Donald E. Knuth.
Who am I to argue with Don Knuth?
Let -p do it's voodoo and do absolutely nothing but set the output record separator :-)
Reads stdin, and outputs each line only once - without sorting ahead of time. This does use more memory than your system's sort utility.
This works by reading in two lines of input, turning each into a list of one-character matches that are sorted and compared.
No need for further filedes or substitution for splitting. Simply use read a b
[Update! Thanks to a tip from ioggstream, I've fixed both of the bugs mentioned below.]
You, yes, 𝙔𝙊𝙐, can be the terror of the Internet! Why use normal, boring bullet points in your text, when you could use a ROTATED HEAVY BLACK HEART BULLET (❥)!? (Which would also be an awesome band name, by the way).
This script makes it easy to find unusual characters from the command line. You can then cut and paste them or, if you're using a GTK application, type Control+Shift+U followed by the code point number (e.g., 2765) and then a SPACE.
USAGE: Put this script in a file (I called mine "ugrep") and make it executable. Run it from the command line like so,
The output will look like this,
☙ U+2619 REVERSED ROTATED FLORAL HEART BULLET
♡ U+2661 WHITE HEART SUIT
♥ U+2665 BLACK HEART SUIT
❣ U+2763 HEAVY HEART EXCLAMATION MARK ORNAMENT
❤ U+2764 HEAVY BLACK HEART
❥ U+2765 ROTATED HEAVY BLACK HEART BULLET
❦ U+2766 FLORAL HEART
❧ U+2767 ROTATED FLORAL HEART BULLET
⺖ U+2E96 CJK RADICAL HEART ONE
⺗ U+2E97 CJK RADICAL HEART TWO
⼼ U+2F3C KANGXI RADICAL HEART
You can, of course, use regular expressions. For example, if you are looking for the "pi" symbol, you could do this:
REQUIREMENTS: Although this is written in Bash, it assumes you have Perl installed because it greps through the Perl Unicode character name module (/usr/lib/perl5/Unicode/CharName.pm). Note that it would not have made more sense to write this in Perl, since the CharName.pm module doesn't actually include a subroutine for looking up a character based on the description. (Weird.)
BUGS: In order to fit this script in the commandlinefu limits, a couple bugs were added. ① Astral characters beyond the BMP (basic multilingual plane) are not displayed correctly, but see below. ② Perl code from the perl module being grepped is sometimes extraneously matched.
MISFEATURES: Bash's printf cannot, given a Unicode codepoint, print the resulting character to the terminal. GNU's coreutils printf (usually "/usr/bin/printf") can do so, but it is brokenly pedantic about how many hexadecimal digits follow the escape sequence and will actually die with an error if you give the wrong number. This is especially annoying since Unicode code points are usually variable length with implied leading zeros. The CharNames.pm file represents BMP characters as 4 hexits, but astral characters as 5. In the actual version of this script that I use, I've kludged around this misfeature by zero-padding to 8 hexits like so,
/usr/bin/printf "\U$(printf "%08x" 0x$hex)"
TIP 1: The author recommends "xsel" for command line cut-and-paste. For example,
ugrep biohazard | xsel
TIP 2: In Emacs, instead of running this command in a subshell, you can type Unicode code points directly by pressing Control-Q first, but you'll likely want to change the default input from octal to hexadecimal. (setq read-quoted-char-radix 16).
TIP 3: Of course, if you're using X, and you want to type one of the more common unusual characters, it's easiest of all to do it with your Compose (aka Multi) key. For example, hitting [Compose] <3 types ♥.
Nobody wants the boss to notice when you're slacking off. This will fill your shell with random data, parts of it highlighted. Note that 'highlight' is the Perl module App::highlight, not "a universal sourcecode to formatted text converter." You'll also need Term::ANSIColor.
range context (-A -B) search, with exclusion of vcs directories
Fun idea! This one adds seconds and keeps running on the same line. Perl's probably cheating though. :)
This command turns a multi-line file into a single line joined with <SOMETEXT>. To skip blank lines, use:
perl -pe '(eof()||s/^\s*$//)||s/\n/<SOMETEXT>/g' file.txt
In this way it doesn't have problems with filenames with spaces.
Today I needed a way to print various character classes to use as input for a program I was writing. Also a nice way to visualize character classes.
grep multiline in Perl regexp syntax with pcregrep