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 have the exact command(s) for every kind of task right at my fingertips? 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. 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.
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.blinkenlights.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.
- Fire up your favorite text editor (mine is vim) and open your ~/.bashrc file (Alternatively, /etc/bashrc)
Define a function as follows:
curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ |openssl base64)/plaintext";
(This little gem is also sourced from commandlinefu.com.)
$ source ~/.bashrc
This will update your currently running shell to become aware of the function you just defined.
$ cmdfu 'disk usage'
and get all the results of your previously conducted search, right in your command shell!
- Bask in the glory of your newfound Linux geekdom ;).