KarmaKarmaKarma
KarmaKarmaKarma

Reputation: 569

unix help with grep?

(I think 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?

Upvotes: 0

Views: 1841

Answers (4)

Jean
Jean

Reputation: 10610

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.

Upvotes: 0

John Kugelman
John Kugelman

Reputation: 361909

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 {} +

Upvotes: 1

dennycrane
dennycrane

Reputation: 2331

May something like

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

get you started?

Upvotes: 0

jpalecek
jpalecek

Reputation: 47770

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

Upvotes: 3

Related Questions