8

I am using zsh, macOS 11.0.1 (Big Sur), was working on a project and for some stupid reason I decided to write touch ... A file was created in the Desktop so I don't think that it will affect the computer's performance in any way.

I tried doing vim .. and a document was opened.

It contains so many things it is not the one that I just created, also on the top I read /Users/Serax instead of /Users/Serax/Desktop.

I don't want to damage or delete something that i should not. I tried using mv .. my_stupid_mistake.txt but it didn't work.

I also checked Desktop in the finder but found nothing.

Is it safe to do rm ..?

2
  • 11
    "The file was created in the Desktop" - as in, you're looking at your desktop in the GUI and you can see an icon for a file labeled ..? Can you post a screenshot? touch .. should not have had that effect. Commented Dec 2, 2020 at 5:17
  • I second @user2357112's request. FWIW, I just did cd ~/Desktop and touch .. on my Mac, and all it did was update the last modification timestamp of my home directory (as it should). Commented Dec 2, 2020 at 20:56

5 Answers 5

9

touch just creates a new empty file if a previously extant file is not specified. If specified it will update the last modified date.

As you created it on your desktop, I'm sure it would be simplest to just grab it and drag it to the trash… saves making any further errors ;)
It will cause no issues at all.

rm has consequences for the unwary that a simple drag & drop doesn't.

  • . means the current directory
  • .. means the directory above the current location

If you're not sure where you are, rm .. could be somewhat chaotic, as it will delete (potentially all) files from the next directory up.

11
  • 8
    All implementations of rm I've seen so far are not recursive by default so I don't think rm .. would be disastrous, it should just throw an error. You can test this by making a folder and attempting to deleting it with rm.
    – nulldev
    Commented Dec 2, 2020 at 5:22
  • 3
    Where in the filesystem hierarchy does .. not already exist? It sounds like you think touch .. created a new file filled with directory entries, which is of course incorrect.
    – pipe
    Commented Dec 2, 2020 at 5:23
  • 5
    @Tetsujin "As you created it on your desktop" gives the impression you think something was created, rather than the time/date of the parent directory being updated.
    – TripeHound
    Commented Dec 2, 2020 at 9:30
  • 2
    RE: "If you're not sure where you are, rm .. could be somewhat chaotic, as it will delete (potentially all) files from the next directory up." -- .. cannot be removed by rm and even if using sudo and the -rf options with rm it will simply error with rm: "." and ".." may not be removed, so there is nothing chaotic, nor is there any danger, potential or otherwise, in running rm ... Commented Dec 2, 2020 at 14:34
  • 2
    @KevinKeane, aliasing it to rm -i is one thing (it just teaches people the bad habit of using -f every time...), aliasing it to rm -r would be another thing entirely
    – ilkkachu
    Commented Dec 2, 2020 at 20:55
21

Do not delete it! In unixish filesystems (including macOS), .. is a link to the parent directory. So if you were in the directory /Users/Serax/Desktop and you ran touch .., that's equivalent to touch /Users/Serax, which just marks your home directory as being modified.

Similarly, when you're in /Users/Serax/Desktop, trying to delete .. is equivalent to trying to delete your home directory. If you succeeded, you'd lose all your files. You do not want to do this.

Running that touch command will not have damaged anything, so there's nothing that needs to be fixed, deleted, or cleaned up. Just go about your business.

BTW, do you have a good backup? If not, I'd strongly recommend you make one. Because accidents happen, and sometimes you delete your entire home directory by mistake.

3
  • Reading what a command does before using it does tend to reduce accidents...
    – Solar Mike
    Commented Dec 1, 2020 at 19:21
  • 6
    I agree that it is important to be cautious about this, but in this special case, OP was aware of the issue (hence the question here). I would think this is not a case for panic, though, since rm (even with the -rf switches) protects against deleting ..: $ rm -f .. rm: "." and ".." may not be removed
    – jstarek
    Commented Dec 2, 2020 at 10:14
  • @jstarek True, but OP was looking for alternate methods, so there's a danger they might have found a way to do something to .., and it probably wouldn't have been good. Commented Dec 2, 2020 at 16:48
15

touch .. didn't create a file. That is impossible on macOS because the name .. is already taken and refers to the parent directory.

So, you have not created a new file, and you don't need to delete anything.

Your touch .. actually only edited some of the metadata associated with the parent directory (sounds like that's the Desktop directory itself in your case):

It updated the

  • last change time
  • last modified time
  • last accessed time

To the time that it was when you ran touch ... You should be able to see these changes by running stat -x ...


Sometimes Finder may show files called .., for example perhaps like this:

enter image description here

However, this file is not truly named .., it's just that Finder is hiding its extension.

Open Finder > Preferences... > Advanced, and enable the "Show all file extensions" checkbox to see what its name truly is (for example, it may be ...png)

5

Don't run rm ..!!!

I just did the exact same thing and it didn't actually create a file. If you run vim .. you will get a list of folders as the computer recognizes .. as previous directory.

Check in Finder and you should see there is no .. file. If there is a file, try opening it in TextEdit with Finder rather than terminal and if it's empty, you are safe to delete it.

But, again, DO NOT RUN rm ..!!!

2
  • 12
    Why? rm .. is guaranteed to fail. Doesn't seem like a cause for all caps and multiple exclamation marks.
    – hobbs
    Commented Dec 2, 2020 at 9:06
  • 2
    rm ..: rm: "." and ".." may not be removed -- okay, let's try -f: rm -f ..: rm: "." and ".." may not be removed -- okay, it's a directory, so -r: rm -rf ..: rm: "." and ".." may not be removed -- Well, no surprise really, since the man page says "It is an error to attempt to remove the files ''.'' or ''..''." That's with the rm on my Mac. GNU rm gives different error messages, but the result is the same.
    – ilkkachu
    Commented Dec 2, 2020 at 18:38
4

I am writing this because I feel that the currently accepted answer doesn't really explain the user's situation. If you ran touch .., that would not create a new file on your Desktop. That would only be a no-op (no operation) at best and update the modification time of the parent directory at worst. It's completely harmless from the user's perspective and requires no response. The filename .. simply refers to the parent folder/directory of the current location which would be the user's home directory if that was run from the Desktop. touch .. would never create a new file because that name is always in use. If the user did see a new file appear on their Desktop, that is from a completely separate, unrelated event to running touch ...

As for what happened with vim .., Vim will show a directory listing of a folder if you try to open a folder like a text file. What the user is seeing is a complete listing of their home directory and why they see Desktop in the "file" they opened. That's completely normal and should not be a concern. There is no reason to attempt either mv .. my_stupid_mistake.txt (which will fail because you can't move a parent into a child) or rm ... That command will fail:

rm ..
rm: "." and ".." may not be removed

So, in summary, don't worry, you did nothing bad by running touch. That is a relatively harmless command. The worst it usually does is creates an empty file, but in this case, it didn't even do that.

1
  • 1
    Except that rm .. just gives an error, even with -r or -f. It's required by POSIX and described in the man page.
    – ilkkachu
    Commented Dec 2, 2020 at 20:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .