3

I had a file in which I had some credentials; and for some reason, it's hidden now. I can see on my desktop that there are two folders with . and .. name. Where did they come from? My file was sample.txt. I messed up with the mv command, and the file became hidden. Now, I'm trying to figure out where my file is.

I need some help!

Edit: These are the commands I used:

1861  mv sample.txt Downloads
1872  find sample.txt
1887  mv .. sample.txt
1888  mv ... sample.txt
Ravexina
  • 55,668
  • 25
  • 164
  • 183
metalhead
  • 184
  • 3
    I've no idea where your file is, but does this answer your question? What do "." and ".." mean when in a folder? – mikewhatever Jun 20 '20 at 17:33
  • 1
    . refers to current directory and .. refers to the parent directory. There's nothing like hidden file in Ubuntu. Hidden files just have their name starting with ., for example, .sample. Did you run any command to move the file? – Kulfy Jun 20 '20 at 17:33
  • 1
    If you press the up arrow in Terminal it will show your command history. Can you try that and find the exact command(s) you ran before the file disappeared, and edit them in to the question please? This will reveal the file paths you used. – Tom Brossman Jun 20 '20 at 17:42
  • I have edited my question with the commands that I used. @TomBrossman – metalhead Jun 20 '20 at 18:01
  • This question is not Duplicate... I edited the title and it's obviously clear that it's not a duplicate. – Ravexina Jun 22 '20 at 07:20
  • 1
    Very closely related: File disappeared on move That's the (apparently quite common) case where an absolute path to a nonexistent file in / is accidentally used as a target of mv run with sudo. In this question, a relative path to a nonexistent file in the current directory was accidentally used a target of mv (without sudo). That affects how answers are worded, but the principle is the same. The other differences are even more minor. This might be considered a duplicate of that. – Eliah Kagan Jun 22 '20 at 12:07

1 Answers1

5

The issue here is that the behavior of commands like mv source target, when target does not end with a /, depends on whether there is an existing directory (or an existing symbolic link that points to a directory) called target. Sometimes that makes them do a different thing than what you expect.

You showed four commands. The first command is the important one:

mv sample.txt Downloads

That command moved or renamed sample.txt.

If there was nothing called sample.txt in the current directory in the first place, then mv sample.txt Downloads failed and no change was made. But based on your description, it sounds like there was such a file. So:

  1. If there was a directory called Downloads in the current directory, then mv sample.txt Downloads tried to move sample.txt into the directory called Downloads, and probably succeeded. This also happens if Downloads is a symbolic link to a directory rather than an actual directory.
  2. If there was no directory called Downloads in the current directory, then mv sample.txt Downloads tried to rename sample.txt to be called Downloads. (Not Downloads.txt, just Downloads.)

If this was in a Desktop directory, the second scenario is probably what occurred, since you probably don't have a Downloads directory in a Desktop directory. But if you do, you're in the first scenario.

So you should look inside the directory you were in when you ran mv sample.txt Downloads for an entry called Downloads. Depending on what existed before, this should either be the file formerly known as sample.txt, or it should contain sample.txt.


As for the other three commands you showed, they should've made no changes at all, and they also should not be expected to have revealed any useful information about the effect of the first command.

find sample.txt won't show anything unless there's something called sample.txt residing directly in the current directory. If you want to find files contained anywhere, directly or indirectly, in the current directory, whose names are sample.txt, you would use find . -name sample.txt. (Of course, that won't find a file whose name is no longer sample.txt.)

In mv .. sample.txt, .. is a name for the parent directory, which is the directory that the current directory resides in, or if the current directory is /, then the parent directory is / itself. Every directory has a .. entry with this meaning. That command tries to rename the .. entry for the parent directory to be called sample.txt. This should simply fail with an error, which in this case will somewhat confusingly be reported as "Device or resource busy".

In mv ... sample.txt, ... is not treated specially. Directories always contain the special entries . and .., but the name ... is not special. So you probably didn't have a file called ....

  • Assuming you didn't, that command failed and made no changes.
  • If you did have a file called ... in the current directory, and no directory called sample.txt (and no symbolic link called sample.txt that points to a directory), then ... would be renamed to sample.txt. If sample.txt already existed and was neither a directory nor a symbolic link to a directory, it would be replaced and (unless there are other hard links to it) it could be difficult or impossible to recover depending on how much the filesystem has subsequently been written. However, this is unlikely, since you probably never had a file called ..., and since that command was run after a command that probably succeeded either at renaming sample.txt in place or putting it somewhere else, and since you don't currently see a file called sample.txt in the directory where you ran the commands.
  • In the unlikely event that you had both an entry in the current directory called ... and another entry sample.txt that was a directory or a symbolic link to a directory, mv ... sample.txt would try to move ... into the sample.txt directory (or into the directory targeted by the symbolic link).
Eliah Kagan
  • 117,780
  • 1
    Woah! I just didn't notice that my sample.txt was renamed to Downloads on my Desktop. Thanks for the useful info. I'll keep all this in mind the next time I try to move files to another directory. – metalhead Jun 21 '20 at 05:38
  • Nice answer... :) – Ravexina Jun 21 '20 at 16:16