1

How would I create a file named . (dot) and read or write data to it, given that . also refers to the current directory?

I know this is possible because I have a directory structure. I'm looking at with ls --all -l that shows a file named . owned by a different user than the user that owns the . and .. directories.

8
  • 1
    Not possible, but you can create a file that appears as just "." to ls output. For example: touch ". ". You won't be able to tell the trailing space is there in ls output.
    – jordanm
    Sep 29 '18 at 4:18
  • 1
    Also, I would be very suspicious of a file named ". ", as dir names such as that is often used to hide malicious code.
    – jordanm
    Sep 29 '18 at 4:19
  • i don't want to execute it, just to find what's in it. It seems you are probably right that the file isn't actually named '.' but i can't figure out how to cat it. i basically want to escape the . and say something like .* i guess, but it's not working Sep 29 '18 at 4:20
  • What do you get with printf '%s\n' .* | sed -n l ?
    – ImHere
    Sep 29 '18 at 4:28
  • 3 lines: (.$\n .\\ \\ $\n ..$\n). \n denotes a newline in the output Sep 29 '18 at 4:28
4

I'm afraid it only looks like you have a file called .. What is very likely happening is that you have a file whose name starts with a dot but is then followed by a whitespace or other special character. To demonstrate how you'd figure this out:

$ cd "$(mktemp --directory)"
$ touch '. '
$ for path in .*
> do
>     printf '%s' "$path" | xxd
> done
00000000: 2e                                       .
00000000: 2e20                                     . 
00000000: 2e2e                                     ..

The dotfile (the second entry above) shows up as a dot (0x2e) followed by a space character (0x20).

1
  • Note that %q is not POSIX. Yes, it works in bash, (*)ksh, zsh (with similar but not identical results) but not in older POSIX shells.
    – ImHere
    Sep 29 '18 at 21:30

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.