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 trialBrody Chen
11,252 PointsHow 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?
2 Answers
Sue Dough
35,800 PointsIt 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.
Brody Chen
11,252 PointsThanks 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
35,800 PointsYou 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.
Brody Chen
11,252 PointsThanks, 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.
Sue Dough
35,800 PointsI see what you are asking now. It is a bit confusing. Check this. https://stackoverflow.com/questions/7401704/what-is-that-total-in-the-very-first-line-after-ls-l
Alexander Davison
65,469 PointsThanks for explaining! :)
Alexander Davison
65,469 PointsHere'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
Brody Chen
11,252 PointsThanks for your help, Alex! I think that might be right.
Sue Dough
35,800 PointsThis shows regardless of bash and is unrelated to bash. Check my answer.
Brody Chen
11,252 PointsHi, Alex. I think I found the answer! Check out my latest comment in Sue's post.
Alexander Davison
65,469 PointsCool! I'm still kinda new to this Console stuff, so it's nice to know more things :)
Sue Dough
35,800 PointsYeah 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
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsDo you mean
ls -a
?