(dired.info)Deleting Files With Dired

Next: Dired Shell Commands Prev: Other File Creating Commands Up: Mark-using Commands

Deleting Files With Dired

Deleting is a special mark-using command.  It uses a special marker,
`D', and does not default to the current file if no files are marked to
prevent accidental deletions.

   Note: Dired Customization, variable `dired-del-marker' to make
deleting behave exactly like any mark-using command.

     (`dired-flag-file-deleted') Flag this file for deletion.  If on a
     subdirectory headerline, mark all its files except `.' and `..'.

     (`dired-unmark-subdir-or-file') Remove deletion-flag on this line.

     (`dired-backup-unflag') Remove deletion-flag on previous line,
     moving point to that line.

     (`dired-flag-regexp-files') Flag all files containing the specified
     REGEXP for deletion.

     The match is against the non-directory part of the filename.  Use
     `^' and `$' to anchor matches.  Exclude subdirs by hiding them.

     The special directories `.' and `..' are never flagged.

     (`dired-do-deletions') Delete the files that are flagged for
     deletion (with `D').

     (`dired-do-delete') Delete the `*'-marked (as opposed to the
     `D'-flagged) files.

     (`dired-flag-auto-save-files') Flag all auto-save files (files
     whose names start and end with `#') for deletion (*note
     Auto-Saving: Protection Against Disasters: (emacs)Auto Save.).

     (`dired-flag-backup-files') Flag all backup files (files whose
     names end with `~') for deletion (*note Backup Files:

`. (Period)'
     (`dired-clean-directory') Flag excess numeric backup files for
     deletion.  The oldest and newest few backup files of any one file
     are exempt; the middle ones are flagged.

   You can flag a file for deletion by moving to the line describing the
file and typing `d' or `C-d'.  The deletion flag is visible as a `D' at
the beginning of the line.  Point is moved to the beginning of the next
line, so that repeated `d' commands flag successive files.

   The files are flagged for deletion rather than deleted immediately to
avoid the danger of deleting a file accidentally.  Until you direct
Dired to delete the flagged files, you can remove deletion flags using
the commands `u' and DEL.  `u' works just like `d', but removes flags
rather than making flags.  DEL moves upward, removing flags; it is like
`u' with numeric argument automatically negated.

   To delete the flagged files, type `x'.  This command first displays
a list of all the file names flagged for deletion, and requests
confirmation with `yes'.  Once you confirm, all the flagged files are
deleted, and their lines are deleted from the text of the Dired buffer.
The shortened Dired buffer remains selected.  If you answer `no' or
quit with `C-g', you return immediately to Dired, with the deletion
flags still present and no files actually deleted.

   Deletions proceed from the end of the buffer, so if subdirs are in a
natural order in the buffer, it usually works to flag `dir1',
`dir1/dir2' and `dir1/dir2/*' (by typing `d' on the directory
headerlines) and delete everything, including `dir1/dir2' and `dir1'.
Using shell commands (e.g.  `rm -rf') to remove complete directories
may be quicker than having Dired remove each file separately. (*Note
Dired Shell Commands::.)  However, like all actions external to Dired,
this does not update the display.

   The `#', `~' and `.' commands flag many files for deletion, based on
their names.  These commands are useful precisely because they do not
actually delete any files; you can remove the deletion flags from any
flagged files that you really wish to keep.

   `#' flags for deletion all files that appear to have been made by
auto-saving (that is, files whose names begin and end with `#').  `~'
flags for deletion all files that appear to have been made as backups
for files that were edited (that is, files whose names end with `~').

   `.' (Period) flags just some of the backup files for deletion: only
numeric backups that are not among the oldest few nor the newest few
backups of any one file.  Normally `dired-kept-versions' (not
`kept-new-versions'; that applies only when saving) specifies the
number of newest versions of each file to keep, and `kept-old-versions'
specifies the number of oldest versions to keep.  Period with a
positive numeric argument, as in `C-u 3 .', specifies the number of
newest versions to keep, overriding `dired-kept-versions'.  A negative
numeric argument overrides `kept-old-versions', using minus the value
of the argument to specify the number of oldest versions of each file
to keep.

automatically generated by info2www