Ah, Unix. A strange and wonderful world. If you're new to Unix, you might think it really blows goats compared to stuff like Windows or even Macs. Hell, at least on a Mac you can double-click something and it'll open for you. None of this command-line, crap, right? Well, truth be told, in modern Unices with modern interfaces, you can just double-click on stuff and have it open for you, too (see ObligatoryScreenshots for proof of that). But you also have a rich and powerful world beneath all that.
If you are genuinely interested in learning some real Unix stuff, I suggest you pick up "Think Unix" by Jon Lasser. It's a great book, and it explains some history behind Unix, how it works and why it works the way it does.
But, to make a long story short, Unix might seem weird and arcane and completely unusable to you at first. But after a while, there's sort of a moment when it all "clicks", and you catch on to some of the patterns and stuff. It really is great stuff. A few taps on the keyboard, and I can do things that would take a Windows user hours. A friend asked me how he could get a list of all the JPEG files on his computer and their sizes. Hmm.. think about how you would do this in Windows maybe using the "search" function and searching for *.jpg and *.jpeg. Ok, now you have a list of all those files, but how do you get that list itself into a file? It's sort of non-obvious. Here's a Unix command that'll do it:
find / |grep -E '(\.jpg$|\.jpeg$)' |xargs ls -lh >> some_file
Ok, that's a bit complicated, but the point is I can type that one thing and easily generate the required list. Anyway, definitely look into "Think Unix" if you're interested. It's great that these days, you can have the eye candy and easy "double-click" interface of Windows and Macs, as well as the immense power and flexibility of the Unix command line. The best of both worlds, I tell yah!
But, on to the actual tips:
- xargs. What a great program. You give it a list, and it runs the specified command on every element in the list. This is very often used with find, which, as the name suggests, finds files. If you just give find a path, it'll print out all the files in that directory and all subdirectories of that directory, so for example you could do find ~/mp3 |xargs id3info to print the id3 tag information for all your mp3s (which, if you have as many as I do, might end up printing a lot of stuff).
- ssh. Another one of those must-haves. Unfortunately, it having to do with remote logins, security issues crop up in ssh every once in a while, so if you run an ssh server, you need to make sure to keep the ssh packages on your system up to date. Anyway, there's a lot you can do with ssh. Its most basic (and most common) function is to provide remote access to a system. In a terminal, you can type ssh username@hostname, and it'll ask you for your username's password on hostname, and off you go. But, ssh encrypts and (optionally) compresses the connection. See SshTips for lots more!
- bash. Bash is the default shell in Linux and (since recently) Mac OS X. It's a pretty nice shell, with quite a few neat features. In particular, I quite like the vi mode, though my friends and co-workers hate me for using it. If you know how to use vi though, you might want to try it out. You can edit your commands on the command line using vi commands. Hit esc, and use h, l, j and k to move within the command and through commands in your history. Most of the vi editing commands are available too. Another useful thing about bash is !$. !$ will hold the last referred-to file. So if you did vi foo.txt you could do lpr !$ to print foo.txt, for example. Finally, there's ^foo^bar. This replaces the first occurrence of foo in your previous command with bar. So if you did cp foo mydir to copy file foo into directory mydir, you could just hit ^foo^bar to copy file bar into mydir. Global search-and-replace is quite a bit more complicated, unfortunately, and so it's usually not worth it.
- ~/.bashrc. This could maybe go with the previous item, but I feel it's a tip on its own. If you use bash, you can use a ~/.bashrc file to add functionality and change behaviour in certain ways. You can see some of the things I have in my ~/.bashrc: DotBashRc