Im having trouble figuring out that, if I'm in let say the directory /home/test/test2 but I want to find the number of files in the /home directory, how would I do it.

I know how to do it if it was the other way around, like in your home directory, list files in /home/test/test2, you would do:

ls /home/test/test2 | wc -l

but how would I do it if I was in the test2 directory and wanted to find the number of files in the home directory.


  • (1) Why does your question title say “List” when you seem to be asking about counting?  (2) Do you mean your home directory, or do you mean the /home directory?  (Or is /home your home directory??)  (3) Do you know how to refer to your home directory on the command line?  (Hint: "$HOME" is one way, typing it out (e.g., /home/shawn) is another, and there’s an even better way.)  (4) If you’re asking about /home, why don’t you think ls /home | wc -l will work?  If you’re asking about your home directory, can you figure it out from what I’ve just said? Feb 13, 2016 at 7:49

2 Answers 2


From any where If you want to find how many files in your home directory

This is the command

ls -la ~/ | wc -l


virt01@virt01:~/test$ ls -la ~/ | wc -l

There ~/ is pointing to current login users Home directory

  • how about other files then my home directory. Like what if im in /home/test/test2 but want to find out how many files are in /home/example/example2 Feb 13, 2016 at 7:15
  • You can use ~/example/example2
    – Raja G
    Feb 13, 2016 at 7:19
  • No , ~/ is home directory and example is another directory and example2 is another one inside of example
    – Raja G
    Feb 13, 2016 at 7:21
  • @Sukminder stop arguing mate virt01@virt01:~/test$ ls ~/ chef-repo jboss-5.1.0.GA jbossatwork-1.0.2 jdk1.8.0_65 New directory Python_Admin some.txt test test1 text.txt typescript virt01@virt01:~/test$
    – Raja G
    Feb 13, 2016 at 7:24
  • /home is the parent directory for all users, or homes. /home/test is home or ~ for user test. /home/example is home or ~ for user example.
    – Runium
    Feb 13, 2016 at 7:54

Also you can use .. to point to the the directory behind your current.


User@~/test/test2:$ ls ../ | wc -l # here you'll list the 'test' directory content

User@~/test/test2:$ ls ../../ | wc -l # here you'll list the 'home' directory content 

Each .. will jump to one dir behind


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