dired
is Emacs built-in tool to work with directories and files. It
resembles the "commander" like tools which go beyond the command line,
but are not graphical in a modern sense. You will find that dired
is
immensely powerful.
To enter dired-mode do
C-x d directory <RET>
or
M-x dired
C-u C-SPC
brings the cursor backMenu Regexp, Mark...
allows to mark files by a regexp e.g.
\.vmc$
selects all files with extension "vmc"Menu Operate, Search Files...
(dired-do-search) allows to search
for content.! find "redetho" *
When the files are all in the same directory or in not too many sub-directories:
M-x dired
\.ext$
, which is a regexp
to search for the file extension "ext"Operate... > Query Replace in files
The find-dired
command lets you run arbitrary 'find' commands, then
displays the results in a dired buffer, including arbitrarily nested
subdirectories.
E.g. to list all executable files containing the string "foo", case insensitively, rooted at /usr:
M-x find-dired <RET> //usr <RET> -iname "*foo*" -executable -type f
Move up one directory (this opens a new dired buffer):
^
Enter a directory without opening a new buffer (in contrast to f
oder RET
):
a
Move a file or a whole directory:
R
Use the up- or down-arrow in Emacs' mini-buffer to select a target path; paths in other Emacs windows will feature.
Do dired of the directory of the file you are currently editing:
M-x dired-jump
Manually input a path (like CD xyz):
C-x d
w
copies the name of the current file or the marked files to the
"kill-ring" (clipboard)C-0 w
copies the absolute path to the kill-ringC-u w
copies the relative path to the kill-ring.
The last option deserves more explanation: there is the notion of
default-directory
for each Emacs buffer. For a dired buffer, this
directory is normally the directory shown by dired. However, you can
set default-directory
using M-x cd
. Thus C-u w
will yield a
non-trivial relative path.
You can associate further file extensions with external commands, to open them from dired, e.g.
(add-to-list 'dired-guess-shell-alist-user '("\.mkv\'" "vlc"))
This complements what the variable dired-guess-shell-alist-default
specifies.
Toggling sorting between date and name:
s
To sort by size:
C-u s S
the big S is ls format option by size
Toggling detailed and terse view:
(
Get two "panes" (Emacs windows):
M-x split-window-horizontally
which is an alias of split-window-right
Menu-bar -> File -> new-window-on-right
Or simply do
C-x 3
Switch between windows ("other" window):
C-x o
To go back to one pane only:
C-x 1
Listing a directory via FTP:
/ftp:user@host.tld:/directory/
The :/directory/
part seems to be mandatory
To copy the dired path to the clipboard, move the cursor to top dired window line (i.e. the one with the path):
w
The path will end with a slash. Note: also under MS Windows this will yield forward slashes. However, the Windows tools accept paths with forward slashes too.
I customised dired-listing-switches
to "-Al")
-A
omits the .
and ..
directory entries-l
always has to be present.To sort directories at the top and hide hidden files:
(setq dired-listing-switches "-lF --group-directories-first")
On Windows, dired is using a Lisp emulation of ls
. My preferences:
ls-lisp-dirs-first
t
ls-lisp-format-time-list
(quote ("%Y-%m-%d %H:%M:%S" "%Y-%m-%d %H:%M:%S")))
ls-lisp-use-localized-time-format
t
speedbar is Emacs built-in tool to explore directory trees, like you it in various graphical user interfaces. You start speedbar with
M-x speedbar
The speedbar is bound to the active frame and lives in its own frame.
speedbar can be used together with dired. C-x d
works in a speedbar
frame as well. It offers to dired
speedbar's "current" directory.
However, that directory is the one shown at the top of the speedbar
frame, not something in the tree that you might have opened below.
In other words: you need to go down to the wanted directory and use
RET
to make it current. BTW: U
(shift-u) sets speedbar's current
directory "up" one level.