Skip to content


Subversion checkout URL

You can clone with
Download ZIP


opt --sort-files-mtime #211

wants to merge 1 commit into from

2 participants


sort based on modified time. Thanks


What is the use case for this? When would you want to sort the files that ack searches by mtime? Or is this something that you'd only use with -f and getting a list of files, so you want to see all the files of a certain type with the most recently touched ones first?


well, just sometimes I want to see the most recent changed files with ack results. is there any other way to archive it?



When you say "ack results", are you talking about actual search results, or just using -f for a list of filenames?

When is a case that you want to see most recent first, and why?

I'm just trying to get my head around the problem that you're trying to solve. Your patch might be the way to do it, and it might not.


"ack results" is actual search results, not using -f for the list of filenames.

but yes, you're right. -f is also working.

my usage is basically very simple and it might be OK that we can do it with -f and combine with other linux command.
for example, I'm searching 'story=' in my git repos and I want to know which file is the most recent, that I can copy it as a template for another new file.

so something like
ack -f 'story=' . | other_linux_command_sort_files_on_mtime_should_also_work



But as I understand the patch, it's not going to actually sort all the files in mtime order. It's going to sort the files in each directory in mtime order, and it's going to sort the directories that it goes through in mtime order. If you have a tree of 1000 files, it's not going to sort all 1000 files. It's only going to sort per directory.


I admit that I didn't think about subdirectories.

but yes, you're correct. it's not right. it needs more fixes. I'll check it and fix it tomorrow since it's a bit later today.


@petdance petdance closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 26, 2013
  1. @fayland

    add opt sort-files-mtime

    fayland committed
This page is out of date. Refresh to see the latest.
3 
@@ -152,7 +152,7 @@ sub read_rcfile {
Takes an array of options passed in on the command line and returns
a hashref of information about them:
# is: Match the filename exactly
# ext: Match the extension
# regex: Match against a Perl regular expression
@@ -452,6 +452,7 @@ File finding:
The PATTERN must not be specified.
-g Same as -f, but only select files matching PATTERN.
--sort-files Sort the found files lexically.
+ --sort-files-mtime Sort the found files based on modified time
--show-types Show which types each file has.
--files-from=FILE Read the list of files to search from FILE.
-x Read the list of files to search from STDIN.
1 
@@ -279,6 +279,7 @@ EOT
'show-types' => \$opt->{show_types},
'smart-case!' => \$opt->{smart_case},
'sort-files' => \$opt->{sort_files},
+ 'sort-files-mtime' => \$opt->{sort_files_mtime},
'type=s' => sub {
my ( $getopt, $value ) = @_;
@@ -41,7 +41,7 @@ sub from_argv {
file_filter => $opt->{file_filter},
descend_filter => $descend_filter,
error_handler => sub { my $msg = shift; App::Ack::warn( $msg ) },
- sort_files => $opt->{sort_files},
+ ($opt->{sort_files_mtime}) ? (sort_files => \&File::Next::sort_mtime_standard) : (sort_files => $opt->{sort_files}),
follow_symlinks => $opt->{follow},
}, @{$start} );
@@ -64,7 +64,7 @@ sub from_file {
File::Next::from_file( {
error_handler => sub { my $msg = shift; App::Ack::warn( $msg ) },
warning_handler => sub { my $msg = shift; App::Ack::warn( $msg ) },
- sort_files => $opt->{sort_files},
+ ($opt->{sort_files_mtime}) ? (sort_files => \&File::Next::sort_mtime_standard) : (sort_files => $opt->{sort_files}),
}, $file ) or return undef;
return bless {
4 ack
@@ -735,6 +735,10 @@ B<-i> always overrides this option.
Sorts the found files lexicographically. Use this if you want your file
listings to be deterministic between runs of I<ack>.
+=item B<--sort-files-mtime>
+Sort the found files based on modified time.
=item B<--show-types>
Outputs the filetypes that ack associates with each file.
2  t/ack-line.t
@@ -143,7 +143,7 @@ $target_file[1]-4-#define YYBISON 1 /* Identify Bison output. */
my @files = qw( t/swamp/ );
- my @args = qw( --cc --lines=1 --after=3 --sort );
+ my @args = qw( --cc --lines=1 --after=3 --sort-files );
ack_lists_match( [ @args, @files ], \@expected, 'Looking for first line in multiple files' );
1  t/config-loader.t
@@ -92,6 +92,7 @@ my %defaults = (
show_types => undef,
smart_case => undef,
sort_files => undef,
+ sort_files_mtime => undef,
v => undef,
w => undef,
Something went wrong with that request. Please try again.