2

I was in user home directory , and wanted to rename the ssh folder into .ssh folder. I tried this.

rachit@DESKTOP-ENS2652:~/ssh$ ls
some-machine  some-machine.pub
rachit@DESKTOP-ENS2652:~/ssh$ cd ..
rachit@DESKTOP-ENS2652:~$ ls
ssh
rachit@DESKTOP-ENS2652:~$ mv -R ssh .ssh
mv: invalid option -- 'R'
Try 'mv --help' for more information.
rachit@DESKTOP-ENS2652:~$ mv ssh .ssh
rachit@DESKTOP-ENS2652:~$ ls
rachit@DESKTOP-ENS2652:~$ ls

After doing this, my ssh folder competely disappeared. Its no big deal I can create another one , but am not able to get my head around what did I do wrong , and why is it wrong. I am trying out things on WSL ( Windows subsystem for linux). Basically ubuntu on windows 10.

3

This

mv ssh .ssh

could move ssh into an (already existing) .ssh directory.

Do this

mv .ssh/ssh ./

to put it back. You would have seen .ssh if you had done

ls -la

If .ssh did not already exist, then

mv .ssh ssh

will make it "appear" when you do just

ls -l
  • Unless .ssh didn't exist before hand, in which case it's now just called .ssh and ls -a will show it. – Stephen Harris Sep 10 '16 at 0:58
  • I suppose so... – Thomas Dickey Sep 10 '16 at 0:58
  • Just while you typed the answer , I googled for search command and found that the files in ssh folder were indeed moved to .ssh/ssh, which means mv ssh .ssh moved the entire ssh folder inside .ssh, Once I put the ssh folder back in place with the command you said , I guess I should do mv ssh/* .ssh to move only contents of ssh into .ssh. ( Please correct me if wrong) – Rpant Sep 10 '16 at 1:09
  • yes - that sounds right. The question seemed to say you wanted to keep a ssh folder in addition to the .ssh folder. It helps to put a trailing / on things that you assume are folders (just in case they are only files...). – Thomas Dickey Sep 10 '16 at 1:12
  • Thanks , the last line really helped. I was just curious about that. – Rpant Sep 10 '16 at 1:26
3

By default files and directories beginning with . are hidden from view. Standard commands like ls and shell globbing such as * will not match them.

For ls you can show dot files with -a (or -A to hide . and ..).

So, for example:

$ ls
$ touch foo
$ touch .bar
$ mkdir .baz
$ ls
foo
$ ls -a     
.  ..  .bar  .baz  foo
$ ls -A     
.bar  .baz  foo

So now when you did mv ssh .ssh one of two things may have happened:

  1. If .ssh didn't exist before then you did exactly what you wanted. You can do ls -a and see it.
  2. If .ssh did already exist then you renamed it to .ssh/ssh.

In both cases you can do ls -a .ssh

In you see the files some-machine and some-machine.pub then you did what you wanted; you were in case 1.

If, instead you see ssh (maybe amongst any files that were there previously) then it means you were in case 2. You can fix this with:

mv .ssh/ssh .
mv ssh/* .ssh/.
rmdir ssh
  • Thanks for such a detailed answer. I already marked the other one as answer.You guys made me feel welcome to the forum. – Rpant Sep 10 '16 at 1:13
  • Also I think the second point in your answer is incorrect. The .ssh folder already existed , however it wasn't renamed. Instead the entire ssh folder was moved inside .ssh folder. Confirmed this by doing ls -a on .ssh and it showed the existing files. – Rpant Sep 10 '16 at 1:17
  • Right, but if you did an ls .ssh then among the existing files you would also have seen an ssh directory. It would have moved the ssh directory inside .ssh but not deleted any previous files. I edited the answer to hopefully make that clearer. – Stephen Harris Sep 10 '16 at 1:18
  • Yeah .. thats what happened. Thanks. Now after undoing with the first command , I guess I can also do mv ssh/* .ssh or mv ssh/* .ssh/. ( Figured this from the comment in other question ). Now what would be the difference between mv ssh/* .ssh/ and mv ssh/* .ssh/. (Mentioned in your answer) – Rpant Sep 10 '16 at 1:24
  • There's not really any difference, in this case, between mv ssh/* .ssh/ and mv ssh/* .ssh/. - they both refer to the same directory. The . entry in a directory means "this directory". Both mv commands are ways of ensuring .ssh is a directory and not a file. – Stephen Harris Sep 10 '16 at 1:30

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.