Well,I m trying to list the number of files created today and the count the number of lines in those files.I have to do it in unix.Please suggest how to write script for this.
To find the number of lines:
find / -type f -ctime 0 -mtime 0 -print0 | xargs -0 wc -l
This is almost what you want. There is no file created time in Unix, this is approximation with both file status changed time and file modified time.
If you would like to search only in certain directory, replace /
with /path/to/your/dir
.
To find the number of files:
find / -type f -ctime 0 -mtime 0 | wc -l
Determining when a file was created reliably is hard. The mtime is when it was modified, the ctime is when the inode data was changed (change of permissions, for example), the atime is when the file data was last accessed. Usually, the mtime is surrogate for the create time; when a file is created, it records the creation time (as does the ctime and atime), but if the file is subsequently modified, the mtime records the time when the contents of the file was last modified.
find . -mtime -1 -print0 | xargs -0 wc -l
Find all the files under the current directory with a modification time less than 24 hours old and send the names to 'wc -l' - allowing for spaces and other odd characters in the file names.
This will find files (-type f
) in /path
modified in the last 24 hours (-mtime -1
means modified in the last 1 day) and run wc -l
to count the number of lines. {}
is a placeholder for the file names and +
means pass all the file names to a single invocation of wc
.
find /path -mtime -1 -type f -exec wc -l {} +
Note that -ctime
as suggested in other answers is change time, not creation time. It is the last time a file's owner, group, link count, mode, etc., was changed. Unix does not track the creation time of a file.
find . -maxdepth 1 -daystart -ctime 0 -type f | xargs wc -l
You'll need to change the maxdepth
argument value if you need to look deeper.
To count the number of files changed today:
find . -daystart -type f -ctime -1 | wc -l
find
finds all the files (-type f
) in the current directory (.
) created* (-ctime
) more recently (-
) than one (1
) day since the start of this day (-daystart
). wc
counts the number of lines (-l
) in find
's output.
To count the lines in those files:
find -daystart -type f -ctime -1 -print0 | wc -l --files0-from=-
The first part is the same, except that find
separates the filenames using nulls (-print0
). wc
counts the lines (-l
) in the null-separated files (--files0-from=
) on its standard input (-
).
* ctime
is not actually the creation time, but the time when the file's status was last changed. I don't think the filesystem holds on to the actual creation time.