LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 05-14-2010, 05:21 AM   #1
jalakas
LQ Newbie
 
Registered: May 2005
Location: Orebro, Sweden
Distribution: Gentoo and Kubuntu
Posts: 5

Rep: Reputation: 0
Get a list of most accessed, "hot", files


Hello!

I have used search and google but i can't see to find an answer to this (if it's here please link and spank me for search-failing

I admin a server that serves small (static) images as part of a bigger site. There is about 1 TB of images, but most of the are seldom accessed.

The problem: Large cheap disks are slow and i would like to move the most accessed images to something faster (be it a server with faster disk in better raid or a machine with ram-cache or SSD or whatev). But how do i find the "top accessed files in period X"?

Anyone have an idea? It's probably an obvious cat-grep-sed-mangle of something in /proc but i just can't solve it on my own...


Thank you in advance!

BTW: We run Debian stable...
 
Old 05-14-2010, 06:53 AM   #2
__raHulk
Member
 
Registered: Apr 2010
Location: Mumbai
Distribution: RHEL, Debian, Fedora, Ubuntu
Posts: 39
Blog Entries: 1

Rep: Reputation: 16
The simplest way I could think of is using the inbuilt find command and its options

The command goes something like this

find / -name *.jpg -atime 1
The above command displays all the files which have been accessed a day ago.

See man find for more exact reference.

Cheers!!!
 
Old 05-14-2010, 07:03 AM   #3
__raHulk
Member
 
Registered: Apr 2010
Location: Mumbai
Distribution: RHEL, Debian, Fedora, Ubuntu
Posts: 39
Blog Entries: 1

Rep: Reputation: 16
man find
Quote:
-atime n
File was last accessed n*24 hours ago. When find figures out
how many 24-hour periods ago the file was last accessed, any
fractional part is ignored, so to match -atime +1, a file has to
have been accessed at least two days ago.
Read more
and you will find more...
 
Old 05-14-2010, 08:35 AM   #4
jalakas
LQ Newbie
 
Registered: May 2005
Location: Orebro, Sweden
Distribution: Gentoo and Kubuntu
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by __raHulk View Post
man find
Read more
and you will find more...

Thanks! Thats obvious, why didn't i think of that myself

Given a short value for atime i would get a list i myself could store and process (as in "this file was also returnd as a when you asked the last time"). That could be a working (although maybe not the most elegant) solution.

The other solution, i just realized, is... of course... turn on access-logging and parse through those files. Dunno where my head's at today.


I have gotten enough answers to solve my problem, thanks! If anyone has a cooler way to do it - plase share if you feel you have the time to do so...
 
Old 04-03-2012, 04:40 PM   #5
jongab
LQ Newbie
 
Registered: Apr 2012
Posts: 1

Rep: Reputation: Disabled
filetop

#!/usr/bin/perl
use Cwd;
use File::Touch;
use File::Temp qw/tempfile/;
use Time::HiRes qw/sleep time alarm/;
use Term::ReadKey;
my ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize();
if($hchar < 10) {print "please increase window size"; exit; }
my $mydir = getcwd;
my ($fh, $tmpfile) = tempfile(UNLINK => 1);

while(1)
{
my $starttime = time;
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm 0.4;
$query = `find -newermm $tmpfile 2>&1`; #change to mm for writes only
touch($tmpfile);
@files = split(/\n/,$query);
alarm 0;
};
system('clear');
foreach $file(@files) { $filecount{$file}++; }
@sorted = sort {$filecount{$b} <=> $filecount{$a}} (keys %filecount);
for ($x = 0;$x < $hchar-2; $x++) {print $filecount{$sorted[$x]}."\t".$sorted[$x]."\n";}
my $endtime = time;
my $length = ($endtime-$starttime);
if ($length > 0.3) {print "program not designed for large trees, please use smaller tree.\n"; exit;}
print "\n$length"."s\n"
}
 
Old 04-03-2012, 05:49 PM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,111

Rep: Reputation: 985Reputation: 985Reputation: 985Reputation: 985Reputation: 985Reputation: 985Reputation: 985Reputation: 985
Interesting first post.

How about inotify ?.

Edit: - didn't realise this was an old post. @jongab, resurrecting such old posts is generally frowned upon.
But welcome to LQ anyway ...

Last edited by syg00; 04-03-2012 at 06:11 PM.
 
  


Reply

Tags
files


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can Linux serve "virtual" files which are (re)produced by script when accessed? batonac Linux - Server 5 03-04-2010 08:02 AM
"Multicolumn" or "tiles", or even "list" icon view on desktop, in any DE? the dsc Linux - Desktop 3 02-20-2010 09:25 AM
List Only Files In a Directory beginning with "k" using the ls command mg92865 Linux - Newbie 3 05-12-2008 06:58 PM
LXer: The Linus Files, Part Two: Torvalds Says GPLv3 Backers Full Of "Hot Air" LXer Syndicated Linux News 3 07-17-2007 05:07 AM
how would I list a sequence of files as "seq.$F4.ext : 1-100" BrianK Programming 0 07-12-2004 07:43 PM


All times are GMT -5. The time now is 09:07 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration