Reading Tar Files With Emacs

I’ve been using Emacs for some time but am still regularly amazed at how it just does the right thing and in the expected way. Emacs has a well deserved reputation of having a steep learning curve and, indeed, like most Emacs users I’m still learning but it also has a simplicity and a “just works” quality that I haven’t found in any other editor.

Case in point: tar files. I do most of my work with OS X and don’t use any of the package managers so my normal procedure is to download tar files (unless there’s a git repository) and compile from scratch. Often times, it’s nice to know what’s in the tar file. For example, I have a tools directory and I untar into it to create a subdirectory for each project. Before doing that I always check the tar file to make sure it’s not going to spew a bunch of files into the top level tools directory. That’s easy enough to do with

tar -tvzf some_project.tgz

but Emacs gives us another way—a completely obvious and expected way. You merely open the tar file in Emacs with 【Ctrl+x Ctrl+fsome_project.tgz. This will give you a Dired style listing of the tar file but that’s not all. You can move the point to one of the files in the listing, type 【e】 or 【Return】 to load it into an editing buffer, edit it, and then save it back to the tar far—all without untarring the files. You can also delete and copy individual files.

All this works in the expected way; it’s not quite Dired but close enough that you can forget it’s not. It just seems natural until you think about what’s going on. First the file is compressed so Emacs has to decompress it, second Emacs has to understand the tar file format and extract the file you want to edit from the archive and then reinsert it. Finally, it has to recompress the archive. All of this is so simple and transparent that you could discover it accidently by inadvertently opening a tar file.

As I say, I’m always discovering some great new Emacs functionality that in retrospect seems so natural and obvious that I wonder why I didn’t “just know” it was there. That is until I think about what’s going on under the covers. Then I realize what a really great tool Emacs is.

Update: e → 【e

This entry was posted in General and tagged . Bookmark the permalink.