1

In my mac Mojave machine, when I tried to delete a file, it shows the error

The directory is not empty.

But when I check, there were no files in that directory. When I did an ls -la, it shows

total 0

drwxrwxrwx 330 root wheel 10560 Nov 23 20:35 .

drwxr-xr-x 3 root wheel 96 Nov 24 07:19 ..

I am not able to delete this using commands rmdir, rm -rf, etc. I tried all these with sudo only.

How can I remove these files?

Community
  • 1
  • 1
Arun
  • 3,640
  • 7
  • 44
  • 87
  • What worked for me was `CMD + SHIFT + .` to show hidden files and then simply delete the . / the folder inside of it – Ryul Oct 22 '20 at 10:25
  • `.` and `..` do not block a directory from being deleted, as they don't really exist at all. It sounds like Ryul above is discussing something with a space in the name after the dot, which is a different matter entirely. – Charles Duffy Oct 17 '22 at 15:24

1 Answers1

5

You cannot delete the . and .. they are just symbols.

. represents the directory you are in and .. represents the parent directory.

From the dot definition:

This is a short string (i.e., sequence of characters) that is added to the end of the base name (i.e., the main part of the name) of a file or directory in order to indicate the type of file or directory.

On Unix-like operating systems every directory contains, as a minimum, an object represented by a single dot and another represented by two successive dots. The former refers to the directory itself and the latter refers to its parent directory (i.e., the directory that contains it). These items are automatically created in every directory, as can be seen by using the ls command with its -a option (which instructs it to show all of its contents, including hidden items).

original SO post

madlymad
  • 6,367
  • 6
  • 37
  • 68
  • This isn't an adequate answer. Most other commands allow you to use `.` and `..`, such as `cd`. It wouldn't make sense to say "you can't cd to `.` and `..`; they are just symbols." Normally, the `.` and `..` get automatically expanded to the current directory and the parent directory. Why doesn't this work for the `rm` command? – Peter Schorn May 13 '21 at 19:36
  • @PeterSchorn if you want to get into details you can check this https://unix.stackexchange.com/a/90075/457789 – madlymad May 13 '21 at 20:11