The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > HP-UX
.
google unix.com



HP-UX HP-UX (Hewlett Packard UniX) is Hewlett-Packard's proprietary implementation of the Unix operating system, based on System V.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Unix script to detect new file entry in directory james_1984 Shell Programming and Scripting 13 10-10-2008 06:31 AM
wh inode index starts from 1 unlike array index (0) sairamdevotee UNIX for Dummies Questions & Answers 1 08-17-2008 04:04 AM
why the inode index of file system starts from 1 unlike array index(0) sairamdevotee Filesystems, Disks and Memory 0 08-17-2008 03:50 AM
tcsh + completing a sub-directory entry JamesGoh Shell Programming and Scripting 0 04-23-2008 03:52 AM
What is index? ravi raj kumar Shell Programming and Scripting 3 12-26-2006 08:43 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-22-2009
psimoes79 psimoes79 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 21
Getting the index of the last entry in a directory

Hello,

Is there anyway of getting the index of the last entry in a directory? I'm using a C program to read the entries, but I want to go to the last entry because the directory is very big and I don't want to read all. I was using the size of the directory file descriptor but when I remove files the size doesn't decrease. Any ideas? Thanks.
  #2 (permalink)  
Old 06-22-2009
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2005
Location: Switzerland - GE
Posts: 1,568
Quote:
I want to go to the last entry because the directory is very big and I don't want to read all.
Something like
Code:
mos:/xtra $ ll|wc -l
2259
mos:/xtra $ ll -lt|head -2
total 1624588
-rw-rw-r--   1 oracle     dba           6645 Jun 20 23:00 oa....
  #3 (permalink)  
Old 06-22-2009
psimoes79 psimoes79 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 21
When you do something like that, all the directory entries are read and only the latter two are printed. What I want is to go directly to the last entry. Has I said, the size of the directory file descriptor won't always work because when a directory grows, the file descriptor increases, but when files are removed, the file descriptor size doesn't decrease.
  #4 (permalink)  
Old 06-22-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
You want seekdir() and telldir() in dirent.h

However, be sure to read your manpage: seekdir() under POSIX basically has to know the offset ahead of time, there is no SEEK_END equivalent (as in lseek() ). Your implementation may behave differently.
  #5 (permalink)  
Old 06-22-2009
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,163
The last entry in a directory with no subdirectories is the most recently created file. It can be of little value if you want the most recently updated file. Directory listings from "ls" always sort the directory.

Code:
# Last entry in directory
find . -type f -print | tail -1 | xargs ls -liad

Is this the same directory as in your previous posts (i.e. 180 Mb directory file). If so, did you manage to find out how many files there are in the directory and whether it has subdirectories?
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0