Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to count how many files/folders exist on the system?

Even better if i could get the list into a csv file?

share|improve this question
you mean, given a folder, count files inside it? – Juan Sebastian Totero Jun 5 '12 at 15:19
Sorry but I somehow miss the point of this. You are aware that there are virtual file systems like proc and sys are mounted as well? If you want to validate contents of directories use check sums and programs like md5deep. – LiveWireBT Jun 5 '12 at 17:31

The following command will output how many files and folders are present under / on your system.

 echo `find  / . -type d -print 2> /dev/null | wc -l` directories and `find  / . -type f -print 2> /dev/null | wc -l` files are present on this system.
share|improve this answer

I don't know if my idea is the most elegant, but it works:

tree / | tail -1 > output

It will take a while until the tree will finish, but you will get a number of directories and a number of files, in your file "output".

share|improve this answer

Type in a terminal:

cd /    
find -type f | wc -l
share|improve this answer
will this get all paths? So for file /directory/file.filetype it will return /directory as well as /directory/file.filetype? – David Jun 5 '12 at 16:55
ls -Rtl / | grep -v ^$ | wc -l 

This will list all the dirs and files on the system.

The another good way to do this is to use find.

find / -type f | wc -l

What list you want to take into CSV file?

share|improve this answer
I would like to import into a csv file a list of all possible paths on the system. so /directory, as well as /directory/file.filetype – David Jun 5 '12 at 16:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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