The primary use of Dired is to flag files for deletion and then delete them.
Flag this file for deletion.
Remove deletion-flag on this line.
Remove deletion-flag on previous line, moving point to that line.
Delete the files that are flagged for deletion.
Flag all auto-save files (files whose names start and end with ‘#’) for deletion (see Auto Save).
Flag all backup files (files whose names end with ‘~’) for deletion (see Backup).
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.
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
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
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.