4

This question already has an answer here:

I would like to know how can I delete a file and/or move it to trash with mv command?

I know where the trash located is, then I tried with this commands to move it to trash:

mv somefile /home/username/.local/share/Trash

this command work fine, but when I open trash in launcher it's still show empty. I can undo this deleted file in original location with:

mv /home/username/.local/share/Trash/somefile ~/

but if this location /home/username/.local/share/Trash isn't for Trash then where is moved my file?

I know rm will permanently delete file and not send it to a trash folder and there is no flag in man rm to delete file to trash.

marked as duplicate by Eric Carvalho, Sylvain Pineau, mikewhatever, muru, Gilles Sep 29 '14 at 21:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Also see this recent question+answer: askubuntu.com/questions/213533/… – v2r Sep 14 '14 at 14:45
  • 1
    I missed out on that one! Thanks for mentioning it! – v2r Sep 14 '14 at 15:11
  • 4
    If you will use mv to move a file to trash, you will never enjoy the option to restore that file from the trash! From here my downvote (sorry). – Radu Rădeanu Sep 17 '14 at 6:00
  • 2
    Ok, then what is your reason to put things in the trash? Just to have things there? Perhaps you do not understand the point of the trash. A novice user can take your idea as a good advice and this is not desirable. – Radu Rădeanu Sep 17 '14 at 6:30
  • 4
    @KasiyA Another reason for downvote: your terminology is not correct: You can delete something from ..., but not to .... When you delete something from one location and then you see that thing at another location implies an action which is called move (not delete). – Radu Rădeanu Sep 17 '14 at 7:30
11

Information about Trash directory:

~/.local/share/Trash contains two directories named info and files.

  • ~/.local/share/Trash/files contains original files.
  • ~/.local/share/Trash/info contains files (extension : .trashinfo)which have information about path and deletion date of files.

Therefore, if you want to use mv command then follow command:

mv somefile ~/.local/share/Trash/files

But it is not recommended to use above method to move files to trash.(as commented here)


You can install trash command line i.e. trash-cli by following command:

sudo apt-get install trash-cli

And here are available commands for trash:

$ apropos trash
gvfs-trash (1)       - Move files or directories to the trash
restore-trash (1)    - Restore for Command line trash utility.
trash (1)            - Command line trash utility.
trash-empty (1)      - Empty for Command line trash utility.
trash-list (1)       - List trashed files.
trash-put (1)        - Command line trash utility.

You can move/put files to trash by following command:

  1. trash-put somefiles
  2. or gvfs-trash somefiles

List trash by command: trash-list
Restore files by command: restore-trash
Empty trash by command: trash-empty

Also visit this Question.

  • 1
    Also visit : linuxg.net/… – Pandya Sep 15 '14 at 2:25
  • 4
    I will never advice someone to use mv command to move a file to trash. See this comment to understand why. – Radu Rădeanu Sep 17 '14 at 6:09
  • @RaduRădeanu Ok. I revisied my answer to including all. – Pandya Sep 17 '14 at 14:29
12

You can use gvfs-trash instead of mv

gvfs-trash somefile

The reason you were unable to see your file after moving it to ~/.local/share/Trash is that there is an additional directory structure below that i.e.

  • ~/.local/share/Trash/files to contain the actual trashed file; and
  • ~/.local/share/Trash/info containing metadata such as the original location

Although you could have used

mv somefile ~/.local/share/Trash/files

in which case somefile would be visible in the trash can, it would not be possible to use the nautilus/gvfs Restore function to undelete the file, due to the lack of info metadata - you would need to know and manually mv the file to its original location. In that sense, only gvfs-trash is the exact command-line equivalent to trashing a file via nautilus.

  • 1
    @KasiyA That shouldn't happen with gvfs-trash since it's part of GNOME (i.e. integrates with other GNOME components such as Nautilus) – Glutanimate Sep 14 '14 at 15:50
  • 8
    Also note that gvfs-trash elegantly handles the case of sending to the trash two independent files with identical names, but using mv the first "trashed" such file would be irreversibly gone. – Marc van Leeuwen Sep 14 '14 at 16:38
  • 1
    gvfs-trash has been deprecated in favour of gio trash. – Teemu Leisti Jun 26 '18 at 12:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.