What's this?

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/

Get involved!

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.

Universal configuration monitoring and system of record for IT.

Stay in the loop…

Follow the Tweets.

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

Subscribe to the feeds.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Commands tagged ruby from sorted by
Terminal - Commands tagged ruby - 20 results
find /srv/code -maxdepth 4 -type f -regex ".*\(\(package\|composer|npm\\|bower\)\.json\|Gemfile\|requirements\.txt\\|\.gitmodules\)"
2014-11-28 16:34:35
User: renoirb
Functions: find
Tags: bash git PHP ruby

List all dependencies manifests so you can install them.

In a scenario where you want to deploy a number of web applications and run their dependency managers, how could you run all of them in a systematic order.

One of the complexity is to ensure you get only your own top level dependencies. That way, you don recursively call development dependencies of your own dependencies.

Otherwise you might end up discovering dependency management manifests that are already been pulled by your own projects.

# Using this command

This command helps me find them and I can then run what?s required to pull them from their respective sources.

This command assumes the following:

1. Your code checkouts are in a flat repository layout (i.e. not nested).

2. Finds manifests for:

- NPM (nodejs),

- Composer (php),

- bower,

- requirements.txt (Python), and

- git submodules

ruby -ruri -e 'u=URI(ARGV[0]).host.split("."); puts u[(u[-2] =~ /^com?$/ ? -3 : -2)..-1].join(".")' http://test.example.com
2014-05-25 18:43:44
User: wejn
Tags: ruby

Extracts 2nd-level domain part (or 3rd level, for co.* or com.*) from the URI's hostname. See sample output.

ruby -rrubygems/commands/mirror_command -S gem mirror
2014-04-22 18:03:01
User: rubiojr
Tags: ruby


ls -1 | xargs ruby -e'puts ARGV.shuffle'
grep -l --include '*.rb' --include '*.rake' '^[^#]*[^a-zA-Z0-9[:punct:][:space:]]' -R . | xargs -L1 awk '!/encoding/ && NR < 2 { print FILENAME }'
rvm --default use ruby-1.9.3
ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 3000, :DocumentRoot => Dir.pwd).start'
2013-08-20 10:19:27
User: boylah

Here's how to serve a directory in one line of Ruby.

Handy for sharing files at a conference, for example.

ruby -ryaml -rjson -e 'puts YAML.dump(JSON.parse(STDIN.read))' < file.json > file.yaml
echo 'Dir.foreach("/usr/local/Cellar/cowsay/3.03/share/cows") {|cow| puts cow; system "fortune | cowsay -f /usr/local/Cellar/cowsay/3.03/share/cows/#{cow}" }' | ruby
2013-04-15 12:27:38
User: orkoden
Functions: echo

Shows a list of all installed cows saying a fortune. Also lists the cows names. Pic your favorite cow!

Needs cowsay, fortune and ruby installed. The path only applies to OS X with cowsay installed using homebrew. On Linux it might be /usr/share/cowsay/cows/ or similar. Uses ruby just because.

echo "$: << '.'" >> $IRBRC
cap -s branch=my_branch deploy
2012-05-23 06:54:21
User: carlzulauf

You can also deploy a specific tag:

cap -s tag=my_tag deploy
ash prod<tab>
2012-05-12 19:51:02
User: c3w


. a Ruby SSH helper script

. reads a JSON config file to read host, FQDN, user, port, tunnel options

. changes OSX Terminal profiles based on host 'type'


put 'ash' ruby script in your PATH

modify and copy ashrc-dist to ~/.ashrc

configure OSX Terminal profiles, such as "webserver", "development", etc

run "ash myhostname" and away you go!

v.2 will re-attach to a 'screen' named in your ~/.ashrc

tail -f production.log | perl -ne 'if (/^Completed.in.(\d+)/){$d = int($1/1000);print "\n";$f{$d}++;for $t (sort(keys(%f))){print $t."s: ".$f{$t}."\n"}}'
2012-02-23 14:37:33
User: theist
Functions: perl tail

Commandline perl filter for, using a production.log from a rails app, display on realtime the count of requests grouped by "seconds to complete" (gross round, but fair enough for an oneliner) :)

ruby -ne 'puts $_.split.collect(&:capitalize).join(" ")' <<< "pleAse cOuld YOu capiTalizE Me"
2011-09-15 01:04:43
User: Quiryaki

"-n" loops around ; "-e" executes the given quoted string ; "$_" is the current line ; "split" creates an array on white space; each item of the array is "collected" to be then "capitalized" ; the array is "joined" back into a string.

echo 'fOo BaR' | ruby -e "p STDIN.gets.split.map(&:capitalize).join(' ')"
require 'time';backup_dir = '/path';Dir.glob(backup_dir+"/*.sql").each{ |f| filetime = Time.parse(`mdls -name kMDItemContentCreationDate -raw #{f}`);monthago = Time.now - (30 * 60 * 60 * 24);`rm #{f}` if filetime < monthago }
ruby -e 'puts (1..6).map{"%0.2X"%rand(256)}.join(":")'
2010-12-08 10:01:31
User: eightmillion

Ruby version.

Also, a perl version:

perl -e 'printf("%.2x.",rand(255))for(1..5);printf("%.2x\n",rand(255))'
changing_assets = `s3cmd sync --dry-run -P -M --exclude=*.php --delete-removed #{preprod_release_dir}/web/ #{s3_bucket} | grep -E 'delete:|upload:' | awk '{print $2}' | sed s_#{preprod_release_dir}/web__`
2010-05-07 16:03:42
User: trivoallan
Functions: awk grep sed sync

Can be useful to granulary flush files in a CDN after they've been changed in the S3 bucket.

ruby -rdate -e 'p DateTime.now.cweek'
ruby -e 'require "date"; puts DateTime.now.cweek'