开发者

unix help with grep?

(I thin开发者_StackOverflow社区k I can use grep, anyway....) Trying to recursively list files modified on a specific date, but, the commands I try to use either list everything sorted by date, or only list files in the directory that I'm in. Is there a way to do this? Is it grep or something else?


See find, particularly the predicates -anewer, -atime, -mtime, -newer and -newerXY.


You could combine ls and grep to list files recursively and then search for particular dates.

# List files recursively with `-R` and grep for a date.
ls -lR | grep 'Nov 23'

find can be used to recursively find files matching the criteria of your choice. It can then display these file names, or pass them to another command, or any number of actions.

# Display all files modified yesterday.
find -mtime 0

# Display all files modified yesterday in `ls -l' format.
find -mtime 0 -ls

# Search all files modified yesterday for the string "foobar".
# "{}" is a placeholder for the file names and "+" tells find to
# pass all the files at once to a single invocation of grep.
find -mtime 0 -exec grep foobar {} +


May something like

find . -type f -exec ls -l \{\} \; | grep " Aug 26  2003"

get you started?


Easiest to use is zsh. Beats find any day simplicity and performance-wise.

ls **/*(m5) will recursively list files modified exactly 5 days ago. ls **/*(mh-5) will list files modifed within the last 5 hours. You can select months, days, hours, minutes, seconds, as you wish. You can ask for files accessed N days ago instead of modification time if you need to.

Of course the command does not have to be ls. Anything you need to do will do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜