![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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. |
|
||||
|
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.
|
|
||||
|
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. |
|
||||
|
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 | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|