commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
Finds the string in every file in an entire directory and all its subdirectories and replaces it with a new string. Especially useful when changing a machine's IP address or hostname - run it on /etc.
Probably only works with GNU du and modern perls.
The Linux /dev/full file simulates a "disk full" condition, and can be used to verify how a program handles this situation.
In particular, several programming language implementations do not print error diagnostics (nor exit with error status) when I/O errors like this occur, unless the programmer has taken additional steps. That is, simple code in these languages does not fail safely. In addition to Perl, C, C++, Tcl, and Lua (for some functions) also appear not to fail safely.
MIME::Base64 is a part of Perl5 distribution. You can also use decode_base64 for oposite result.
self explanatory see sample output
Insert a comma where necessary when counting large numbers. I needed to separate huge amounts of packets and after 12+ hours of looking in a terminal, I wanted it in readable form.
Adds a newline to the end of all cpp files in the directory to avoid warnings from gcc compiler.
That "^M" is Ctrl-M, which is a carriage return, and is not needed in Unix file systems.
Where ^V is actually Ctrl-V and ^M is actually Ctrl-M (you must type these yourself, don't just copy and paste this command). ^V will not be displayed on your screen.
Find all files that contain string XXX in them, change the string from XXX to YYY, make a backup copy of the file and save a list of files changed in /tmp/fileschanged.
This removes the type prefix used in Hungarian notation (v. bad) for PHP variables. Eg. variables of the form $intDays, $fltPrice, $arrItems, $objLogger convert to $days, $price, $Items, $logger.
Quick command to check if Perl library is installed on your server.
joins multiple lines to create single line with comma separated values. for example if we have an email addresses one per line (copy&paste from spreadsheet) it will oputput one line with comman separated addresses to put it to email client.
Encodes HTML entities from input (file or stdin) so it's possible to directly past the result to a blog or HTML source file.
This script first find all files which contains word xxxxx recursively. Then replace the word xxxxx to yyyyy of the files.
- Web site domain change
- Function name change of the program
syntax follows regular command line expression.
example: let's say you have a directory (with subdirs) that has say 4000 .php files.
All of these files were made via script, but uh-oh, there was a typo!
if the typo is "let's go jome!" but you meant it to say "let's go home!"
find . -name "*.php" | xargs perl -pi -e "s/let\'s\ go\ jome\!/let\'s\ go\ home\!/g"
all better :)
multiline: find . -name "*.php" | xargs perl -p0777i -e 's/knownline1\nknownline2/replaced/m'
indescriminate line replace: find ./ -name '*.php' | xargs perl -pi -e 's/\".*$\"/\new\ line\ content/g'
changes THIS to THAT in all files matching fileglob* without using secondary files
Bork, bork, bork!
To keep it short, the first terminal line doesn't show a prompt.
Replaces every ocurrence of 'old' for 'new' in all files specified. After the 'i' char you can put a '~' or whatever to create a backup file for each replaced with the name equal to the original plus character.