Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List the latest sub-directory using ls 1

Status
Not open for further replies.

kobewins

Programmer
Dec 1, 2005
57
0
0
US
I have a directory that contains a lot of files/sub-directorys as following.

drwxr-xr-x 2 dbl users 512 Aug 21 13:58 80
drwxr-xr-x 2 dbl users 512 Aug 21 14:19 81
-rwxr-xr-x 1 dbl users 116004 Aug 21 14:27 DEMO.sh
drwxr-xr-x 2 dbl users 512 Aug 21 14:28 Logs
-rw-r--r-- 1 dbl users 53 Aug 21 14:28 fmn_list_f.dat
-rw-r--r-- 1 dbl users 1245015 Aug 21 14:28 ppm.dat
-rw-r--r-- 1 dbl users 2093 Aug 21 14:28 ppm.log
-rw-r--r-- 1 dbl users 98980 Aug 21 14:28 XML_4aFORM.dat
-rw-r--r-- 1 dbl users 325805 Aug 21 14:28 XML_aFORM.xml
drwxr-xr-x 2 dbl users 512 Aug 21 14:28 [red]82[/red]
-rw-r--r-- 1 dbl users 90799 Aug 21 14:28 pdcs_4aform.dat
-rw-r--r-- 1 dbl users 17980 Aug 21 14:32 product.dat

I wanted to get the last sub-directory, in my sample data, [red]82[/red]. How can I do it with a simple cmd, such as

ls -d -ltr ???

Thanks all in advance for any suggestions/inputs.

-David
 
Thank you, feherke.

I modified your script a little bit by reversing the list order, it works like a charm, on my IBM AIX platform.

% ls -ltr | grep ^d | tail -1
drwxr-xr-x 2 dbl users 512 Aug 21 14:28 [red]82[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top