Fu’ing around

So I am this long time Linux user – I started with my first linux installation some time in 2004. It was a Mandrake (now Mandriva) 7 or 8. I started out pretty clueless, but had the help of some geek friends when taking my first toddler steps into this fascinating world.

Now I’m at a stage where I’m more comfortable on Linux than on a Win/Mac. Does that mean I’m fairly comfortable with the shell? Yes. Does it mean I know each and every command under the sun for each and every task under the sun (Yes, you can do pretty much everything under the sun on a bash shell.)? Nope!

There is a HUGE number of commands and combinations, several meta-languages, regular expressions and built-in features, which together render the unassuming command shell not only incredibly powerful, but also (seemingly) incredibly difficult to learn and use (It isn’t.). There is a natural trend for most system configurations, software and scripts to rely heavily on the shell (many tools have feature-complete GUIs as well). Unfortunately, this also acts as a major deterrent for users coming from other platforms, wanting to migrate to a Linux environment. THE LINUX SHELL CAN BE INTIMIDATING!

Well, not anymore, thanks in no small part to these guys. Commandlinefu.com gives you ready-made, baked recipes for many things you can do with your shell, ranging from something as mundane as listing the open tcp ports on your machine, to the most eccentric (and dare I say, hare-brained) stuff, such as watching Star Wars episode IV in ASCII mode!! (I’m not kidding! Try

$ telnet towel.blinkelights.nl

)

This is a boon, not only for newbies, but also for mid-level Linux enthusiasts like me, who haven’t quite reached elite geekdomness yet! So if I want to see the disk usage under  a certain folder, to identify space hogs or possible bloated temporary disk caches, I just search ‘disk usage’ and here’s what I get:

  • $ du -cs * .[^\.]* | sort -n

    Shows size of dirs and files, hidden or not, sorted.
    Very useful when you need disk space. It calculates the disk usage of all files and dirs (descending them) located at the current directory (including hidden ones). Then sort puts them in order.

  • $ du | sort -gr > file_sizes

    Outputs a sorted list of disk usage to a text file
    Recursively searches current directory and outputs sorted list of each directory’s disk usage to a text file.

Those were just a couple of examples. The site lists many more. You’re almost 100% sure to find a command that suits your needs. But I’m not writing this post to tell you how to use a website. I’m going to show you how to search this website from the shell!

The following instructions assume that you have a ready and working bash shell at your disposal.

  1. Fire up your favorite text editor (mine is vim) and open your ~/.bashrc file (Alternatively, /etc/bashrc)
  2. Define a function as follows:
    cmdfu(){ curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ | openssl base64)/plaintext"; }

    (This little gem is also sourced from commandlinefu.com.)

  3. Run
    $ source ~/.bashrc

    This will update your currently running shell to become aware of the function you just defined.

  4. Type
    $ cmdfu 'disk usage'

    and get all the results of your previously conducted search, right in your command shell!

  5. Bask in the glory of your newly found Linux coolness ;).
Advertisements

,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: