LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-27-2006, 06:29 PM   #1
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,056

Rep: Reputation: 78
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
===
 
Old 07-27-2006, 07:43 PM   #2
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
you probably want
Code:
find -mtime -21 -exec ls -rtdl {} \;
 
Old 07-27-2006, 11:27 PM   #3
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
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.
 
Old 07-28-2006, 12:16 PM   #4
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,056

Original Poster
Rep: Reputation: 78
cool. will try these. thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
find and list files modified since system was booted Mike144 Linux - Newbie 5 04-09-2006 08:03 PM
Tar files in a dir modified before 7 days in a shell script jayachristina Linux - Newbie 4 05-14-2004 02:49 AM
remove 'modified date' column in nautilus list view nexx_au Linux - Software 0 12-09-2003 03:29 AM
Files modified by switchdesk benjaminrtz Linux - General 1 01-25-2003 10:05 AM
How would you check which files had been modified? entm Linux - General 1 05-14-2002 09:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration