I have talked about some basics about emacs in the last 10 days. From now on, I will be focus more on the specific usage of emacs. On around day 19, I will start to talk about my attitude towards emacs 1.
Today I will talk about two sysadmin tasks that are suitable to be done in emacs. There are many other tasks in the realm of sysadmin. For those I would rather do them in the shell, which I talked about on day 5.
On day 4, I talked about it is not a good idea to use emacs like vi(m). This is another example: Some configuration files can only be edited with
/etc/environments. The direct response to this task would be:
sudo emacs /etc/environments
sudo su emacs /etc/environments
For a long time, I really did it like that. But the problem with this approach is that I am launching emacs as root. And my root account doesn’t necessarily have any emacs configuration file. And therefore a vanilla white box is there for me. Nein, danke.
Inside my own emacs, I can actually use
C-x C-f) to open
/etc/environments. But I can’t save.
TRAMP is a built-in feature of emacs and many users would associate it with editing remote files. I don’t want to talk about editing remote files and actually TRAMP is much more powerful than just editing remote files. On a recent enough version of emacs, one can use the
/method::/ syntax in
It can also be used for opening a file with
I use Helm (see day 1) and the helm version of
helm-find-files, can also open a file as
root. This method is under-documented.
The method is to use
M-x helm-find-files, pointing to a file you want to edit as root, then press
C-c r to run
Another task that is suitable to do in emacs is process management. One can also do the same either with 1) the suite of
pkill), or 2) ncurses-based tools such as
The built-in emacs process manager
proced is also useful. For quick-and-dirty tasks such as “sorting processes by memory usage” or “send SIGTERM to a process”, I find it quite useful. It is one of the two “dired-like” tools that I regularly use. What is a “dired-like” tool? Well, a “dired-like” tool looks like the directory editing mode (
dired) of emacs. Commands are largely assigned to one single button. If you need to know two of these single-button commands, know
g for refresh (or
q for quit. Usually, these tools also have a mechanism to select multiple items by marking one item with
m. And also important to know how to unmark one item
u and unmark all
OK. Firing up
M-x proced, I see something like that (by default it is opened as a split-window).
It is very similar to running
ps. But the buffer is searchable by the usual
isearch-backward) or even regex search
C-M-s. For example, I want to search for a process with
eog (the image viewer)
I can kill this process by pressing “k” and send a TERM signal (“Terminate”) to it.
htop, the buffer is not constantly updated. One need to manually update it by pressing
g. For senior citizens like me who read slowly, I like it. But if you don’t like it, you can toggle the auto-update mode by the command
I have a complicated relationship with
dired. As I said on day 5, I prefer to do file management in the shell.
I have tried several times to make
dired more useful, e.g. using Sunrise Commander. I think the fundamental problem is that I have a preconception that it is faster to do file management with the command line and not quite familiar with managing files in the 2-dimensional space with tools such as Norton Commander. For some tasks, emacs adds value by changing it from 1-D to 2-D, e.g.
proced. But to me, file management isn’t one of these tasks. “But that can well be my prejudice.”™
image-dired is something I can appreciate. It is a nice interface to deal with a directory full of images with an iPhoto kind-of interface. In this case
image-dired really adds a lot of value for being 2-D. Also it gives another reason to use the GUI emacs.
Tomorrow I will talk about another task that emacs adds a lot of value by changing it from 1-D to 2-D.