Quantcast
Channel: How can I count files with a particular extension, and the directories they are in? - Ask Ubuntu
Browsing latest articles
Browse All 9 View Live
↧

Answer by user3424127 for How can I count files with a particular extension,...

I see one solution posted using os.walk which has some limitations.It doesn't work well with large directories (bug-report) and it's difficult to use in-line.glob might be a better fit here.This inline...

View Article


Answer by Hynek -Pichi- Vychodil for How can I count files with a particular...

Simple Perl one liner:perl -MFile::Find=find -le'find(sub{/\.c\z/ and -f and $c{$File::Find::dir}=++$c}, @ARGV); print 0 + keys %c, " $c"' dir1 dir2Or simpler with find command:find dir1 dir2 -type f...

View Article

Answer by terdon for How can I count files with a particular extension, and...

Find + Perl:$ find . -type f -iname '*.c' -printf '%h\0' | perl -0 -ne '$k{$_}++; }{ print scalar keys %k, " $.\n"'7 29ExplanationThe find command will find any regular files (so no symlinks or...

View Article

Answer by WinEunuuchs2Unix for How can I count files with a particular...

Consider using the locate command which is much faster than find command.Running on test data$ sudo updatedb # necessary if files in focus were added `cron` daily.$ printf "Number Files: " &&...

View Article

Answer by sudodus for How can I count files with a particular extension, and...

Small shellscriptI suggest a small bash shellscript with two main command lines (and a variable filetype to make it easy to switch in order to look for other file types).It does not look for or in...

View Article


Answer by Eliah Kagan for How can I count files with a particular extension,...

Python has os.walk, which makes tasks like this easy, intuitive, and automatically robust even in the face of weird filenames such as those that contain newline characters. This Python 3 script, which...

View Article

Answer by muru for How can I count files with a particular extension, and the...

I haven't examined the output with symlinks but:find . -type f -iname '*.c' -printf '%h\0' | sort -z | uniq -zc | sed -zr 's/([0-9]) .*/\1 1/' | tr '\0''\n' | awk '{f += $1; d += $2} END {print f,...

View Article

Answer by dessert for How can I count files with a particular extension, and...

Here's my suggestion:#!/bin/bashtempfile=$(mktemp)find -type f -name "*.c" -prune >$tempfilegrep -c / $tempfilesed 's_[^/]*$__' $tempfile | sort -u | grep -c /This short script creates a tempfile,...

View Article


How can I count files with a particular extension, and the directories they...

I want to know how many regular files have the extension .c in a large complex directory structure, and also how many directories these files are spread across. The output I want is just those two...

View Article

Browsing latest articles
Browse All 9 View Live