Why does deleting a folder from the command line take longer than manual deletion? [duplicate]

I noticed whenever I want to delete a folder containing a lot of data using a command line (sudo rm -r folder_name), the Terminal hangs on for the operation to terminate. But at the same time, when I manually delete a folder of similar size, the deletion is performed instantly without waiting.

Any explanation as to why this difference happens


Solution 1:

When you delete from the GUI you are only moving the files to the trash bin. This updates the pointers to the files instantaneously saying that they now reside in the trash bin which is another folder.

When you delete from the command line like that it is removing the files 1 by 1 until they are all gone from within the folder then removing the folder itself. This bypasses the trash bin. This also takes longer.

If you do a Shift+Del in the GUI this will bypass the trash bin and take longer to delete.

Hope this helps!