Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I know I can find a directory that's most recently modified by doing ls -ltr, but the last modified item might be a file, not a directory. Secondly I still have to type the directory name. My directory name is like a hash code, which is not really readable and it's quite painful to type each time.

Any easy one-liner to do so?

share|improve this question

1 Answer 1

up vote 6 down vote accepted
cd "$(ls -dt */ | head -1)"

Save this as an alias in ~/.bashrc, e.g.

alias lcd='cd -- "$(ls -dt -- */ | head -1)"'

and now lcd in any directory will change to the most recently changed directory in the current directory.

share|improve this answer
Keep in mind that the timestamp ls is checking here doesn't recurse - ie, it does not find the most recently modified file anywhere in the tree. It only measures direct changes to that directory. –  Daenyth Mar 29 '12 at 18:51
This doesn't work for me. I get the error -bash: cd: mydir/: No such file or directory where mydir is the last modified directory. It seems to find the right directory but something is causing cd to fail. Any ideas? –  Patrick Marchwiak Jul 21 '14 at 17:04

Your Answer


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.