Category Archives: Code Samples

All Code Samples go here.

One Line Linux Command to Print Out Directory Tree Listing 4

My professor sent us this little one liner (ok, I had to format it to 2 lines to fit in this blog. You know what I mean) which prints out the current directory tree:
ls -R | grep “:$” | sed -e ’s/:$//’ -e ’s/[^-][^\/]*\//–/g’ \
-e ’s/^/ /’ -e ’s/-/|/’
What’s going on here?

One Line Batch Rename Files Using CSV Input File and awk 3

The Bash command environment, which is the namesake of this blog, is very flexible in that it allows you to manipulate the filesystem in many ways. Awk and sed are very powerful tools that allow you to do this rename with a simple one line command. This post will walk you through doing this with [...]

Linux Command Line, Generating a Random File 2

It is very easy to create a random file using the linux command line. Much like the command to fill a file with all zeros, for example a 1 Meg file:
dd if=/dev/zero of=zero.filename bs=1024 count=1000
You do the same using /dev/urandom:
dd if=/dev/urandom of=random.filename bs=1024 count=1000
Resulting in a 1MB file:
1000+0 records in
1000+0 records out
1024000 bytes (1.0 MB) [...]

Copy Files to Many USB Drives Quickly and Easily 1

I was recently tasked with copying speaker’s presentations, files and handouts onto 100s of USB Drives (key drives) for a conference that work is hosting down in Washington, D.C. My first thought was that it was going to be a pain to have to copy/paste the files to each drive. I thought about creating a [...]

How to Install SNMP on Tomato Router Firmware and Graph Traffic with Cacti 5

You’ve flashed your old WRT54G or other vanilla router with the Tomato firmware. This itself turns your router into a lean, mean routing machine with QOS, SSH and more, but let’s say we want to take it a bit further. What it we want to get some more stats out of it?
In order to do [...]