Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there any way to overload or wrap the ls command so that it will highlight / underline / otherwise make obvious the last three modified files?

I know that I can simply ls -rtl to order by reverse modification time, but I usually do need an alphabetical list of files despite the fact that I would like to quickly identify the last file that myself or another dev modified.

share|improve this question

2 Answers 2

up vote 15 down vote accepted

The following seems to work for me

 grep --color -E -- "$(ls -rtl | tail -n3)|$" <(ls -l)

It uses grep with highlight on input ls -l and uses a regular expression to search for either of the inputs for the three oldest command. It also search for the end-of-line $ in order to print the whole file.

You can also put it in a function, such that you can use lll * with multiple arguments, just as you would use ls

function lll ()
{
    command grep --color -E -- "$(ls -rtl $@ | tail -n3)|$" <(ls -l $@)
}
share|improve this answer
1  
+1: That's much nicer than the crazy one-liner I eventually came up with: ls -l | grep --color=ALWAYS -C 1000 -E `ls -rt | tail -n 3 | perl -0777 -e '$x=join("|",split(" ",<>));print $x'` –  ire_and_curses Sep 27 '12 at 8:02
    
This is terrific, thanks! –  dotancohen Sep 27 '12 at 12:01
2  
That is ridiculously epic. :D –  whoami Sep 27 '12 at 13:38
1  
@dotancohen You're welcome, thanks for the challenge :) –  Bernhard Sep 27 '12 at 17:26
1  
function lll () { command grep --color -E -- "$(ls -rtl $1 | tail -n3)|$" <(ls -l $1) } With this function, you can give a directory as argument, i.e. lll /home @dotancohen –  Bernhard Feb 18 '13 at 13:11

It won't highlight the last three modified files (which I think is quite a difficult thing to achieve reliably), but ls++ might be enough for what you want. It highlights files by relative age, grouping by colour files that are seconds, hours, days or months old.

ls++ screenshot

You can configure the colours to make the timescale you tend to work on more apparent (for active coding, hours vs days is the most important cross-over point for me).

share|improve this answer
    
Nice, thanks. However, I'm usually SSHing into servers that I cannot install packages on. –  dotancohen Sep 27 '12 at 12:00
1  
@dotancohen It's a single perl script, you should be able to install it in to your home directory (~/bin or something, add to your PATH in profile) - though this won't work if there are dependencies that are not installed. –  Random832 Sep 27 '12 at 14:58
    
I see, thanks Random! In fact I usually do have things in $HOME/bin/. –  dotancohen Sep 27 '12 at 16:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.