Emacs Advent Calendar 15: File Management with Dired
Emacs includes dired, a mode with file manager functionality. As this is quite a big topic, today's entry can only be considered an introduction. Read the Reference Manual for the full documentation.
Dired is started with
C-x d or by visiting a directory with
C-x f. Because
ls is used for listing the directory
contents you can specify its command line options by starting dired
with a prefix argument (
C-u C-x d); e.g.
C-u C-x d -alh
<RET> to get human readable file sizes. To reload the directory
content, e.g. after you made some changes outside Emacs, press
Movement in a dired buffer uses the standard keybindings; in addition
<SPC> move to the next line,
p moves to
the previous line.
To flag a file for deletion, press
d on the correspondig
line. To unflag a file, press
<DEL>. When you
are sure that the right files are flagged, press
x to execute
the deletion command (it will list the files and ask for confirmation
before actually deleting anything).
There are commands to automatically flag files you might want to
~ for backup files (ending in ~),
autosave files (surrounded by #) and some more about which you can
read in the reference manual.
Visiting files from dired is straightforward, just press
e) on a file name. To open a file in another
o or click it with
Mouse-1. To move up one
directory visit the
.. folder or press
While deletion operates on flagged files, all other commands act on
files that are marked. To mark one file, press
works like unflagging with
<DEL>, upper case
U unmarks all files. Files can be marked according to various
criteria (again, see the Manual), for example
* / to select
|C||copy one or multiple files (like cp)|
|R||rename file or move multiple files (like mv)|
|G||change group of file|
|O||change file ownership|
You can run shell commands on the selected file with
& (asynchronously). See the Manual for how
the command can be applied to multiple files.
There are many more features of dired left for you to explore in the manual as needed (systematic file renaming, diff, version control, image preview among others).
For full documentation see chapter 30 of the Emacs Reference Manual (Dired, the Directory Editor).Tags: emacs
This text by Ludger Sandig is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.