简体   繁体   中英

How to write bash script which recursively scan subdirectories and list files with current day of month?

I need to write a simple bash script to recursively scan subdirectories (starting at the current directory), listing the names of all files where the name contains the current day-of-the-month. I am very new to bash script.

I had wrote the following script but I did not get anything.

  #!/bin/bash

  for i in $find*
  do
  if grep -rq date +%d $i; then
  echo $i
  fi
  done

Use find . Example:

find . -type f -iname "*09*"

-iname "*09*" tells it to find only files that have "09" in them. You can replace it with the day of the month that you have.

-type f tells it to return files only, not directories.

There are many more options. Read the man page for find

Get current day in a variable using date command then run find :

d=$(date '+%d')

cd /base/dir
find . -name "*$d*" -type f

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM