I thought I was moving a sub directory up a level so that it would be a sibling of its parent. But it's now completely invisible. Is it gone?

Here's the command I used:

mv parentdir/mydir ../mydir
link|improve this question

feedback

3 Answers

up vote 2 down vote accepted

I figured it out. All I did was change the name so that it started with the .., and that made it hidden to the "ls" command.

link|improve this answer
Ah.... so you accidentally ran "mv parentdir/mydir ..mydir" not "mv parentdir/mydir ../mydir" (no slash after the dots) I'll guess. Good find! Thanks for updating the question. – pbr Nov 25 '09 at 20:24
feedback

If ../mydir already existed, you've moved it into ../mydir/mydir. Otherwise it's at ../mydir.

In a command like this, paths are relative to the current working directory (unless the path starts with /, in which case it's an absolute path). So your command didn't tell mv to make mydir a sibling of parentdir, you told it to make mydir a sibling of the working directory.

What you wanted to do was one of these two:

# make parentdir/mydir to be a sibling of parentdir
$ mv parentdir/mydir ./
$ ls -1
parentdir
mydir

# make parentdir/mydir to be a sibling of parentdir
$ ( cd parentdir ; mv mydir ../ )
$ ls -1
parentdir
mydir
link|improve this answer
feedback

When running a command like cp, scp, mv and the like, where the second argument is a directory, it's safest to end it with a /., so that both you and the command know that you are looking for a directory there. For example, instead of doing this:

$ mv /opt/foo /temp

I would do:

$ mv /opt/foo /temp/.

and get the error message:

mv: cannot move `/opt/foo' to `/temp/.': No such file or directory

because, of course, I meant to type /tmp/.. Had I run the first command I would have silently -- and quite unintentionally -- renamed the directory.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.