10

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

Boann
  • 117
Billal Begueradj
  • 6,011
  • 11
  • 39
  • 56

1 Answers1

16

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!

Terrance
  • 41,612
  • 7
  • 124
  • 183
  • 2
    For moving files to trash via command line: How to open “Trash” through terminal? – wjandrea Oct 23 '18 at 21:15
  • 4
    This updates the pointers to the files. Yes, or to be more accurate it updates directory's listing of inodes which actually are the pointers to blocks of disk space we call files. +1ed. Also if there's just minimal number of subdirectories and majority of files are there, that's gonna be faster probably, since I think it's only necessary to move subdirectory's inode to another directory's listing. Removing is recursive traversal of whole directory - that's opening syscalls, unlinking syscalls, etc, so of course longer. – Sergiy Kolodyazhnyy Oct 23 '18 at 21:26
  • @SergiyKolodyazhnyy I really do like your explanation here! Thank you! =) – Terrance Nov 20 '18 at 15:11