Quickie Linux tip: most recently modified files

Remember Last Night?
Image via Wikipedia

This little tip is not really deserving of its own post, but here goes.

Assume for the moment that you are one of those ADHD busy people who saves files into a folder so fast that you don’t remember their names. Maybe you don’t even remember last night. Or the names don’t ring a bell… or you thought project_823_notes was a great name for a file you saved yesterday, but today you can’t remember the project number. These are all good reasons to get a listing by date of your files. Now, sure, you could use some stinkin’ GUI file-manager tool, but suppose your files are on a distant server with no GUI tools installed. Try this:

ls -lt

That will list all 500 files in the directory reverse-sorted by date. Now you need a way to get just the last 10 or so modified files. Here’s a way to do that:

ls -lt | head

Aha! Just what the doctor ordered. To make it even easier, you could alias this to something shorter, like lst:

alias lst="ls -lt | head"

Now, you can just enter lst to get the last 10 files in the current directory. Test it and make sure it works. To save the alias so that it will be available next time you log in, you can add it to the end of  your .bash_profile file in your home directory.

By the way, this works just the same in the Bash shell in OSX. Got any tips to share? Think we should have used find or sent the users off with a curt man ls? Post a comment.

Enhanced by Zemanta

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s