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:
- 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.
- 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).
.
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/
is accidentally used as a target ofmv
run withsudo
. In this question, a relative path to a nonexistent file in the current directory was accidentally used a target ofmv
(withoutsudo
). 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