I've created a new command which I believe is an improvement to the normal Linux/Unix cd command, and I thought I'd share it here.
(If you're just looking for the Download link, it's at the bottom of this article.)
(Also, if you'd like to see the Teleport command in action, I've created this Teleport command demo video on YouTube.)
I've named the command "teleport", and it's intended to be a replacement for the Unix/Linux cd command. (Really, it's a wrapper around the cd command, first doing all of its work, and then issuing the appropriate cd command.)
The teleport command (tp, for short) does everything the Linux cd command does, with these improvements:
Once installed, you can get help on the teleport command by issuing the -h flag, like this:
tp -h
This displays a usage statement similar to the following:
Usage: tp [DIR]
Purpose: Provide the same capabilities as the 'cd' command, but with a memory
of directories that you have previously visited.
-h Show HELP (this output)
-j PARTIAL-DIR
JUMP to a directory found in your history (by partial directory name)
-l LIST the history of visited directories
-n NUM Go to a directory by NUMBER. NUM corresponds to the number printed
by the -l option
-s DIR SEARCH for and display a directory named DIR found in your history
Given that starter information, let's see what the teleport command can do.
For basic cases, you'll use the tp command just like the cd command. For instance, to move to your home directory, just type tp by itself, just like you would with the cd command:
tp
Or, if you prefer more typing, you can add the ~ character:
tp ~
Either one of those commands will take you to your home directory, just like cd.
To move back to your last directory, just add a -, again, just like cd:
tp -
To move to a local subdirectory named Pictures, again just replace the cd command with tp:
tp Pictures
To move to an absolute directory, like /tmp, again tp works just like cd:
tp /tmp
And to move up two directory levels, again, tp is the same:
tp ../..
Nothing too exciting yet ... so far it it works just like the Unix/Linux cd command. Now let's have some fun.
Where the tp command really shines is with its memory. For instance, let's say your current working directory is something like this:
/tmp/foo/bar/baz
Next, let's assume you want to move to another directory somewhere else in the filesystem, like this one:
/home/al/Pictures/2008/AlaskaTrip/Talkeetna
With the cd command, you'd normally have to type something like this:
cd /home/al/Pictures/2008/AlaskaTrip/Talkeetna
But with the tp command, if you've already been to the Talkeetna subdirectory, all you have to type is this:
tp Talkeetna
The teleport command instantly takes you to that directory. In this case, that saves you over 30 characters of typing.
Here's an image showing a few more examples of how easily the Teleport command lets you jump around:

This is one example of what remembering your working directory history can do for you, and is the primary reason for the name "teleport".
The next nice thing teleport does is provide a listing of your teleport history. When you issue the teleport "list" command, like this:
tp -l
teleport will show you all the directories you've visited recently, like this:
/Users/al/AlsLife/DD/Projects/DDBlog/htdocs/caketest1/app/tmp/logs /Users/al/AlsLife/DD/Projects/DDBlog/htdocs/caketest1 /Users/al /Users/al/bin /Users/al/AlsLife/DD/Projects/DDBlog/htdocs/caketest1/app /Users/al/AlsLife/DD/Projects/DDBlog/htdocs /tmp /Users/al/AlsLife/DD/Perl /Users/al/AlsLife/DD/Perl/ArrayTests /Users/al/OldLaptop/C_Drive/Projects/DDProjects/TypeAheadTests /Users/al/Xfer /Users/al/AlsLife/DD/Projects/DDBlog /Users/al/AlsLife/DD/Projects/DDBlog/sql /Users/al/AlsLife/DD/Perl/ArrayTests
I like this feature because (a) I work on a lot of different projects every week, and (b) I have a bad memory. With the teleport command, it's much easier to remember where all my project files are located.
Also, once you've seen this history, you can teleport to any of those directories very easily. For instance, no matter where I am currently in the filesystem, if I want to go to this directory:
/Users/al/AlsLife/DD/Projects/DDBlog/htdocs/caketest1/app/tmp/logs
all I have to type is this command:
tp logs
and I'm instantly teleported to that directory. I hope you'll agree that's a really nice time-saver.
The teleport command also includes an option to let you teleport to a directory by the number that is shown when you list the teleport history. As of this writing this option isn't currently implemented, but as soon as I fix it, your teleport history will look like this:
tp -h 1 /Users/al/AlsLife/DD/Projects/DDBlog/htdocs/caketest1/app/tmp/logs 2 /Users/al/AlsLife/DD/Projects/DDBlog/htdocs/caketest1 3 /Users/al 4 /Users/al/bin 5 /Users/al/AlsLife/DD/Projects/DDBlog/htdocs/caketest1/app 6 /Users/al/AlsLife/DD/Projects/DDBlog/htdocs 7 /tmp 8 /Users/al/AlsLife/DD/Perl 9 /Users/al/AlsLife/DD/Perl/ArrayTests 10 /Users/al/OldLaptop/1_Al/DDProjects/TypeAheadTests
and then you'll be able to teleport to a directory by number, like this:
tp -n 5
That command will take you to the 5th directory shown in your history, i.e., this directory:
/Users/al/AlsLife/DD/Projects/DDBlog/htdocs/caketest1/app
This can be a nice feature for when you have multiple directories that end with the same name. For instance, in this case, if you had two directories named app, you would use this command to get to the right app directory ... or ...
You can also use a teleport alias.
Teleport aliases provide a simple way for you to create aliases to directories. If you want to resolve conflicts between multiple directories with the same name (as I just showed in the previous section), or you simply want to make sure teleport always knows about a certain directory, you can create an alias for that directory.
Currently the teleport alias works as a separate command named tpa. (I've thought about merging the tp and tpa commands into one command, but have not done so yet. After using the commands for a while, I'll be glad to hear your opinion on whether they should be merged together, or not.)
Here's the usage statement for the teleport alias (tpa) command:
Usage: tpa ALIAS Purpose: Transport to a directory that has an alias ALIAS associated with it. -a ALIAS DIR Add ALIAS as an alias/shortcut for the directory DIR -h Show HELP (this output) -l LIST the known directory aliases -r ALIAS Remove ALIAS from your list of known aliases
To add a new teleport alias, use the -a option, and specify the alias first, followed by the actual directory name, like this:
tpa -a baz /tmp/bar/baz
After issuing that command you'll see output similar to this:
Alias "baz" was added for the directory "/tmp/bar/baz".
Once you've created an alias like that, no matter where you are on the filesystem, you can move to that directory using your alias with the tpa command, like this:
tpa baz
To list your teleport aliases, just use the -l option of the tpa command, like this:
tpa -l
This will list all of the aliases you've defined, like this:
perl:/Users/al/AlsLife/DD/Perl arrays:/Users/al/AlsLife/DD/Perl/ArrayTests pub:/Users/al/AlsLife/DD/Perl/published
(I need to improve this format, but that's the way it looks currently.)
To remove a tpa alias, just use the -r option and the name of the alias, like this:
tpa -r pub
The tpa command responds like this:
About to remove alias "pub" -- are you sure (y/[n])?: _ Remove operation cancelled.
At this point 'n' will cancel the remove operation, and 'y' will proceed with the remove.
I hope you like the teleport command. I think it makes some nice improvements to the standard Linux cd command.
The hardest part for me when I first started using it was remembering to type tp instead of cd. Once I made it through that mental hurdle, I now hate to work on systems where I haven't installed the teleport command yet.
You can download the teleport command as a tar'd and gzip'd file from the following link:
This file will extract to a directory named teleport, and that directory will contain the following files:
teleport/tp_command teleport/INSTALL teleport/LICENSE
Once you've extracted the contents of this file, you can proceed with the installation. See the INSTALL file for more information.
Many thanks to everyone who
Many thanks to everyone who has sent me emails about the Teleport command already. To answer your questions, yes, I will put this on a site like SourceForge or Google Code, and yes, I will try to add the other features soon.
I am curious. Do you know
I am curious. Do you know about the bash built in commands "pushd" and "popd"?
pushd, popd, and dirs
Yes, I was aware of them, and I probably should have mentioned them (and the dirs command) here. I'll try to write up a little tutorial about them this week.
FWIW, I went with this approach b/c I like this being automated. I don't have to think about pushing and popping, it just happens.
Thanks for your comment. In my experience, not many people know about pushd and popd.
Thanks dude, I like this. A
Thanks dude, I like this. A simple idea, but clever.
Very useful command, thanks
Very useful command, thanks
I seem to have problems with
I seem to have problems with directory names that have spaces
Teleport now handles directories with spaces
Sorry for the very long delay here, I've been busy, moved 4,500 miles, etc., but I've finally updated the teleport command to Version 0.3, with the primary visible change being that I now properly handle directories with spaces in them.
I've updated the Download link here. Any problems, just let me know.
Thanks for fixing the issues
Thanks for fixing the issues with spaces, it works fine with tp, but with tpa I cannot get it to work, maybe I need some instructions.
tpa command
Alex -- Sorry for the long delay, I'm about 100 comments behind here. I'll look at the tpa portion of this over the weekend.
Teleport tpa command fixed
Sorry again for the long delay here, but the tpa command should now be working with directory names that contain spaces. The latest version is 0.4, and it is now available here for download (see the download link).
thanks!
Thanks Alvin! I just updated teleport and all my directories with spaces work perfectly. This is a wonderful program!
Great work
I was planning to write exactly similar command. Searched hard on internet and found this.
Great work. one suggestion, may be a option of unique history of directory visited will be good too
Thanks
Post new comment