3

I'm asked to get the line count of all the files in some directory for which the path will be provided as a terminal argument.

My solution so far is:

wc -l "$1/"*

But doing this also gives me some unnecessary output like this:

wc: '/home/user/Desktop/Dir': Is a directory

So how can I print only the results for actual files not directories? And then how could I only display the ones that have been edited at most 10 minutes ago?

  • You can just ignore the error message: `wc -l "$1/"* 2> /dev/null` – chepner May 26 '17 at 16:11
  • Does this answer your question? [How can I count all the lines of code in a directory recursively?](https://stackoverflow.com/questions/1358540/how-can-i-count-all-the-lines-of-code-in-a-directory-recursively) – Josh Correia Oct 13 '20 at 19:53

2 Answers2

8

Thy this:

find ./pathToDirectory -type f -exec wc -l {} +
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
cn007b
  • 16,596
  • 7
  • 59
  • 74
0

To create a file with modification time 10 min ago

touch -t $(date -d '10 min ago' +%Y%m%d%H%M.%S) special_flagtime.txt

Add option -newer special_flagtime.txt or ! -newer special_flagtime.txt to find command.

So for example:

find "$1" -type f -newer special_flagtime.txt -exec wc -l {} +
Nahuel Fouilleul
  • 18,726
  • 2
  • 31
  • 36
  • 1
    Creating a sentinel file is a lot of work compared to just using the `-mtime` primary, which is standard (`-newer` is not). – chepner May 26 '17 at 16:13
  • @chepner `-mtime` cannot find files with modification time less than 10 min -mtime n `File’s data was last modified n*24 hours ago` ; reading man page again there is the option -mmin which can be used also – Nahuel Fouilleul May 29 '17 at 07:28