How do I count all files on my system? [duplicate]
I need to see how many files I have on my whole system. Specifically, I need to count all files from /
(so on the whole system), and I need to get a number at the end. So like there are 10000 files on the whole system.
How can I accomplish this? I hope you can help!
Solution 1:
Use df -i
to see the number of Inodes used -> IUsed
field.
Or limit the output like:
df --output=source,target,iused
Note, that numbers from find
and df -i
won't necessarily match:
-
df -i
also counts directories - files that link to the same inode (hard links) will count only once
- Some special inodes that are not linked to any directory for internal use are not counted.
-
df
will not traverse into mounted directories, e.g./boot
or if you have a separate/home
partition. Withfind
, you can get that behavior using-xdev
flag.
Check this Answer on U&L SE.
I'd expect the result to be slightly less than the df -i count as a few file systems (including ext4) have a few special inodes that are not linked to any directory for internal use.
Solution 2:
You can use find /
to list all the files. When find's output is redirected, it outputs file names containing newlines as spanning multiple lines, so you can't just count the lines. You can output something else for each file and count the characters, though:
sudo find / -type f -printf 1 | wc -c
Without sudo
, you probably can't access all the paths, so you can't count all the files.