Traverse Latest directory First


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Traverse Latest directory First
# 1  
Old 01-24-2014
Traverse Latest directory First

I wish to traverse the latest to the oldest directory based on its timestamp.

Code:
ls -ltr
drwxr-x---   3 admin   bel      1024 Jan 22 02:29 sys
drwxr-x---   2 admin   bel      2048 Jan 22 02:30 admin
drwxr-x---  10 admin   bel     24576 Jan 23 21:31 bin

For the above i need to cd first to bin, then to admin and finally to sys in a for loop.

Can you please let me know how can i?
# 2  
Old 01-24-2014
Don't reverse the sort. Don't use the long format. If any pathname contains whitespace or a shell metacharacter, use a while-read loop instead of a for.

Regards,
Alister
# 3  
Old 01-24-2014
remove r

Code:
ls -lt

This User Gave Thanks to Akshay Hegde For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Remove all the subdirectories except latest 5 inside any given directory

I Want to remove all the sub-directories except latest five in any given TGTDIR. Is there a way to do so without making a cd to TGTDIR? I have tried the following but not worked. Thank you. rm -rf `ls -t $TGTDIR | awk 'NR>5'` (20 Replies)
Discussion started by: Devendra Hupri
20 Replies

2. Shell Programming and Scripting

How to retrieve the latest files from the directory.?

hi, i have some file in a directory say p1.txt.201305051200.lst p1.txt.201305051300.lst p1.txt.201306051200.lst p1.txt.201306051300.lst p2.txt.201306051200.lst p2.txt.201306051300.lst i am using p* pattern to retrieve these file ls -1 p* the files in red color are the latest... (7 Replies)
Discussion started by: Little
7 Replies

3. Shell Programming and Scripting

How to traverse directory structure and sum size of files?

How do I write a bash or ruby or perl or groovy script to print all the files in my directory tree that are one-to-two years old, the size of each file, and the sum of file sizes and then delete them? I was using find . -atime +365 -exec rm '{}' \; but the problem was that I could not... (5 Replies)
Discussion started by: siegfried
5 Replies

4. Shell Programming and Scripting

Move the latest or older File from one directory to another Directory

I Need help for one requirement, I want to move the latest/Older file in the folder to another file. File have the datetimestamp in postfix. Example: Source Directory : \a destination Directory : \a\b File1 : xy_MMDDYYYYHHMM.txt (xy_032120101456.txt) File2: xy_MMDDYYYYHHMM.txt... (1 Reply)
Discussion started by: pp_ayyanar
1 Replies

5. Shell Programming and Scripting

Traverse through directory....

hi I have a directory structure like Parent Parent/child1/ Parent/child2/ Parent/child3/ and the each main directory contains Parent/child1/file1.txt, Parent/child1/fil2.zip ....... Parent/child2/file1.txt,Parent/child/fil2.zip ...... Now i want to traverse to each and want to... (1 Reply)
Discussion started by: Reddy482
1 Replies

6. Shell Programming and Scripting

Copy the latest file to a directory

Hi Team, I wish to copy the latest file of pattern "MyFile*" to some other location. I need to do all the operation in a single command separated by |. ls -rt <MyFile*> | tail -1 | <copy command>. How can I do? Please help me. Thanks, Kanda (2 Replies)
Discussion started by: spkandy
2 Replies

7. Shell Programming and Scripting

Copy the latest file from one directory to another

Hi All, I am in the directory a/b/processed the files in this directories are -rw-r--r-- 1 owb users 330 Aug 8 chandantest.txt_08082008 -rw-r--r-- 1 owb users 220 Aug 7 chandantest.txt_07082008 -rw-r--r-- 1 owb users 330 Aug 6... (3 Replies)
Discussion started by: chandancsc
3 Replies

8. UNIX for Dummies Questions & Answers

pick the very latest directory

Hi, I have some list of directories in the form datemonthyear e.g. 02082009, 03082009 and 04082009 etc. I need to pick the latest directory from the current working directory. Outcome: 05082009 This is the output am expecting. Thanks (6 Replies)
Discussion started by: venkatesht
6 Replies

9. Shell Programming and Scripting

Get the latest directory created

hi, I need to get the latest directory created for example wheni run ls -altr *xyz_Integration* I have plenty of directories created like my_build_77_xx_Integration_050908_150714: total 177898 -rw-rw--- 1 xyzmgr cchyg 7687338 May 9 19:29 myapp.ear ... (2 Replies)
Discussion started by: f354676
2 Replies

10. Shell Programming and Scripting

Traverse Directory Tree for backup

Hi, I am trying to write a script that will move all the files from source directory structure(multiple levels might exist) to destination directory structure. If a sub directory in source doesnot exist in destination then I have to skip and goto next level. I also need to delete the files in... (1 Reply)
Discussion started by: srmadab
1 Replies
Login or Register to Ask a Question