Announcement

Collapse
No announcement yet.

Unable to delete files in Ubuntu

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to delete files in Ubuntu

    I've spent hours trying to delete a folder. I can view it (and it's files) in Nautilus and Terminal, but if I try to delete it get "permission denied". The files list using ls, but any operations in Terminal either return no such file or directory, or permission denied even using sudo. I'm stuck - what's the way round this?

  • #2
    Sounds like you are becoming a more advanced user, and there are tools for file manipulation.
    I use teminal and MC or midnight commander.
    Midnight commander has been around as long as there has been unix commands.
    It is a great tool.
    I use it a lot.

    First I don't use sudo persay, I log in as root.
    You can get to root by doing using sudo, or by assigning a root password. (more on root passwd, another day)

    Here is the sudo way
    terry@Ubu3:~$ sudo su
    [sudo] password for terry:
    root@Ubu3:/home/terry# apt install mc
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    mc is already the newest version (3:4.8.27-1).
    0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.

    Once mc is installed, log in to midnight commander mc
    root@Ubu3:/home/terry# mc
    it will look like this


    Click image for larger version  Name:	Screenshot from 2022-06-06 12-39-14.png Views:	0 Size:	100.1 KB ID:	961762

    From mc, you navigate to the folder and delete with the delete button at the bottom.
    There are few safety's, so be careful what you delete.
    If you will give the folder name and location, I will add it and delete it, as an example?


    Here are some tutorials, for midnight commander.

    https://www.youtube.com/watch?v=7qiIa-iuKfM
    https://www.youtube.com/watch?v=rddUniuHuWM

    GL,
    T
    Last edited by big_teee; 06-07-2022, 04:04 AM.
    "If Hitler invaded Hell, I would make at least a favourable reference of the Devil in the House of Commons." Winston Churchill
    Terry

    Comment


    • #3
      MC can't see any of the files - I think it's because they're on an SMB share (remotely mounted SSD). I moved the USB SSD onto my local machine and ran MC as SU and deleted the files and directory structure. that looked to work fine, but when I remounted the drive remotely the files were back. The files are in .Trash-1000. I moved the drive back locally, renamed .Trash-1000 to get it out of the way and created a new, empty .Trash-1000. I then deleted the renamed one and emptied the trash can to permanently delete the files. As a test I deleted a random file and it appeared in the newly-created folder, then I emptied the trash and there were no more files in there. As soon as I remounted the drive remotely the old files were back, so there's something going on at a deeper level as when connected locally there's no trace of these.

      I've tried deleting the files off the inode number, but this doesn't work - as SU I get 'permission denied'.

      I'm wondering if the drive is corrupt at a more fundamental level - would e2fsk fix this, or am i best copying off the wanted files and re-formatting?

      Comment


      • #4
        I'm not familiar with e2fsk?
        You can use MC to set the permissions and who the owner of the file and folder are.
        From file, select chmod to change to 40777, from chown change from user to root.
        Or a variation of 777, that determines who can read, write, and execute.
        Owner, group or others.
        to format a remote drive, like a usb drive.
        I use command line,
        # lsblk
        that shows what drives are mounted.
        to unmount I use
        # umount /dev/sdxx
        to format the usb drive I use
        #mkfs.ext4 /dev/sdxx
        Be careful what you write to.
        I use gparted to partition a drive.
        GL,
        T

        Click image for larger version  Name:	Screenshot from 2022-06-07 10-20-13.png Views:	0 Size:	110.2 KB ID:	961817

        Click image for larger version  Name:	Screenshot from 2022-06-07 10-19-17.png Views:	0 Size:	119.1 KB ID:	961818

        Click image for larger version  Name:	Screenshot from 2022-06-07 10-37-05.png Views:	0 Size:	109.8 KB ID:	961820
        Last edited by big_teee; 06-07-2022, 04:29 PM.
        "If Hitler invaded Hell, I would make at least a favourable reference of the Devil in the House of Commons." Winston Churchill
        Terry

        Comment


        • #5
          Thanks. All attempts to execute chmod and chown result in 'permission denied' or 'unable to' errors. I'm logged in as SU, and it's the same message in terminal. I've just backed up the SSD to my main machine and there's a discrepancy in the number of files between the two (the backup has 51 fewer files, but no errors) and I'm wondering if the SSD is somehow corrupt. I'm thinking at this stage of formatting the SSD and copying back everything except the problem folder to see if that fixes the problem.

          Comment


          • #6
            Originally posted by Mick Bailey View Post
            Thanks. All attempts to execute chmod and chown result in 'permission denied' or 'unable to' errors. I'm logged in as SU, and it's the same message in terminal. I've just backed up the SSD to my main machine and there's a discrepancy in the number of files between the two (the backup has 51 fewer files, but no errors) and I'm wondering if the SSD is somehow corrupt. I'm thinking at this stage of formatting the SSD and copying back everything except the problem folder to see if that fixes the problem.
            To chmod or chown, you have to be root.
            If you have a $ you are user, if you have a # you are root.
            as root, in command line or root mc you should be able to assign privileges to any file or folder.
            To see permissions you can use mc or use terminal ls -l
            In my Screenshot I had made a directory Testing
            I made files using the touch command, break and break.txt
            I also deleted a file
            See screenshot.

            Click image for larger version  Name:	Screenshot from 2022-06-07 13-54-40.png Views:	0 Size:	109.7 KB ID:	961844
            Last edited by big_teee; 06-08-2022, 04:24 AM.
            "If Hitler invaded Hell, I would make at least a favourable reference of the Devil in the House of Commons." Winston Churchill
            Terry

            Comment


            • #7
              I was in root (#). With the drive mounted locally via USB I've established that I can use chown/chmod. Permission is denied when the drive is mounted remotely as an SMB share, hanging off my wifi router. The drive was originally formatted locally. I did some checks and found that I'm denied permission (as root) to change any permissions or ownership on any file. Maybe the router has a layer of security; if I copy a file to my local machine I have full control over it, If I change the permissions and copy it back I lose control and permission is denied again, though the changes made locally are retained.in the copied file. I can work with that - I only read or write files to the drive, but the problem with a folder persistently getting recreated is puzzling. I read that tracker can do this and after deleting a file that tracker can be forced to reindex and prevent the file from being recreated. When I ran the command I got a warning saying that data loss could result, so didn't go further.

              Anyhow, I've just reformatted the drive and copied everything back except the offending folder and this has worked - the folder hasn't been recreated after remounting the drive off my router. Root still doesn't have control over the file permissions, though. I need to research this to find out what the difference is.


              EDIT: I've been researching my router and the local USB drive uses SMB1. Could that be related to the permissions?
              Last edited by Mick Bailey; 06-08-2022, 10:24 AM.

              Comment


              • #8
                When you get remote, and away from my laptop, that is beyond my scope, and I'm pretty lost?
                If you log into your router with an ip address, maybe there are some permissions there, you can set.
                You can put in a problem at Ubuntu forum.
                https://ubuntu.com/support/community-support
                They may be able to help you.
                Also if the wifi router has a help line.
                Maybe they can help.
                If anyone else has any insight, please jump in?

                Hopefully I helped a little?
                GL,
                Terry
                "If Hitler invaded Hell, I would make at least a favourable reference of the Devil in the House of Commons." Winston Churchill
                Terry

                Comment


                • #9
                  Do you use clamtk free AV?
                  If you suspect any hacking or malware, I would install it.
                  # apt install clamtk
                  It sets up a gui that looks like this.

                  Click image for larger version

Name:	Screenshot from 2022-06-08 10-44-46.png
Views:	40
Size:	44.8 KB
ID:	961895
                  You have to update it, and set the options before you run it, but it runs great.
                  It is passive and stays out of the way until you need it.
                  T
                  "If Hitler invaded Hell, I would make at least a favourable reference of the Devil in the House of Commons." Winston Churchill
                  Terry

                  Comment


                  • #10
                    Thanks for the advice, I'll install this - currently I have no AV installed. The router is a BT Smarthub 2 (only 18 months old) and I've just found the only supported protocol is the redundant SMB1. No manufacturer support of any value, just occasional updates. The router is widely criticised for the insecure connection, though it appears to be 'inside' the network. I can't say whether this makes it any less vulnerable from some kind of tunnelling, but I would prefer to move it over to SMB2 or 3. I checked and there are no configuration options for the USB port. At this stage my thought is to mount the drive via my Raspberry Pi - this supports SMB1, 2 and 3. The transfer speed is also faster as it uses USB3 (the router is USB2 and is painfully slow accessing the SSD) and it has an Ethernet connection to the router. I liked how it worked via the router USB port as it's always on (the Raspberry is usually off - only switched on with the TV it services). I'll do some further research and report back.

                    EDIT: I posted on the Ubuntu forum and got this reply;

                    "SMB doesn't know anything about root or Unix permissions. Typically, the root account (or sudo accounts running with elevated privileges) have that account converted to 'nobody' as a security feature.
                    SMB doesn't support chmod or chown. The user account and group accounts are set by the share configuration. NTFS, exFAT, FAT32 don't support chmod or chown either.
                    Sorta off-topic, but it is extremely common for routers that have USB storage features to be hacked. Probably not a good idea. Don't use sudo with GUI tools. That's a general recommendation. There are plenty of bad repercussions that we've seen over the years when people do it.
                    If you want chown and chmod to work, use Unix/Linus file systems and either local or NFS storage mounts."
                    Last edited by Mick Bailey; 06-09-2022, 08:36 AM.

                    Comment

                    Working...
                    X