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:
Kill all process that concide whit PATTERN
This revision to my command (command #8851) was called for when it failed to find the parent
package of 'rlogin', which is really a deep symbolic link to /usr/bin/ssh.
This revision fixes this newfound issue, while ensuring fixes of other older issues work too.
Sometimes you unzip a file that has no root folder and it spews files all over the place. This will clean up all of those files by deleting them.
You could avoid xargs and sed in this case (shorter command and less forking): At least bash and zsh have some mighty string modifiers.
I would also suggest using find with exec option to get more flexibility. You may leave out or include "special" file for example.
Helps if you accidentally deleted files from an svn repo with plain rm and you would like to mark them for svn to delete too.
Tells you everything you could ever want to know about all files and subdirectories. Great for package creators. Totally secure too.
On my Slackware box, this gets set upon login:
LS_OPTIONS='-F -b -T 0 --color=auto'
alias ls='/bin/ls $LS_OPTIONS'
which works great.
Grabs the Apache config file (yielded from httpd) and returns the path specified as DocumentRoot.
find . -type f -name '*.wav' -print0 |xargs -0 -P 3 -n 1 flac -V8
will encode all .wav files into FLAC in parallel.
Explanation of xargs flags:
-P [max-procs]: Max number of invocations to run at once. Set to 0 to run all at once [potentially dangerous re: excessive RAM usage].
-n [max-args]: Max number of arguments from the list to send to each invocation.
-0: Stdin is a null-terminated list.
I use xargs to build parallel-processing frameworks into my scripts like the one here: http://pastebin.com/1GvcifYa
If your version of curl does not support the --compressed option, use
curl -s http://funnyjunk.com | gunzip
curl -s --compressed http://funnyjunk.com
This example command fetches 'example.com' webpage and then fetches+saves all PDF files listed (linked to) on that webpage.
[*Note: of course there are no PDFs on example.com. This is just an example]
rename file name with fixed length nomeric format pattern
The result of this command is a tar with all files that have been modified/added since revision 1792 until HEAD. This command is super useful for incremental releases.
for when find . -print | grep -v .svn | xargs doesnt cut it.
Deletes capistrano-style release directories (except that there are dashes between the YYYY-MM-DD)
One of my friends committed his code in the encoding of GB2312, which broke the build job. I have to find his code and convert.
If you have the fdupes command, you'll save a lot of typing. It can do recursive searches (-r,-R) and it allows you to interactively select which of the duplicate files found you wish to keep or delete.
Take a folder full of files and split it into smaller folders containing a maximum number of files. In this case, 100 files per directory.
find creates the list of files
xargs breaks up the list into groups of 100
for each group, create a directory and copy in the files
Note: This command won't work if there is whitespace in the filenames (but then again, neither do the alternative commands :-)
grep -lL "foo" $(grep -l bar *cl*.log)
Uses xargs to call the second grep with the first grep's results as arguments