This is a nifty little trick for making Bash a little more intuitive (for my taste). Usually, when you press the up key, Bash will bring back the last command you typed. This is cool, but what bothers me is that sometimes I start typing a command and then remember I executed it before. So I press the up key and… Bash shows me the last command, disregarding what I typed. What I want it to do is search history for things with the prefix I entered.
Here’s what you do to achieve this. In your
inputrc file (
~/.inputrc for personal configuration,
/etc/inputrc file for global configuration), add the following lines:
The weird symbols at the start of each line represent up/down arrow keys in keypad/ANSI modes. I wish Unix configurations would use proper readable symbols, but a man can only dream.
Little things matter. I’m often amazed of how I can feel I mastered a certain tool or technology, only to discover I’ve missed some basic way of using it. It happened to me on Windows a couple of weeks ago when I discovered cool keyboard shortcuts, like Win+E (which opens My Computer), or on Eclipse when I found out there is a menu that finds everything. On Linux, I’ve found that this happens all the time. Now, finding out how to use
sed is one thing, and it requires learning a complicated tool. But there are a lot of little things that are so easy to pick up, that it’s a shame that people miss them. Playing around with directories is so common in a Unix shell, and there are so many tricks you can use.
The basic way of moving around is, of course,
cd path/to/dir. So far, so good. What more can you do?
I’ve been using Windows 7 for a couple of years now and only recently I found PowerShell. If I didn’t hear about it, maybe you haven’t either, and I would love to correct that. But first, an obligatory story.
On my second semester in the university, I took a course called “Introduction to Systems Programming”. It’s a course where you learn advanced C and then move on to C++, but first you learn c-shell*. A further requirement for this course is that your C/C++ projects will compile on the university’s Linux server, where it’ll be tested. What most people do when taking this course is that they use some sort of Windows IDE like Visual C++. Then, usually at the eleventh hour, they copy their code to the Linux server via SSH (which is painful if you’re not POSIX-literate) and then have to solve all sorts of weird NT-Linux, gcc-VC comparability issues. Why aren’t students POSIX-literate? Because there’s only so much you can learn without using it “for real”.
I decided to use it for real.
I backed up all my data and documents on my laptop (thank god I also had a desktop - so I can play Civilization 4) and installed Ubuntu. I was going to do this the right way. It wasn’t the first time I tried using Linux, but in the past (as a highschool student) I usually gave up after a few days since it was uncomfortable. But with Ubuntu I lasted all semester. It was tough. There are Windows idioms that are very difficult to shake, like using My Computer as an anchor point for directory movements. I didn’t become a Linux expert, but I was way above the pack where it came to using the shell to do… well, anything. However, since Ubuntu is very user-friendly (as far as UNIX systems go) there were still lots of stuff I was doing in a pseudo-Windows style - like copying files, which I did by opening two windows and using drag & drop.
Then, on my third semester, I got a job at Intel. We were using Windows laptops and VNC to connect to actual Linux machines where we did our actual programming work. When I got my VNC set up, it was some sort of weird, antiquated x-window manager (it was fvwm2 if I remember correctly). It wasn’t configured to anything comfortable and being that it was my first job ever, I was a bit shy about asking someone to help me with it (yeah, geeks are sometimes shy). Words can’t describe how much it sucked, but just to give you a taste - there wasn’t any open-windows-bar or anything. If I wanted to find an open window, I had to manually move other windows around until I found the one I’m looking for. I used it for a whole year.
While it sucked, after about a year of using it, I found that I was getting more and more proficient in using the shell at a very high pace. I literally had to use it for everything. At the end of that year I decided I had enough and that it’s time to use a real desktop manager, but my experience with bare-boned Unix was something I do not regret for one minute.
I never use drag & drop to copy files on a Unix machine.
Why am I telling you all this? Well, my new job has me programming with Python on a Windows machine, but using the Windows command line to do stuff drove me mad. I started looking into using bash on Windows, but to no success. It’s also not a very good solution, as sometimes I use other people’s prompt-snippets. And then someone told me about PowerShell. PowerShell is a built-in command prompt replacement in Windows 7. It’s completely backwards compatible and supports POSIX commands out-of-the-box, like ls, grep, tail, pipelining, etc. It’s not perfect, but considering it’s built in in Windows 7, it’s my shell of choice for Windows machines for the foreseeable future.
* c-shell is bad for you, yadda-yadda-yadda.