Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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!
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 ..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.