0

I would like to count the number of files with yesterday's date in ls's output. I tried:

yday=$(date --date="yesterday" +"%b%Oe")
ls . -ltr | grep $yday | wc -l

The problem is that files have dates with two spaces between the month and days less than 10, for example:

Jan  6
   ^^---- two spaces

but my command creates a date with only one space:

yday=$(date --date="yesterday" +"%b%Oe")

Jan 6
   ^----- one space

How can I modify my command to solve this problem?

1
  • 2
    You want the -mtime option to find. You'll need to calculate how long ago the day you want is and try something like "find pwd -mtime -1 -type f -print" You may refer to cyberciti.biz/faq/howto-finding-files-by-date
    – love
    Jan 7, 2016 at 5:22

1 Answer 1

1

You can use:

yday=$(date --date="yesterday" +"%b %_d")

to produce the string you want (the underscore says to pad with spaces)

0

You must log in to answer this question.