0

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.

Thanks

  • (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? – Scott - Слава Україні Feb 13 '16 at 07:49

2 Answers2

0

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

This is the command

ls -la ~/ | wc -l

Example:

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

There ~/ is pointing to current login users Home directory

Raja G
  • 5,937
  • 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 – shawn edward Feb 13 '16 at 07:15
  • You can use ~/example/example2 – Raja G Feb 13 '16 at 07:19
  • No , ~/ is home directory and example is another directory and example2 is another one inside of example – Raja G Feb 13 '16 at 07: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 '16 at 07: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 '16 at 07:54
0

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

E.g.

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

karel
  • 2,030
tachomi
  • 7,592