Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Console Foundations Getting Started with the Console Running Commands

How does "ls -l" calculate number of files and directories?

In the video "ls -l" gave us "total 8", but in the output of "ls -a" I saw 10 files and directories, excluding "." and "..".

What is going on?

Do you mean ls -a?

2 Answers

Sue Dough
Sue Dough
35,800 Points

It is because

./ = current dir ../ = back 1 dir

You can see for yourself by running

cd ./ This will do nothing and keep you in the same

cd ../ This will take you back a directory

It is a little easier to understand if you run ll because it will show the slash after the dot(s).

It has nothing to do with the bash files as the previous poster mentioned because same thing will happen even without bash.

Thanks for the answer, Sue. However, your answer doesn't solve my question.

Maybe I should make my question more clear.

Here is the output of ls -a:

.    .bash_history  .bashrc  documents  .profile  .sudo_as_admin_successful
..   .bash_logout   .cache   hello.txt  .ssh      .viminfo

If you include . and .., there are 12 files and directories.

But the output of ls -l showed total 8

Now the question is: which 4 of 12 were not counted in?

Sue Dough
Sue Dough
35,800 Points

You see more with -a because it shows all files including hidden.

-a means all including hidden files starting with a dot. Dot files do not show on default.

ls and ls -l are the same thing. The -l just makes it visually show a long output.

. and .. are what I explained above.

If you want further details then just use man. man is short for manual in linux.

Type in man ls and q when you want to exit.

Thanks, Sue. man helps!

This is what I found:

-l      (The lowercase letter ``ell''.)  List in long format.  (See
        below.)  If the output is to a terminal, a total sum for all the
        file sizes is output on a line before the long listing.

So the answer is that 8 in total 8 is the "total sum for all the files sizes" instead of the number of files and directories.

Thanks for explaining! :)

Here's what I think is causing the Console to say "total 8" (IT MAY NOT BE RIGHT fyi):

There's two directories that is only for the Console (the ones that start with .bash_), and the Console doesn't count those in the total.

Just guessing!

Might be right :)

Good luck! ~alex

Thanks for your help, Alex! I think that might be right.

Sue Dough
Sue Dough
35,800 Points

This shows regardless of bash and is unrelated to bash. Check my answer.

Hi, Alex. I think I found the answer! Check out my latest comment in Sue's post.

Cool! I'm still kinda new to this Console stuff, so it's nice to know more things :)

Sue Dough
Sue Dough
35,800 Points

Yeah sure thing. The console is fun. If you ever want to dive deep into a certain command then use the man page.

by typing

man PROGRAM_NAME_GOES_HERE