Does `du /` list every single file on a system?

by tjt263   Last Updated April 16, 2018 07:01 AM

Does du / list every single file?
||
Is there a better way?



Answers 1


Does du / list every single file?

From man du:

Summarize disk usage of each FILE, recursively for directories.

I do interpret that as: yes, du / lists every single file under /. There may be some pitfalls I don't know though.

This will list files if they are given as arguments. Because / is a directory, du / lists directories; files are taken into account while calculating sizes of their respective directories; in this case they are not listed.


find is a standard tool to list files. To list every single file invoke:

sudo find / -type f

where -type f tells the tool to list regular files only. This way you get your output without the sizes (compared to du output); it's a good thing if you want only to list the files.


In general case find is useful because you can specify several criteria to it (the following list is non-exhaustive):

  • should the results include regular files, directories, named pipes,… (-type option);
  • by ctime, atime, mtime;
  • by owner;
  • by permissions;
  • by size.

I guess you need to have a list of files in order to do something with it. You can use paths provided by find in a pipe, specify its output (-fprint option) or execute command for every file found (-exec). There are also options (like -print0) designed to avoid problems with some troublesome characters in filenames.

Refer to man find for more information.

Kamil Maciorowski
Kamil Maciorowski
August 16, 2016 05:34 AM

Related Questions


Bash - No such file, yet the file exists

Updated October 06, 2015 12:00 PM

Debian : -bash: ls: command not found

Updated June 10, 2016 08:00 AM