14

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?

enter image description here

  • can you provide the full(absolute)path of the file – aneeshep Nov 3 '11 at 16:32
  • In this case is /var/www. Am already the owner of it and permissions are good. But there is also external units like hard drives and pen drive that have the same issue. – Luis Alvarado Nov 3 '11 at 17:21
10
+50

(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)

  • Does this also works for me? I have a slight different environment: Using Linux only, and I have NFS mounted home where deleting is working quite well and there also exists a trash, but I have symlinked a directory repos to local filesystem /local/home/me/repos (its faster). Only inside this directory and subdirectories deleting does not work. Directories /local/home are owned by root 755, but my directories /local/home/me/repos are owned by me with modalities 700. – math Jan 9 '12 at 9:57
  • Question: Can the values of this line: $env{mount_options},gid=46,dmask=000,fmask=111,utf8" also be written inside the <options> column of fstab? Is that the same thing? – Nearoo Oct 24 '16 at 16:38
6

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
2

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).Modifying fstab mount options through the Disk utility

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.

0

I used to have this problem when I added a line in /etc/fstab for mounting a ntfs partition. It was not present if I mounted the partition "manually" in nautilus.

The Ubuntu documentation explains that you should mount disks using udisks, which is what nautilus uses.

Summary of the steps for automatically mounting a partition:

  1. Prerequisite: mount the partition and find its name (for example /dev/sdb1) using the mount command.

  2. Get the uuid of the partition. The uuid appears before the -> in this command:

    ls -al /dev/disk/by-uuid/

  3. The command for mounting will be:

    /usr/bin/udisks --mount /dev/disk/by-uuid/<the uuid you found previously>

  4. Add this command in your startup applications

  • 1
    This is not let you execute files in the ntfs partition – Anwar May 20 '12 at 10:38
-1

For those who like GUIs, here's how to solve this graphically:

  1. Open up the nemo file editor (sudo apt-get install nemo to install) with elevated privileges, by typing sudo nemo into a terminal. [This will probably work in nautilus too, but I've only tested in nemo].
  2. Right-click the mounted device where your files are stored, and go to "Properties."
  3. Go to the "Permissions" tab, and for "Owner," click the drop-down menu and select your username. Close everything and go back to your normal file manager.
  4. With you set as the owner of the device, it should now create a trash for you on that device and allow you to press the delete button to automatically move files to the trash.
  • Running a GUI program with sudo is generally not a good idea; Many things can go wrong - like, for example when running nemo the first time, it will write it's config files and create directories it needs. These will be owned by root, and not writable by the user. And it will take some time until the problem gets noticed - the sudo command may long be forgotten. For example, I think nemo creates the directory ~user/.local/share/nemo/scripts/ on first run. – Volker Siegel Apr 24 '17 at 18:13
  • Interesting.... – Gabriel Staples Apr 24 '17 at 22:18

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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