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:
xargs -P N spawns up to N worker processes. -n 40 means each grep command gets up to 40 file names each on the command line.
This command uses mutt to send the mail. You must pipe in a body, otherwise mutt will prompt you for some stuff. If you don't have mutt, it should be dead easy to install.
Force make command to create as many compile processes as specified (4 in the example), so that each one goes into one core or CPU and compilation happens in parallel. This reduces the time required to compile a program by up to a half in the case of CPUs with 2 cores, one fourth in the case of quad cores... and so on.
Colorize output of make, gcc/g++ or diff, making it easier to read at a glance.
They are not distributed with make, diff or gcc, but are usually available in the repositories.
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.
This is more or less the same as 'reset', but with two advantages: the initial LF character makes sure you're starting a new line to the tty driver, the final one is more reliably a line-end as CR is often unset; and second, 'stty sane' is reliable on older UNIX systems, especially Berkeley-based ones.
This works in some situations where 'reset' and the other alternatives don't.
This will mv all your mp3 files in the current directory to $ARTIST/$ALBUM/$NAME.mp3
Make sure not to use sudo - as some weird things can happen if the mp3 file doesn't have id3 tags.
Easy way to find out what Debian version your machine is running
I used this because I needed to sort the content of a bunch of gzipped log files. Replace sort with something else, or simply remove sort to just rezip everything
this will show the names of the deleted directories, and will delete directories that only no files, only empty directories.
If you are downloading a big file (or even a small one) and the connection breaks or times out, use this command in order to RESUME the download where it failed, instead of having to start downloading from the beginning. This is a real win for downloading debian ISO images over a buggy DSL modem.
Take the partially downloaded file and cat it into the STDIN of curl, as shown. Then use the "-C -" option followed by the URL of the file you were originally downloading.
Within /proc and /sys there are a lot of subdirectories, which carry pseudofiles with only one value as content. Instead of cat-ing all single files (which takes quite a time) or do a "cat *" (which makes it hard to find the filename/content relation), just grep recursively for . or use "grep . /blabla/*" (star instead of -r flag).
For better readability you might also want to pipe the output to "column -t -s : ".
put "-linux" option into $HOME/.indent.pro to make it default
Doesn't require password (asks for it instead)
Display the code of a previously defined shell function.
A quick way to find and delete empty dirs, it starts in the current working directory.
If you do find . -empty -type d you will see what could be removed, or to a test run.
Just a copy of a big dir when you wan't things like ownership and date etc etc to be untouched.
Note: Updated with the ideas from "mpb".
rev - reverse lines of a file or files
rev [file ...]
The rev utility copies the specified files to the standard output, reversing the order of characters in every line. If no files are specified, the standard input is read.
The rev command is part of the util-linux-ng package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
This command would move the file "dir/image.jpg" with a "DateTimeOriginal" of "2005:10:12 16:05:56" to "2005/10/12/image.jpg".
This is a literal example from the exiftool man page, very useful for classifying photo's. The possibilities are endless.
Since the original command (#1873) didn't work on FreeBSD whose stat lacks the "-c" switch, I wrote an alternative that does. This command shows also the fourth digit of octal format permissions which yields the sticky bit information.
dname is a directory named something like 20090803 for Aug 3, 2009. lastbackup is a soft link to the last backup made - say 20090802. $folder is the folder being backed up. Because this uses hard linking, files that already exist and haven't changed take up almost no space yet each date directory has a kind of "snapshot" of that day's files. Naturally, lastbackup needs to be updated after this operation. I must say that I can't take credit for this gem; I picked it up from somewhere on the net so long ago I don't remember where from anymore. Ah, well...
Systems that are only somewhat slicker than this costs hundreds or even thousands of dollars - but we're HACKERS! We don't need no steenkin' commercial software... :)
Calculates md5 sum of files. sort (required for uniq to work). uniq based on only the hash. use cut ro remove the hash from the result.
This requires the command-line print extension (see #2861 for more details). I use it to make up complex images with formatted text using CSS and whatnot. It's a lot slicker than imagemagick for certain things. Now imagine using a local webserver with PHP and a database to generate the images. Oh, the possibilities...