3

I accidently left a trailing slash on my directory name when renaming a folder in Linux,

mv /images/images/ ..

Now the folder has vanished, But I know it's still there due to the space it's using, I'm thinking it's renamed to '..' but I cannot seem to rename it back? Anyone know the answer? :)

  • I know that in Unix file terms, .. (dot dot) refers to the parent directory. To see this, run: ls -a I'm not certain what implications this has. – cremefraiche Dec 11 '14 at 13:55
  • What shell are you using? – tachomi Dec 11 '14 at 14:12
  • 1
    What directory you where when you moved the directory and.. was it filled with stuff? – Braiam Dec 11 '14 at 14:13
  • this would have moved images (last directory) up one level. If you were in / (root) . and .. are equivalent, this would have moved images to / – Archemar Dec 11 '14 at 14:15
1

mv /images/images/ .. moves the directory called images from the directory /images into the parent directory of the current directory.

The current directory is whichever directory you were in at the time you ran the mv command. Your directory will not have "disappeared". You just need to work out where you were when you ran the mv command, and from there find the parent.

P.S. mv /images/images .. (without the trailing /) would have done exactly the same thing if /images/images is (or was) a directory. The only difference you would have seen in behaviour by adding a slash would be to force the mv command to fail if /images/images turned out to be a file instead of a directory.

  • Note that if working out of a symlinked directory, the parent will be the parent of the source directory. – user3751385 Feb 7 at 7:21
1

.. denotes the parent directory. Suppose you are in the home/user/TEST folder, where there is the images1/images2 directory. Then you have now a images2 folder in home/user/ and an images1 folder in TEST, without the subdirectory images2:

~$ mkdir TEST
~$ cd TEST
~/TEST$ mkdir -p images1/images2
~/TEST$ touch images1/images2/a_file
~/TEST$ mv images1/images2/ ..
fti@erebe:~/TEST$ ls images1
fti@erebe:~/TEST$ ls ..
images2  TEST
fti@erebe:~/TEST$ ls ../images2/
a_file

I didn't see the first slash in /images/images.
As you were in the root folder (/), and since root folder doesn't have a parent directory, /.. is the same as / so you move /images/images to (/..)/images. In other words, a file in /images/images/foo.txt should now be in /images/foo.txt.

  • I don't have this, in your code your mv images1/images2 .. is what I wanted to do, but i actually put mv images1/images2/ .. (trailing slash) now I can't find the folder – Ricky Odin Matthews Dec 11 '14 at 13:58
  • The trailing slash shouldn't matter. – fredtantini Dec 11 '14 at 14:00
  • Well I'm using Centos 6 and the folder isn't visible since I moved it with trailing slash. I've done ls -a and cannot see in the directory above :( – Ricky Odin Matthews Dec 11 '14 at 14:02
  • try ls -a .. to see the parent directory – fredtantini Dec 11 '14 at 14:03
  • 1
    Let us continue this discussion in chat. – Ricky Odin Matthews Dec 11 '14 at 14:14

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.