On windows I have a program that can count all the files on a hard drive and the output shows a list of file extensions and a number (which showed how many files on the drive were for example are jpg).
How do I do this in a terminal on gnu+linux?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
The unix philosophy is to provide the building blocks, and let you assemble those building blocks to perform specialized tasks such as this one.
find command traverses a directory tree and lists files matching certain criteria or acts on them. For example,
find -xdev / traverses all files on the root filesystem and displays their name. The option
-xdev omits files on other filesystems, such as network mounts, special filesystems that provide system information, etc.
Linux file names can contain any byte except slashes (which are directory separators) and null bytes. If you're willing to assume that your file names don't contain newline characters, the processing of file names will be simpler. For safety, you can exclude file names that contain a newline.
find / -xdev ! -name $'*\n*' -printf '%f\n'
To select files that have an extension, we'll match a name containing a dot that isn't the first character, and only regular files (you may or may not want to include symbolic links as well).
find / -xdev -name '?*.*' ! -name $'*\n*' -type f -printf '%f\n'
find. To work on the extensions, we'll use text processing tools, using a shell pipeline to combine them. First sed to do a bit of rewriting to eliminate the part of the file name that isn't the extension:
find / -xdev -name '?*.*' ! -name $'*\n*' -type f -printf '%f\n' | sed 's/.*\.//'
find / -xdev -name '?*.*' ! -name $'*\n*' -type f -printf '%f\n' | sed 's/.*\.//' | sort | uniq -c | sort -n