-2

I searched but can't seem to find the answer anywhere...

For example, in a recent Debian distribution I typed the "ls -R > filelist.txt" command and the total output was over a half a million lines in the text file... Is this right? It was not my system and I told the owners of it that it seemed like way too many files, but being a windows guy I wasn't completely sure so I told them I would ask... The Debian version was current.

If someone here could simply pipe out a full file list of their Debian build and let me know how many lines they see please?

Mikev
  • 2,012
  • 1
  • 15
  • 27

1 Answers1

0

While the actual question is offtopic for Stackoverflow I'll answer because computing the number of files is at least a bit related to programming and the way it is done in the question is wrong.

ls -R will list not only files, but also directories (multiple times!) and empty lines.

Example

Given the following file hierachy

.
├── file1
└── subdir
    └── file2

The command ls -R | cat (cat to simulate redirection to a file, which changes the output format) will print

.:
file1
subdir

./subdir:
file2

Alternative Commands

To count the number of files in a system use find -type f -printf . | wc -c.

Output for me

I have a mostly unused Ubuntu 18.04 server. Some tools like gcc, clang, and so on were installed. There is only one user having nearly no personal data (running the find command in his home directory prints 1274).

$ cd /
$ sudo ls -R | wc -l
303414
$ sudo find -type f -printf . | wc -c
203608
Socowi
  • 25,550
  • 3
  • 32
  • 54
  • Yeah, I'm still learning my linux command nuances. So using that command i get : cd / ls bin content dev home lib32 media opt root sbin swift tmp usr boot datalab etc lib lib64 mnt proc run srv sys tools var $ sudo ls -R | wc -l 532317 $ sudo find -type f -printf . | wc -c 392341 Still a bit large- I think I will install another and compare the two to see why so many extra files are there. – Anthony Walker Feb 20 '19 at 22:30