Next: Dired Visiting Prev: Dired Commands Up: Dired
Deleting Files with Dired
The primary use of Dired is to "flag" files for deletion and then
delete the files previously flagged.
Flag this file for deletion.
Remove deletion flag on this line.
Move point to previous line and remove the deletion flag on that
Delete the files that are flagged for deletion.
Flag all auto-save files (files whose names start and end with `#')
for deletion (Note: Auto Save.).
Flag all backup files (files whose names end with `~') for deletion
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.
`% d REGEXP RET'
Flag for deletion all files whose names match the regular
expression REGEXP (`dired-flag-files-regexp'). This is just like
`% m' except that it uses `D' instead of `*' to mark the files.
Only the non-directory part of the file name is used in matching.
Use `^' and `$' to anchor matches. Exclude subdirectories by
hiding them (Note: Hiding Subdirectories.).
You can flag a file for deletion by moving to the line describing the
file and typing `d'. The deletion flag is visible as a `D' at the
beginning of the line. This command moves point 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
reduce the danger of deleting a file accidentally. Until you direct
Dired to expunge 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' (`dired-expunge'). This
command first displays a list of all the file names flagged for
deletion, and requests confirmation with `yes'. Once you confirm, `x'
deletes all the flagged files, then deletes their lines from the text
of the Dired buffer. The shortened Dired buffer remains selected.
If you answer `no' or quit with `C-g' when asked to confirm, you
return immediately to Dired, with the deletion flags still present in
the buffer, and no files actually deleted.
The `#', `~' and `.' commands flag many files for deletion, based on
their file 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 whose names look like auto-save
files (Note: Auto Save.)--that is, files whose names begin and end
with `#'. `~' flags for deletion all files whose names say they are
backup files (Note: Backup.)--that is, whose names end in `~'.
`.' (Period) flags just some of the backup files for deletion: all
but the oldest few and 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
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.
The `% d' command flags all files whose names match a specified
regular expression (`dired-flag-files-regexp'). Only the non-directory
part of the file name is used in matching. You can use `^' and `$' to
anchor matches. You can exclude subdirectories by hiding them (*note
automatically generated by info2www