Tag Archives: Linux

Making and Changing into a Directory

This function, added to your shell profile, will allow you to create directories and cd into them in one fell swoop, without you having to type mkdir, and then cd ALL DAY. After looking around online, I like the name mkcd for this utility, because md makes me think of markdown.

For some reason, I couldn’t get this to work as a one-liner in my .zshrc file, but the listing below worked fine.

function mkcd () {
  mkdir -p $1
  cd $1
}

Note that the -p flag allows you to create a directory several directories deep at one go, without having to descend into them one at a time.

Using find and xargs

In regular linux or unix you can recursively find the files in a subdirectory and apply some utility with arguments on them using xargs as,

find <dir> -type f | xargs <utilitiy> <args>

If the filenames in <dir> have spaces, quotation marks, or other characters in their filenames that make xargs barf, then you can use the following.

find <dir> -type f print0 | xargs -0 <utility> <args>

That should totally work–unless you’re on SunOS, then you have to do,

find <dir> -type f -exec <utility> <args> {} +

It looks crazy, I know, but that’s the honest truth.

Creating a Flowchart with TikZ and LaTeX

In this post I’ll discuss how to make simple flowcharts in LaTeX using TikZ. Probably the best collection of TikZ examples can be found at TeXample.net, but there are other helpful examples like these two PDFs, here and here. In case you’re wondering, TikZ is a recursive acronym “TikZ ist kein Zeichenprogramm,” a reminder (in German) that it is not an interactive drawing program.

Continue reading

Local Variables and Return Values in BASH

In this post, I’ll discuss some lessons learned from BASH programming, in particular, how to pass return values from BASH’s “functions”. BASH does not provide support scoped variables by default, so variables declared in a function are available everywhere once the function has been called. BASH will let you declare local variables within a function through the local keyword. Returning values is then a matter of echoing them out.

Continue reading

An Introduction to Vim

This post will represent some running notes regarding the use of the Vim editor. Why should you use something as arcane as Vim you ask? Well, sometimes you find yourself on a server or something that doesn’t have any other editors, so you should be know some Vim basics. Plus, it’s fun.

Vim is built on vi, an even more bare-bones editor. At the outset you should know that Vim has two modes, normal or command mode, and edit or insert mode. You add words and stuff in edit mode, and you perform operations like searching, saving, and moving around in normal, or command mode. (I prefer the edit/command terminology.) You can always get into the command mode by hitting ESC.

Continue reading