Solved Easily - cannot remove "dir": No such file or directory

Previously I had a problem to delete a directory which was unable to be deleted, and I tried many workarounds to sort the problems out but It did not work.

The original link was this:
The previous asked question link

I tried many solutions such as:

  • rm -r dir-name
  • rm -Rf dir-name
  • rmdir -p /dir-name/
  • rm -R --force dir-name

But I figured out that I was forgetting sudo to perfectly finish the job.

  • sudo rm -Rf dir-name

Any additional points are highly acceptable!

Ok. This is like posting on a downhill bike forum that you just figured out how to ride a bike.

So… congratulations, but you should know that after first week of linux.

5 Likes
  1. It happened because you didn’t have the proper permissions for it;
  2. directory /run/media/user/usb_name/.Trash-1000
    Anything in /run/* is not persistent and shouldn’t be relied on. It might be back later. Especially after a reboot and something that seems to be created by another OS;
  3. Using sudo to delete something is like using an angle grinder to fish out a stubborn splinter from your finger. Sure, it might work, but heck the chance of amputating your finger, or even your hand is so great, it’s really not worth it;
  4. This might seem over-the-top, but trust me, in the long run it’s worth it, read up on permissions, that will help you not use an angle grinder when all that’s needed is a nail file.

I almost think @Aragorn has something on permissions, if, and only if he wants to chime in.

More information:

https://wiki.archlinux.org/title/File_permissions_and_attributes

1 Like

Linux terminal has a shortcut (!! - bang bang ) to repeat the previous command entered in terminal

So if a user forgets to use sudo they can use

sudo !!

to run the previous command with sudo

3 Likes

Yeah…

:zipper_mouth_face: :zipper_mouth_face: :zipper_mouth_face:

From the thread ttitle:

cannot remove “dir”: No such file or directory

That error message means you tried to remove something called dir which didn’t exist.

So yes it is solved easily, you have 3 options:

  1. Use the correct path
  2. Stop trying to remove the thing you’ve already removed
  3. Don’t try to remove things that don’t exist

Admittedly the 2nd and 3rd options are pretty similar.

1 Like