RSS

Tag Archives: bash

Adding some color to ls in Mac OS

If you have ever used ls in the Mac OS terminal you have probably noticed that you get a boring monochrome list. If you have never used Linux before you might not find this a problem at all. Why would you anyone expect or need it to have color? Well, sometimes color is very important, for instance if you are in an unfamiliar directory and you don’t know what is a file and what is a sub-directory.If you are completely new to the Terminal/Unix-like operating systems a short explanation of what ls is is in order.ls is a program which lists all of the files and directories in a directory. Try opening the terminal and typing ls to see what I mean (type man ls for more information on how to use ls). On a mac, and all other BSDs to my knowledge, the output text will all be in one color (probably black in your case),but on Linux the output will be color coded (files and directories have different color text)So you want Mac OS to have colored output just like Linux? well, that is easy. ls has the argument -G which will output colored text (on Mac OS. Linux uses -C (–color) but you shouldn’t need that, and I don’t know what other BSDs do.) So, you could type ls -G every time you want to list the contents of a directory, but that would get every annoying after a while. There is an easy way you can make it output colors every time you run ls so you won’t have to add the -G every time! Go the command line and type:

cd ~/ (if you are not already there)

echo alias ls=’/bin/ls -G’ >> .bash_profile

Now every time you type ls you will see colored output (if you ever want to remove this just edit ~/.bash_profile with your favorite text editor and remove the line we just added) Enjoy!

Advertisements
 
Leave a comment

Posted by on December 21, 2008 in apple, bash, concatenation

 

Tags: , , , , , , , ,

A Backup Script Mark 2

You may remember a while ago I posted about a backup script I wrote. I have put some work into it and improved it quite a bit. Here are some of the more important changes I made.

I realized that saying that it did incremental backups was not completely true. What it was doing was snapshots so I changes all of the terminology to snapshot instead of incremental.

Last time I mentioned that snapshots take a very long times. Well, I fixed that, kind of. Before the script was set to compress the tar files it generated which took hours if they were large. To illustrate this problem this problem I have some numbers. I ran a backup using the same exact 21.87GBs of data one compressed with bzip and one not. Using bzip the backup took 7h52m; without bzip the backup took 23m51s. That is 94.9% faster. All that time is for only a 1.26GBs (6.12% savings) of space saved. So I changed it so compression is not default anymore, though it is still an option. depending on the size and composition of your files to be backed up compression may still be worth using. Now I said I kind of fixed it because after I took those statistics I made the script hash the backup files so that when you can ensure that your backups are good. This takes some times, but no where near as much as compression. If you are a Mac OS X user you will have to install md5sum using macports or fink or whatever you want for this to work. Apple sucks and they can’t include this so you will have to install it yourself(if you already have macports you probably already have md5sum).

I added a option to restore from a snapshot (I believe the last version only supported restores from the normal backup).

You may have noticed a bug while using -v where if all you used was -v nothing would happen. Its fixed.

I added a paranoia mode that uses srm instead of rm. I hope that I can add more to this in the future. Encryption is still a problem.

I changed the configuration so that multiple users could be added. This part makes me with I hadn’t written this is bash. I hate the way it works and I can’t get anything better as I am pushing up against the barriers of the language (or my understanding of it?). check out the readme and /etc/backup/main.conf for more an this. Note that the install script will replace your current config file with a standard one(useless one) so make sure to save yours before you install.

If you want to look at all of the the changes take a look at the todo file.

Before I forget like last time it I need to link to this. So Here it is. I’m not sure how but this one is actually 2kb smaller than the last version(it is 30kb by the way).

I don’t know if I will continue to work on this or not. I am still using it even on leopard because I don’t know if I want to trust time machine. However there are some really great backup utilities out there so I may want to use one of those.

Just as last time if you have any suggestion, comments, or bug fixes you can leave them in the comments or email me.

Oh before I forget I’v been trying to think of a name for this (I’ve just been calling it backup so far). If you have any ideas I would love to hear them.

 
Leave a comment

Posted by on February 11, 2008 in backup, bash

 

Tags: , , ,

Site of the Week: Cygwin

Have you ever been stuck using the-OS-which-mustn’t-be-named without the most basic of utilities, bash!? How are we supposed to actually do anything with that thing they call an OS? Well the answer may be Cygwin..

So what is Cygwin?

The Cygwin tools are ports of the popular GNU development tools for Microsoft Windows. They run thanks to the Cygwin library which provides the UNIX system calls and environment these programs expect.

With these tools installed, it is possible to write Win32 console or GUI applications that make use of the standard Microsoft Win32 API and/or the Cygwin API. As a result, it is possible to easily port many significant Unix programs without the need for extensive changes to the source code. This includes configuring and building most of the available GNU software (including the packages included with the Cygwin development tools themselves). Even if the development tools are of little to no use to you, you may have interest in the many standard Unix utilities provided with the package. They can be used both from the bash shell (provided) or from the standard Windows command shell.

(from Cygwin’s FAQ)

I played with Cygwin a while ago; I can’t say much about it because I really didn’t use it that much. It seemed to be pretty cool and from what I remember it even has a packager of sorts. Hopefully, if you are forced to use Windows occasionally, like me, and have permissions to install stuff, unlike me, this may just make your computing experience almost bearable.

 
Leave a comment

Posted by on January 25, 2008 in site of the week

 

Tags: , , ,

Concatenation: Encrypt /home, An Introduction to Wine, Some really cool bash tips

It’s time for yet another concatenation. I don’t feel like trying to get those title to actually look like links right now so just trust me if you put your mouse on them, not the first one though, it will turn blue.

Before I get into the concatenation I would like to inform all of you who read via rss that I set up a feedburner feed so while the wordpress feed will continue to work I would prefer it if everyone would switch over to the feedburner feed. Thanks.

CommandLine Warriors: Encrypt /home

I had planned to spend some time on figuring out how to encrypt partitions in linux and then write up a little how to but it seems that zeth beat me too it. I haven’t tried it yet but it looks like it is about what I was going to do.

I would like to stress the importance of encrypting your disk, specifically /home, but I’m lazy so I’ll let zeth do it for me.

You can’t always guarantee the physical security of mobile computers, indeed I myself had one stolen this year. However, on Linux, there is no need to leave yourself open to identity or data theft. Indeed if you are using Linux and you ended up at this blog post somehow, then you are highly likely to either work in IT or be otherwise highly technically competent. In other words, you have no excuse.

Encryption is easy to set-up, the approach I’ve outlined here does not require a reinstall, we are just going to swap out your home directory for an encrypted home partition. The simplest possible approach, but a big step forward in security for many of us.

I really doesn’t seem to be that hard. Do it or you may regret it later.
Part 1
Part 2
Part 3
Part 4

wine-review:A quick introduction to Wine

wine-review:>wine-review:>Wine is a way to run windows programs on linux, for those you you who don’t know. Here is a quick explination of what Wine is that is a lot better than I could ever do.

Wine is a translation layer (a program loader) capable of running Windows applications on Linux and other POSIX compatible operating systems. Windows programs running in Wine act as native programs would, running without the performance or memory usage penalties of an emulator, with a similar look and feel to other applications on your desktop.

The Wine project started in 1993 as a way to support running Windows 3.1 programs on Linux. Bob Amstadt was the original coordinator, but turned it over fairly early on to Alexandre Julliard, who has run it ever since. Over the years, ports for other Unixes have been added, along with support for Win32 as Win32 applications became popular.

I for one have tried wine but never put much effort into it. I have a copy of KOTOR that I haven’t played in a while and I might see if I can get it to install.

This is just a quick introduction to Wine, the entire site is dedicated to wine, so it might be good to look at the rest of the site to really learn to use Wine.

Richards linux, web design and e-learning collection: Bash Tips and Tricks

This one blew me away. This is some really good stuff. Here was what he covers:

  1. Lost bash history. Which is losing history when you have multiple tabs open
  2. stupid spelling mistakes
  3. Duplicate entries in bash history
  4. Multi-line commands split up in history
  5. searching bash history
  6. moving to the previous directory

That last one may not seem all that amazing to you right now but it is actually really cool, unless you already know how to do it. Why mess with paths to get back where you were when you can do it with one character?

I really suggest you give this a read.

That’s all for now folks.

 
Leave a comment

Posted by on December 11, 2007 in concatenation

 

Tags: , ,

A backup script

Edit (nov. 17): I just realized I completely forgot to link to the file. Sorry. Here it is.


I got a external hard drive for Christmas last year to store some of the less important/larger things that I didn’t need or want on my internal 60GB hard drive. At some point I decided that it was impractical to continue backing up to DVDs and that I would have to use my external drive to to hold the backups unless I wanted to buy a tap drive (which I didn’t). So I manually copied my user file onto the drive every once in a while. I got really tired of how long that took so I started using rsync to manually backup the files. At the time I didn’t know anything about bash scripting but I though a shell script would be very useful so I didn’t have to type out the whole command (I’m lazy). I found the sites that I mentioned in the last site of the week and looked up what I needed to know to make a very simple shell script. I used that very simple script for several months until my brother started pushing me to add features and make something that other people might want to use. I’m glade he did this because as a result I learned a lot more about bash scripting and I have a much more functional and robust script. This script, after a few months of tweaking, is now at a point where I’m not embarrassed to let other people use it; It does everything that I want it to do (save 1 thing) and more importantly it is in complete working order.

So what does this script do?

  1. In place backups using rsync (as in it just keeps a folder up to date)
  2. Incremental backups
  3. backup of applications (I’m a mac user so I don’t think this would be a useful feature on Linux or BSD)
  4. restore

I bet your asking yourself “what is that feature that he wants but didn’t implement? and why didn’t he just go ahead and add it?” The feature is encryption (using gpg) and I didn’t add it because I couldn’t figure out how to get it to work in the way I want. For now if you want to encrypt it you will just have to do it by hand like a real man/woman.

If you have a large amount of data that needs to be back up it will take you a while so it is best to schedule the backup at night (if possible) or at any other time that the computer will be on but not in use. My user file is currently 22GB and I use an external USB Maxtor drive. With my setup it took me almost 9 hours for an incremental backup with a resulting file of 21.8GBs and 7 minuets for a normal+application backup. 21.8GBs is a a large file and only 1% smaller than the normal size of my user folder (assuming that it hasn’t changed in size significantly since I backed up last) so I may end up cutting out the compression in the future to save time. This talk of size brings me to another topic. My external drive is only 160GBs so I can’t fit very many backups on it which is the only reason there is an in-place backup in this script. In the future I may get a larger drive and remove the in-place backup.

I have only tested this on my computer (ibook G4) so I can’t guarantee that it will work on Linux. I am positive that it will work just fine on all Mac os X systems execpt that it uses bzip by default for incremental backups and mac os doesn’t come with bzip pre-installed, so I added an option (-g) to use gzip (which is installed by default.

There are a lot of different backup scripts and programs out there that may be far better than this one so feel free to stick with those if you want to. I don’t care how you backup your stuff as long as you do it. I’m sure you all know why it is important to back stuff up so I don’t think I need to get into that, however, I will say that just having a backup script/program is useless if you don’t use it. So Automate it!

Any bug reports/feature suggestions/patches can be left in the comments (in plain text please) or emailed to me (no I’m not going to give you my email address you have to find it yourself (I don’t need more spam.(by that I mean I don’t get spam and I don’t want to start(I’m not sure this is grammatically correct))))

 
Leave a comment

Posted by on November 13, 2007 in backup, bash

 

Tags: , , ,

Site of the Week: Bash Scripting

Well, its Friday and that means it is time for another site of the day. This week I actually have two sites for you because I felt like it. So as you have probably already figured of from the title today I’m going to be giving you sites about bash scripting. The first is the site that I used to learn how to script the second is the site that I use for reference; I haven’t really read through it but I would like too sometime.

Linuxcommand.org is actually just about bash in general but it has a pretty good introduction to bash shell scripting. I used this site to learn because it does a very good job of presenting its information in a well organized, good looking, easy to understand way. If all you want is a introduction to shell scripting this site is great.

Linux Shell Scripting Tutorial: A Beginner’s handbook offers a much more in depth introduction to shell scripting but it isn’t as pretty and may be a little more complex than a noob would want. I use this book mostly for reference because it goes into more detail and a wider range of topics than Linuxcommands does. I probably should read this so I can learn about all the cool stuff that I that I didn’t learn with Linuxcammands.

Bash shell scripting is a great way to introduce someone to the basic concept of programming. If you want to learn to program but don’t think you can handle a real programing language or if you have kids that want to learn how to program, Bash scripting is probably the best way to go.

I think now I should point out the differences between scripting and programming. They are actually pretty simple. Scripting is writing a list of commands for programs to carry out while programming is writing code that will be compiled/interpreted and is itself ran, not just telling other things what to do but doing them itself. I don’t know if that is very clear or at all a good way of explaining the difference. If you can do a better job the comments awaits you.

 
1 Comment

Posted by on October 26, 2007 in bash, site of the week

 

Tags: , ,