Why does deleting from the command line take significantly less time than from a GUI?
Solution 1:
As you rightly noticed the GUI does more than just "delete" the files.
$ rm -rf
just recurses into folders deleting the files and folders it finds in there.
The GUI first scans the whole tree to work out what there is there (so it knows how much it has to do to draw the pretty bar), then it recurses through the tree again moving the files from the current location to the location of the trash can files for your specific GUI. That moving takes longer, as it has to first generate a new unique filename, link the file in the trash folder, then unlink it from the current folder, and update an index of where the files came from so they can be "undone" - many operations instead of just one.
For instance, on Gnome 3 the files are moved to the location:
~/.local/share/Trash/files/<filename>[.<version>]
Where filename
is the original file name, and version
is an incrementing version number to ensure the file is unique (the first file instance has no version number). Associated with that is a .trashinfo
file stored in the folder:
~/.local/share/Trash/info/<filename>[.<version>].trashinfo
This file contains the original path of the file before deletion, as well as the date and time this file was deleted.
All these extra operations, which have to be performed on each and every individual file in the tree you are deleting, ensure that you are able to restore any file from the trash can, and that you are able to delete files named the same from the same location and still restore earlier versions.
None of that is done with a simple rm
or mv
command.