LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   how to list all files modified in last N days (https://www.linuxquestions.org/questions/linux-general-1/how-to-list-all-files-modified-in-last-n-days-468365/)

sneakyimp 07-27-2006 06:29 PM

how to list all files modified in last N days
 
hi:

i'm trying to list all the files in my public_html directory that have been modified in the last N days. i need them to be listed WITH the last modified date and sorted in order by date modified. directories too i guess.

i'm using this, but it's not working:

find -ctime -21 -exec ls -rtdl {} \;

it's listing files modified years ago and doesn't appear to be sorted properly...like so:

===
[root@spain www.mydomain.com]# find -ctime -7 -exec ls -rtdl {} \;
-rw-rw-r-- 1 root user4 24 Jul 27 04:00 ./.htpasswd
drwxr-xr-x 3 apache user4 4096 Jul 6 00:30 ./log
-rw-r--r-- 1 apache user4 116312 Jul 20 18:46 ./log/error.log
-r-------- 1 apache user4 0 Jul 1 22:30 ./log/.no_delete
drwxr-xr-x 3 apache user4 4096 Jul 6 00:30 ./log/2006
drwxr-xr-x 2 apache user4 4096 Jul 6 00:30 ./log/2006/07
-rw-r--r-- 1 apache user4 3287023 Jul 21 00:30 ./log/2006/07/web.log
lrwxrwxrwx 1 apache user4 45 Jul 6 00:30 ./log/web.log -> /home/www/www.mydomain.com/log/2006/07/web.log
drwxr-xr-x 2 apache user4 4096 Jul 6 04:00 ./web/stats
-rw-r--r-- 1 apache user4 2141 Jul 21 04:00 ./web/stats/hourly_usage_200607.png
-rw-r--r-- 1 apache user4 3411 Jul 21 04:00 ./web/stats/daily_usage_200607.png
-rw-r--r-- 1 apache user4 33689 Jul 21 04:00 ./web/stats/webalizer.current
-rw-r--r-- 1 apache user4 41 Jul 21 04:00 ./web/stats/webalizer.hist
-rw-r--r-- 1 apache user4 105142 Jul 21 04:00 ./web/stats/usage_200607.html
-rw-rw-r-- 1 apache user4 125 Jul 27 04:00 ./web/stats/.htaccess
-rw-r--r-- 1 apache user4 3735 Jul 21 04:00 ./web/stats/index.html
-rw-r--r-- 1 apache user4 2178 Jul 21 04:00 ./web/stats/ctry_usage_200607.png
-rw-r--r-- 1 apache user4 2217 Jul 21 04:00 ./web/stats/usage.png
-rw-r--r-- 1 apache user4 12288 Jul 27 04:00 ./web/stats/dns_cache.db
===

spooon 07-27-2006 07:43 PM

you probably want
Code:

find -mtime -21 -exec ls -rtdl {} \;

haertig 07-27-2006 11:27 PM

Example: Find all files under /var/log that have been modified in the last 5 days, list them newest first.
Code:

$ find /var/log -mtime -5 -type f -print0 | xargs -0 ls -al | sort -r +5
I tested this quickly, not exhaustively, so do you own testing to verify it really works.

There were a couple of things off in your initial example:

You wanted modification time, and this is "mtime" (rather than "ctime"). You can't use -exec directly with find because this works like xargs and sends the find output to ls in bursts, each burst would then be sorted individually by ls. You want to sort the whole thing at once, not a piece at a time.

sneakyimp 07-28-2006 12:16 PM

cool. will try these. thanks!


All times are GMT -5. The time now is 02:43 PM.