8

I'm using Ubuntu 16.04.

Step 1) I logged into my root user account.

Step 2) I used cd to navigate to a different user account's home directory.

Step 3) I typed ls to examine the contents of that directory.

Step 4) The contents came back as empty.

Step 5) I typed mkdir .ssh to create a directory.

Result) mkdir: cannot create directory '.ssh': File exists

Question: Why is the directory listed as empty if an .ssh folder exists inside of it?

-- update --

I logged into root because this is a test server. I'm repeatedly creating and destroying it.

  • use ll or la, not ls – phuclv Nov 30 '17 at 2:51
  • 1
    ll is just an alias, so rather use ls -alF – Dennis Nolte Nov 30 '17 at 11:23
  • 2
    Your process has a major bug in it at step 1. – Lightness Races in Orbit Nov 30 '17 at 12:48
35

ls by itself does not show hidden directories (hidden directories and files are ones that start with a ., such as .ssh)

Try using ls -a in the directory.

From the ls manpage:

-a, --all

do not ignore entries starting with .

As noted in the comments, "hidden" directories and files are not technically a thing, there is just code built into a lot of common tools that treat . and .. with special meaning, the result being that . is usually considered "hidden" by most tools. The reason I used this term is because it's common to hear it referred to that way.

Additionally . and .. usually have special meaning to most filesystems, indicating current directory and parent directory, respectively.

| improve this answer | |
  • 4
    Note that "hidden directories" are not a thing per se, they are hidden because ls has special code to not show them when they start with a dot. – PlasmaHH Nov 29 '17 at 10:19
  • 2
    @PlasmaHH Well, ls and a whole bunch of other tools. But in principle you are absolutely right; then again, even on systems that trace their lineage back to MS-DOS and its file attributes, it requires special code to handle the case of "hidden" files (which there means "files with the hidden attribute set" rather than "files which have named on this particular form"). – user Nov 29 '17 at 12:05
  • 3
    @MichaelKjörling: on a lot of these systems it is however the other way round. There you normally ask the system to "give me everything" and when you want to display hidden files you say "give me everything plus the hidden stuff" or "give me all hidden stuff". So it is doing extra effort to hide files vs. doing extra effort to display hidden files too. – PlasmaHH Nov 29 '17 at 12:10
  • 12
    Fun fact, the invention of hidden files was a bug, ls was only supposed to hide . and .., so they added code to see if it started with a dot – Ferrybig Nov 29 '17 at 12:40
  • 4
    I'm concerned about the "logged in as root" part combined with apparent unfamiliarity with *nixes. It would be very easy for OP to accidentally destroy something important. – shoover Nov 29 '17 at 17:51
4

In your step 3, type ls -a to list the contents of directory.

File or directory whose name starts with . will be ignored by ls.

| improve this answer | |
0

.ssh is a hidden directory, as it starts with a .

To list hidden files and directories, use ls -a instead of just ls.

| improve this answer | |
  • 1
    .ssh is not a file, it's a directory – Ferrybig Nov 29 '17 at 12:41
  • 7
    How is this anything more than the accepted answer given 8 hours ahead, or the other answer given at the same time as the accepted answer? – Colt Nov 29 '17 at 13:18
-2

"." is reserved for hidden folders/files. ls by default will not list the hidden files and directories. ("." and ".." are two default hidden directories in any directory). To view all the files inside a folder, use ls -a or ls -al (if you want more details about each file/folder.

| improve this answer | |
-4

For creating the directory you need to remove the existing directory

Use rm -rf .ssh it will remove the directory

Or if already exist You can use cd .ssh

| improve this answer | |

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