LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-01-2006, 07:10 PM   #1
kaiserbeto
LQ Newbie
 
Registered: Oct 2006
Posts: 10

Rep: Reputation: 0
find script


Hello!

I've got a directory structure that increments (ie 501, 502, 503) at random times based on an algorithim. Within each directory contains xml files that get counted for running metrics (ultimately i'm going to run an ls -l | wc -l and if it's below a certain number then i'll get notified).

Basically, I want to "find" the second to last directory created. So if 502 is the latest directory created, I want it to find 501, and then I'll run the metrics.

I can't use ls -lt | head because that shows access times and all my directories are accessed at random times. So, i just need to be able to find based on creation time, and not access time. Any suggestions?
 
Old 12-01-2006, 07:22 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
ls -l |tail -n 2 |head -n 1
 
Old 12-01-2006, 07:38 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by kaiserbeto
I can't use ls -lt | head because that shows access times and all my directories are accessed at random times. So, i just need to be able to find based on creation time, and not access time. Any suggestions?
Actually 'ls -t' uses the last modification time, not the
access time, so a 'ls -tr|tail -n 2|head -n 1' should work
just fine.


Cheers,
Tink
 
Old 12-02-2006, 12:30 AM   #4
kaiserbeto
LQ Newbie
 
Registered: Oct 2006
Posts: 10

Original Poster
Rep: Reputation: 0
Hmm ... this doesn't work; maybe i should have provided more details. The structure is as follows:

DIR/1
DIR/2
DIR/etc onwards up to 999.

Each directory is modified as xml files within DIR/1, DIR/2 (etc) are updated. So, when I run ls -l |tail -n 2 |head -n 1 in the directory that has up to DIR/600, the output is 116, when it should be 599 (remember, it needs to be the second to last directory created, and modify/access times can't be a factor). Thanks for the assistance already, it's much appreciated!
 
Old 12-02-2006, 02:49 AM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Well, if 116 was the last one written to, then maybe your algorithm
is not working properly? Or other programs (people?) are interacting
with the same directory structure? If you know for SURE that the
numerically highest and 2nd highest values are what you want just use
sort ..

ls |sort -n |tail -n 2 | head -n 1


Cheers,
Tink
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find symlink target name in script germanyzulu Linux - Software 4 08-14-2015 10:23 AM
how to find a pattern using shell script sharad Linux - General 1 05-23-2006 03:50 AM
find shell script help liren Linux - Newbie 3 05-02-2005 03:05 PM
problem with find command in script cojo Linux - Software 3 05-26-2004 10:28 AM
how to find the pid of a perl script from shell script toovato Linux - General 1 12-19-2003 06:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration