Picking back up on the Emacs series I started earlier this month I would like to take some time to discuss the Dired mode for directory management.
I've used ECB in the past and found it nice, feature rich but in my opinion it had too much information and was in my way, not to mention it drastically increases emacs load time. So I removed it from my configs and now only use Dired. Once you get used to it it really is very powerful.
The Basics
To initiate a Dired buffer type C-x d and you will be prompted for a directory path starting in the directory of your current open buffer. Navigate the path you want to open and return to open it. If you haven't extended Dired with additional modes, you'll get something that looks like a terminal directory listing (ls -lna). I'll tell you how to change this later.
Navigation
Movement in Dired is exactly like any buffer so I won't go into that here. For long directories I always navigate with iSearch (C-s and C-r). It's much easier to jump to a particular location.
To open a folder press f (find-file). To go up a directory type ^. Every time you open a new directory a new buffer is opened in the background for you and always accessible until you kill it.
Top view a file in read-only mode, press v. To return to the Dired buffer press q.
o will open the file in another window while RET or f will open the file in the current window. At anytime in the Dired buffer you can sort by typing s.
Deleting files
Dired allows you to perform actions on files and folders such as deletion, renaming, etc.
To delete files, you first must mark the files you want to delete by navigating to the file or folder and pressing d which will place a capital D to the left of the file. When you are done with your selections x will initiate the actions and you will be prompted to confirm your actions. Typing # marks all the autosave files for deletion with a D status and typing ~ marks all the backup files for deletion with the same status. At any time, if you accidentally mark a file you can press u to unmark it.
Copying and Renaming Files
To copy a file first navigate to it and press C (capital C). Emacs will ask you for the name of the file to copy to. Enter will execute the copy. If you type C4 from the file you are on, the current file and the next three will be copied.
To rename a file type R. Are you getting the naming conventions yet? Emacs will ask you for the new file name and again, Enter will execute it.
File Compression
You can compress and uncompress files from Dired by typing Z. You will be asked to confirm. Z is universal in that it will uncompress a compressed file or compress it if it's not compressed already.
Diffs
Dired lets you compare a file with its respective backup file. This has come in handy many times for me. Find the file you want to compare and press =. You'll be presented a buffer showing you the difference in the two files.
Extending
To make the dired buffer a little more presentable and less like terminal I installed a few other modes. Install Dired+ which will give you extra command and expand on existing commmands. It will also give you some better file highlighting than what is present in the default Dired mode. I also installed Dired-details and Dired-details+ to customize the look of my Dired buffers like the picture above.
With these additions I added the following to my dotemacs files to hide files I don't want to see, such as .pyc, backups and autosave files.
(require 'dired-x)
(setq dired-omit-files
(rx (or (seq bol (? ".") "#") ;; emacs autosave files
(seq "~" eol) ;; backup-files
(seq bol "svn" eol) ;; svn dirs
(seq ".pyc" eol)
)))
(setq dired-omit-extensions
(append dired-latex-unclean-extensions
dired-bibtex-unclean-extensions
dired-texinfo-unclean-extensions))
(add-hook 'dired-mode-hook (lambda () (dired-omit-mode 1)))
(put 'dired-find-alternate-file 'disabled nil)








On Sunday, Nov 16
Another cool thing with dired is you can mark individual files with m and then remove them from the buffer with k I use this because I'm too lazy to install and setup dired-x. Now that I have it all mapped out for me, I have a lot less of an excuse :-P Thanks!
On Sunday, Nov 16
I didn't know that Justin, thanks.
There's a lot more that Dired can do. I've only scratched the surface with the basics in this post. Grouping is very nice and might make it to another post.
On Monday, Nov 17
This series are great, Greg! I'll read it all and update my .emacs with your tips. More comments soon.
On Monday, Nov 17
Thanks Edcrypt! I appreciate that.
Hopefully more coming soon. I'm testing out Pysmell right now which might make a great post.
On Monday, Nov 17
This is awesome. As a Django/emacs user I was particularly excited to see some Django template support in your .emacs samples.
I've been pretty happy with flymake+pylint but if there are more advanced Python tools ahead I'll be thrilled. Thanks for the series!
On Tuesday, Nov 18
Thanks Liza. Glad you enjoy it.
I have not used flymake & pylint but have heard a lot about them. Right now I'm using Rope and Ropemacs. I'm also going through some testing with PySmell which looks pretty nice. A Python Emacs post is in the works for the series.
On Tuesday, Nov 18
Slight correction: Incremental search is mapped to C-s and C-r not (C-x s and C-x r).
On Tuesday, Nov 18
Correct you are, I did not catch that mistake, thanks Tim. Corrected.
On Tuesday, Nov 18
I became inspired and decided to write my own post instead of wasting comment space here:
http://muublog.blogspot.com/2008/11/inspired-by-this-blog-post-by-greg.html
/Mathias
On Tuesday, Nov 18
Hello Mathias. I tried to comment on your post at blogger but it won't allow it.
Great information Mathias!! Thanks for leaving the link. I'm convinced there will always be something to learn with emacs.
I think the most useful for me from your narrative is dired-upcase and dired-downcase. I wasn't aware that was available. Thanks. I also wasn't aware of wdired. Grabbing it now.
On Wednesday, Nov 19
Can one get a norton commander two panel style functionality with dired or other dired extensions?
On Wednesday, Nov 19
Greg,
I forgot that the comments were only for members of my blog. I opened it up now, will see how that works. Great that there were things you did not know about Dired! :)
You say that you are "grabbing" wdired, does it mean you are trying to download it? It is part of Emacs since version 22 at least.
Happy directory editing! :)
/Mathias
On Wednesday, Nov 19
Mathias,
I actually double checked before I went to the wiki to download it. :)
Thanks for opening comments. It's always nice to see other people leave useful information.
On Wednesday, Nov 19
Lol Lolovici,
There are one or a few modes that tries to mimic midnight commander and friends and maybe there is one that uses Dired as part of the mode. However I don't think you can do more with that than with two Dired buffers side by side (or over/under). There is a dwim (do what I mean) setting that makes copy and rename command "guess" that you want to copy or rename to the directory in the other window.
/Mathias