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:
(relies on 'imagemagick')
This command will convert all .pdf files in a directory into a 800px (wide or height, whichever is smaller) image (with the aspect ratio kept) .jpg.
If the file is named 'example1.pdf' it will be named 'example1.jpg' when it is complete.
This is a VERY worthwhile command! People pay hundreds of dollars for this in the Windows world.
My .jpg files average between 150kB to 300kB, but your's may differ.
Prints a graphical directory tree from your current directory
Use graphicsmagick or imagemagick to composite a RGBA image over a flat white background and discard the alpha channel.
usefull in case of abuser/DoS attacks.
special thanks to XwZ :)
Uses the PHP binary to check the syntax of all .php files in or below the current working directory. Really handy for doing that last minute check before you commit code to the repository.
Shows the current directory and those below it in a simple tree structure. Recommended use:
checking files in current and sub directories, finding out the files containing "sampleString" and removing the containing lines from the file.
* Beware that The command will update the original file [no backup].
The command can be extended if play with 'find' command together,
e.g. it is possible to execute on certain type of files: *.xml, *.txt... (find -name "*.xml" | grep....)
if anybody knows a better solution on that, please drop a comment. thx.
Format a password file for John the Ripper from Cisco configs (Level 5)
Create a tgz archive of all the files containing local changes relative to a subversion repository.
Add the '-q' option to only include files under version control:
svn st -q | cut -c 8- | sed 's/^/\"/;s/$/\"/' | xargs tar -czvf ../backup.tgz
Useful if you are not able to commit yet but want to create a quick backup of your work. Of course if you find yourself needing this it's probably a sign you should be using a branch, patches or distributed version control (git, mercurial, etc..)
Similarly, if you want to print from 10 to the end of line you can use: sed -n '10,$p' filename
This is especially useful if you are dealing with a large file. Sometimes you just want to extract a sample without opening the entire file.
Credit goes to wbx & robert at the comments section of http://www.commandlinefu.com/commands/view/348/get-line1000-from-text.#comment
The description of how the one-liner works is here at my blog:
From a saved page of google search results, split out all of the links for the results. Useful for creating apache rewrite rules from.
If the file content is :
Blah blah blah
hello blah blah blah
bloh bloh bloh
Bah bah bah
hello blah blah blah
bloh bloh bloh
If you have a file full of numbers written line by line, you can sum every line to get the total.
With a file like this:
you will got:
Replaces A with B in binary file "orig" and saves the result to "new". You must have the hex representations of A & B. Try od: echo -e "A\c" | od -An -x
Does an in situ search-replace but leaves a datestamped backup. A variation with more precision:
sed -i.`date +%Y%m%d%H%M%S 's/pattern/replace' [filename]
Very quick way to change a word in a file. I use it all the time to change variable names in my PHP scripts (sed -i 's/$oldvar/$newvar/g' index.php)