Terminal Essentials for Linux and Mac OS X

People working with the command line terminal under Linux or Mac OS X often use a plethora of scripts, aliases and shell functions to facilitate their daily work. Many of these scripts are strongly related to our work, but a few shortcuts are useful to many of us.

The Terminal Essentials provide a few general-purpose scripts and aliases, and a surprisingly simple way to manage them. Most scripts are wrappers to existing programs, and therefore short and easy to understand. Yet, they are extremely useful.

Features

  • dog: simple script and alias management system
  • put/get: copy&paste for files
  • go: an ssh shortcut
  • c: cd deeper into the filesystem hierarchy
  • backup: rudimental rsync backup of your files
  • archive: rename folders with the YYYY-MM-FolderName convention

The Terminal Essentials assume you are using the bash shell.

Philosophy

The core of the Terminal Essentials is a "bin" folder in your home directory, holding your own scripts as well as those of the Terminal Essentials. This is nothing new, and has been standard on many Linux distribution for years. Inside this "bin" folder, you can now configure your "dog", which is simply a set of aliases, shell functions, servers you frequently access, and other configuration values. Dogs are like the ".alias" file seen on one Linux distributions - just a little bit more advanced.

If you are working on multiple computers - potentially running different on different operating systems - you deploy your bin folder on all of them, and simply activate the appropriate dog.

Download

Download terminal-essentials.tar.bz2

Getting Started

Download the Terminal Essentials and unzip them with

tar xfj terminal-essentials.tar.bz2

Launch the install script which will help you setting up your dog (you won't need root access):

terminal-essentials/bin/terminal-essentials-setup

This script is small but very verbose.

Editing Your Dog

To edit your dog, type

dog

This will launch "vim" with your selected dog and reload it once you finish editing. If your dog imports other dogs, you can edit them with

dog name-of-the-dog-to-edit

The content of a dog file should be mostly self-explanatory to frequent terminal users.

Want to know what your generated ".dog" file looks like? Cat your dog :-)

cat .dog

To change your dog, type

dog --set name-of-new-dog

Using put/get to Copy&Paste Files

The put/get commands can be used to copy files or folders in the convenient copy&paste fashion. From the source folder, copy a file with

put name-of-the-file
Then paste it by typing
get

inside the destination folder. Note that you can put several files and folder before calling get. These files will simply be collected in your transfer folder until you get them. Try this, for instance:

cd source-folder
put file1 file2
put folder3
cd destination-folder
get

put/get are actually scp wrappers, which means that you can copy&paste from one computer (or account) to another. If your first argument to put or get is the name of one of your servers defined in your dog (the GO_* variables), files will be copied to and from this server. Test this by typing

cd source-folder
put computer2 file1 file2
put computer2 folder3

on your computer 1

cd destination-folder
get        or: get local

on your computer 2

Go to Your Servers

With the "go" command, you can easily ssh to your servers, e.g.

go computer2

to connect with the preconfigured username, or

go computer2 as root

to log in as root user.

Quick ls -la

The following aliases (which are fairly standard on many Linux distributions) are configured by default:

Alias Command
l ls -la (or ls -laG on Mac OS X)
.. cd ..
... cd ../..

Deep CD

If you find it tedious to type

cd MyCurrentProjects/2008-04-SampleProject/simple_examples

try this

c simple

This command will look for directories up to 3 levels deep containing "simple" in their name. If only one directory name matches, it will cd into that directory. If multiple directories match, a list of matches is shown.

Other useful variants are

c ex simple

which looks for directories containing both "ex" and "simple" (in any order) in their name, or

c -4 simple

which looks 4 levels deep instead of just 3.

Simple rsync Backup

A simple backup script based on rsync copies all modified files in your home directory (or whatever folders you specify) onto another disk. To use that, activate and adjust the following lines in your dog file:

export GO_BACKUP=backupuser@backupserver.mydomain.com
export BACKUP_REMOTEFOLDER=/Volumes/Backup/my_username
export BACKUP_RSYNCARGS='--exclude *.o --exclude *.d'
export BACKUP=/home/my_username:/data/my_very_important_files

and then invoke the backup script from time to time by typing

backup

This is a rather simple and rudimental backup solution, and may not be sufficient for your backup needs. Note that you need to to add a cron job by yourself in case you want to backup automatically in regular intervals. The backup script really just backs up your data when you launch it.

Archive Folders

One of the most widespread folder naming conventions is to prepend year and month (in ISO 8601 format) to the actual folder name. This is easy to read and most useful for archives, as folders appear in chronological order, e.g.

2007-10-SampleProject
2008-06-AnotherProject
2008-07-YetAnotherProject

The archive script automatically renames a folder according to this convention. By default, it uses the folder modification date,

archive SampleProject

but it can also use the current date,

archive -now SampleProject

or a manually provided date,

archive -y 2007 -m 10 SampleProject

Feedback, Support and Bug Reports

Feel free to contact me if you have questions or comments.

© 2010 Thomas Lochmatter, 2010-01-07