Cannot move file to trash warning when trying to delete a file in Nautilus
I am trying to delete files in Nautilus and every time I try to delete one it always gives me this message:
Cannot move file to trash, do you want to delete immediately?
Then it gives me several questions. All I want is that when I press Delete in the keyboard, it sends it automatically to the trash can. Not to ask me every time.
The problem relates to NTFS partitions, external drives but also include Linux filesystems.
What are the reasons for nautilus beeing not able to move to trash?
(About removable media, not the case from the user since it was a bug solved with an update)
This behaviour happens because when the drive is mounted you are not considered the owner so a trash bin cannot be created. No uid or gid was assigned and since a trash bin folder cannot be created in the drive you are only offered the choice to delete the files automatically.
In that case you have 2 options: cut the files in to your Linux file system and delete them there (which defeats the purpose of press delete and the files are deleted) or make sure you are assigned the correct permissions when mounting the drive.
Create a new rule for your auto-mounted drives with these lines, use your favorite text editor for that
gksudo gedit /etc/udev/rules.d/10-my-media-automount.rules
# vim:enc=utf-8:nu:ai:si:et:ts=4:sw=4:ft=udevrules:
#
# /etc/udev/rules.d/10-my-media-automount.rules
# start at sdb to ignore the system hard drive
KERNEL!="sd[b-z]*", GOTO="my_media_automount_end"
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="my_media_automount_end"
# import some useful filesystem info as variables
IMPORT{program}="/sbin/blkid -o udev -p %N"
# get the label if present, otherwise assign one based on device/partition
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"
# create the dir in /media and symlink it to /mnt
ACTION=="add", RUN+="/bin/mkdir -p '/media/%E{dir_name}'"
# global mount options
ACTION=="add", ENV{mount_options}="relatime"
# filesystem-specific mount options (777/666 dir/file perms for ntfs/vfat)
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},gid=46,dmask=000,fmask=111,utf8"
# automount ntfs filesystems using ntfs-3g driver
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", RUN+="/bin/mount -t ntfs-3g -o %E{mount_options} /dev/%k '/media/%E{dir_name}'"
# automount all other filesystems
ACTION=="add", ENV{ID_FS_TYPE}!="ntfs", RUN+="/bin/mount -t auto -o %E{mount_options} /dev/%k '/media/%E{dir_name}'"
# clean up after device removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/media/%E{dir_name}'", RUN+="/bin/rmdir '/media/%E{dir_name}'"
# exit
LABEL="my_media_automount_end"
Reboot your computer and your ntfs drives will be mounted using this custom rule, to change the permissions for the mounted drive have a look at the line $env{mount_options},gid=46,dmask=000,fmask=111,utf8"
, the option gid=46
should mount the ntfs drive with group privileges (46(plugdev)
is the group that allows a user to mount a drive in Ubuntu), fmask
and dmask
settings to write, create, delete files/folders on the drive.
Change it according to needs. You will need to sort out other file systems by yourself according to to each type but this should get your started.
(Source for the udev
rule)
For cases where the user can not delete a file stored in a non-removable partition (Ubuntu 14.04)
As Bruno Pereira stated, this behaviour happens because the user does not have write permissions at the mount point of the partition (in the OP case, /var), so a directory for the trash bin can not be created.
In this case, the OP can not move to trash files stored at the /var partition. To solve this issue:
$ cd /var
$ sudo mkdir .Trash-1000
$ chown user:group .Trash-1000
You will have to replace:
-
1000
by your user identifier (see the number following your login name at the file /etc/passwd) -
user:group
by your login name and group, respectively
On 16.04, I ran into the same problem. The solution was opening Disks, clicking on the NTFS partition -> on the little gears icon underneath (Additional partition options)-> "Edit Mount Options" and adding "uid=1000" (no quotes, separated with a comma) to the line above the Mount Point (see picture).
uid should be set to an alternative number from 1000 as returned by the "id" command from the terminal if you are not the original user, as mentioned here.