Re: unix question

  • From: "QuentinC" <webmaster@xxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Thu, 7 Oct 2010 19:38:33 +0200

My question now is is there a way to incoorporate in this code a way to count the number of the output files when I do the find ls command? I have found several commands but they appear to be only for counting the files in a directory.

You may use wc -l tou count the number of lines.

Something like that :
find '/home/faserv/hrprod/cron/logs' -name '*.log' -type f -mtime +30 -print | wc -l It will count the number of lines sent by the find command, which is equals to the number of files. Problem: you wont no more see the list itself. In this case you could use a temporary file. I'm not sure if it is possible to store the whole list (which contains a couple of lines) into a $ variable and proceed without any temporary file. find '/home/faserv/hrprod/cron/logs' -name '*.log' -type f -mtime +30 -print >temp.tmp
cat temp.tmp | wc -l

In fact, I think you can simplifiy your actual delete command :
find '/home/faserv/hrprod/cron/logs' -name '*.log' -type f -mtime +30 -delete

__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: