Easy About Bash Script function

Hi to all,

first of all,i am working on MINIX 3 OS.
I want to create a bash script file,which will create a list of files(not directories) that have been modified one specific day (i.e today) under my home directory.

thank you very much!! :slight_smile:

Look at the man pages for "find" command. Roughly what you're looking for:

#!/bin/bash
find $HOME -daystart -ctime 0 -type f >files_today.list # files modified today
find $HOME -daystart -ctime 1 -type f >files_yesterday.list # files modified yesterday

I'm not sure that "daystart" may be a Linux extension. If your OS doesn't support it, you can still accomplish this with ctime piped into a grep. My OS has date field in format "Mon dd" where dd is two-digit day with no leading zero. So April 1st would be:
"Apr 1" (i.e., two spaces between r and 1). So I would do:

#!/bin/bash
find $HOME -ctime 0 -type f | grep "Apr 1" >files_today.list
find $HOME -ctime 0 -type f | grep "Mar 31" >files_yesterday.list
find $HOME -ctime 1 -type f | grep "Mar 31" >>files_yesterday.list

hi marcus!

with this line:

find $HOME -daystart -ctime 0 -type f >files_today.list # files modified today

you take the list with the files modified today or also the files that are created today?which is the parameter that ensure this?:slight_smile:

Broken down

$ find \      # Command
  $HOME \     # Directory
  -daystart \ # Use the start of the day as base for time calculations
  -ctime 0 \  # ctime (Change time, either content or metadata) in the last
              # 24 hours
  -type f \   # Only regular files

maybe i didn't express me so good.My question is which files are been found with this.Not since when. i.e. Just modified files or also created files?

Both. Change time is always the time of the last content or metadata change. Metadata changes include file creation, renaming, moving, permissions, ...

Ahhh..Ok thanks for the note..I understand now how it works.. :slight_smile:

According to this,If you want to take all the backup files that have been modified today (as marcus described good before) with the command "tar", and put them in a file *.tar, putting also the date as a name of the file...for example like Backup_of_01_04_2009.tar.. any ideas how to implement this.??? :slight_smile:

Thanks a lot!!

$ tar -cvf Backup_of_$(date +%d_%m_%Y).tar $(find $HOME -daystart -ctime 0 -type f)

Orestis, that is why I mentioned you should look at the man pages for find, as I don't know exactly what your requirements are. And I think I said here is an example "roughly" what I think you may want. The bigger point being that you can probably use the find command to accomplish what you want.

Without going too much into find (check man page), ctime is last time file status was changed. You may need mtime for last modified. Point is I think you can do it with find or find/grep combo.

Hope this helps.
~Marcus