Why do directory listings contain the current (.) and parent (..) directory?

后端 未结 8 1197
面向向阳花
面向向阳花 2020-12-11 03:11

Whenever I list the contents of a directory with a function like readdir, the returned file names also include \".\" and \"..\". I have the suspicion that these are just nor

8条回答
  •  悲&欢浪女
    2020-12-11 03:28

    One reason is that without them there is no way to get to the parent directory. Or get a handle to the current directory.

    Without them, we cannot do such things as:

    ./run_this
    

    Indeed, we couldn't add '.' to the $PATH, meaning we couldn't ever execute files that weren't already in the path.

提交回复
热议问题