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.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
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:
Uses curl to download page of membership of US Congress. Use sed to strip HTML then perl to print a line starting with two tabs (a line with a representative)
change the *.avi to whatever you want to match, you can remove it altogether if you want to check all files.
The sort utility is well used, but sometimes you want a little chaos. This will randomize the lines of a text file.
BTW, on OS X there is no
| sort -R
option! There is also no
| shuf
These are only in the newer GNU core...
This is also faster than the alternate of:
| awk 'BEGIN { srand() } { print rand() "\t" $0 }' | sort -n | cut -f2-
the command show can be run in vim, here is the same thing on the command line
cat script.pl | perl -MO=Deparse | perltidy
In this example the command "somecommand" will be executed and sent a SIGALARM signal if it runs for more than 10 seconds. It uses the perl alarm function. It's not 100% accurate on timing, but close enough. I found this really useful when executing scripts and commands that I knew might hang E.g. ones that connect to services that might not be running. Importantly this can be used within a sequential script. The command will not release control until either the command completes or the timeout is hit.
This will show where your Perl installation is looking for modules.
This pipeline will find, sort and display all files based on mtime. This could be done with find | xargs, but the find | xargs pipeline will not produce correct results if the results of find are greater than xargs command line buffer. If the xargs buffer fills, xargs processes the find results in more than one batch which is not compatible with sorting.
Note the "-print0" on find and "-0" switch for perl. This is the equivalent of using xargs. Don't you love perl?
Note that this pipeline can be easily modified to any data produced by perl's stat operator. eg, you could sort on size, hard links, creation time, etc. Look at stat and just change the '9' to what you want. Changing the '9' to a '7' for example will sort by file size. A '3' sorts by number of links....
Use head and tail at the end of the pipeline to get oldest files or most recent. Use awk or perl -wnla for further processing. Since there is a tab between the two fields, it is very easy to process.
if you want to only print the IP address from a file.
In this case the file will be called "iplist" with a line like "ip address 1.1.1.1"
it will only print the "1.1.1.1" portion
Fixes the faulty files with perl, which may exist on more platforms
notice what happens when there is more than one unread message in a thread...
also people please dont hardcode the password when you use curl. Leave it out and curl will ask you when it runs. Please...?
This finds all the PowerPC apps recognized by OS X.
A better version is:
system_profiler SPApplicationsDataType 2> /dev/null | perl -
wnl -e '$i=$j=$k=$p=0; @al=; [email protected]; while($j
s[$i].=$al[$j]; $i++ if ($al[$j]) =~ /^\s\s\s\s\S.*:$/; $j++} while($k
apps[$k++]; if (/Kind: PowerPC/s) {print; $p++;}} print "$i applications, $p P
owerPC applications\n\n"'
but that is more than 255 characters...
'jot' does not come with most *nix distros, so we need to use seq to make it work. This version tested good on Fedora 11.
This is an extension of a previous command by satyavvd on 2009-07-23 12:04:02, but this one grabs the whole archive. Hard coded numbers in previous script capped number of commands that could be fetched. This one grabs them all regardless of how big the archive gets.
Alter "AddHandler php5-cgi .php" and "AddHandler php4-cgi .php" entries to new "AddHandler x-httpd-php5 .php" respective php4 entries in all .htaccess files under /var/www
Only shows files with actual changes to text (excluding whitespace). Useful if you've messed up permissions or transferred in files from windows or something like that, so that you can get a list of changed files, and clean up the rest.
When you have one of those (log)files that only has epoch for time (since no one will ever look at them as a date) this is a way to get the human readable date/time and do further inspection.
Mostly perl-fu :-/