Thursday, November 12, 2009

Find last modified directory in UNIX


Question: In my current working directory how can I find the last modified directory ?

Way1:

$ ls -lrt | awk '/^d/ { f=$NF }; END{ print f }'

Way2:

$ ls -d --sort=time */ | head -n 1

Relates post:

- Find the latest file in a directory in UNIX

Any better way to find this? please suggest; really appreciated. Thanks.

2 comments:

OntureƱo said...

ls -td * | head -1 is slightly shorter than your second option...

Unknown said...

@Ontureno: Thanks.

© Jadu Saikia www.UNIXCL.com