Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Zeke Sikelianos

« Newer Snippets
Older Snippets »
Showing 1-10 of 17 total  RSS 

Sort last 1000 shell commands by popularity

  history 1000 | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head

Bashy Perlness for generating Favicon text for OpenSearches

echo -n '<Image width="16" height="16">data:image/xicon,' ; perl -ne 's/(.)/"%".unpack("H2",$1)/egs; print' ~/Desktop/favicon.ico ; echo '</Image>' 

Find all subdirectories of a given path at a particular depth

def subdirectories_of(path, options = {}) depth = options[:at_depth_of] || 1 Dir[File.join(path, * ["*"] * depth + [""])] end >> subdirectories_of("/var") => ["/var/agentx/", "/var/amavis/", "/var/at/", "/var/audit/", "/var/backups/", "/var/db/", "/var/empty/", "/var/folders/", ...] >> subdirectories_of("/var", :at_depth_of => 2) => ["/var/amavis/db/", "/var/amavis/tmp/", "/var/at/jobs/", "/var/at/spool/", "/var/at/tabs/", "/var/at/tmp/", 

MySQL Dump entire database

mysqldump -v --quick --single-transaction --all-databases -uroot > file.sql

Rename old HTML views for Rails 2

# Snagged from http://softiesonrails.com/2007/7/11/upgrading-your-views-to-rails-2-0
for old in `find app/views -name *.rhtml`; do svn mv $old `dirname $old`/`basename $old .rhtml`.html.erb; done

Kill the cornball dock in Leopard

defaults write com.apple.dock no-glass -boolean YES
killall Dock

find and replace text from the shell

Snagged from http://snippets.dzone.com/posts/show/116

find . -name '*.txt' -print0 |xargs -0 perl -pi -e 's/find/replace/g'

Count the number of files in a directory

ls -a | wc -l

You can also try ls -A (same as --almost-all) to list all dotfiles but . and ..


Snagged from http://www.webservertalk.com/archive109-2004-7-315190.html

Move files using find and exec

find . -name "xyz*" -exec bash -c "mv {} ./xyz-dir/" \;
« Newer Snippets
Older Snippets »
Showing 1-10 of 17 total  RSS