Getting the index of the last entry in a directory


 
Thread Tools Search this Thread
Operating Systems HP-UX Getting the index of the last entry in a directory
# 1  
Old 06-22-2009
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  
Old 06-22-2009
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  
Old 06-22-2009
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  
Old 06-22-2009
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  
Old 06-22-2009
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Automate DIRECTORY ENTRY when in remote SHELL

Good day all I am trying to figure out how to automate the command in a shell script that i have written. Some context: The script does the following on the local host #!/bin/sh banner 'QikCopy' echo "Please insert file name for SCP command!" read file DUMMY scp -p $file... (2 Replies)
Discussion started by: MrRobot
2 Replies

2. Shell Programming and Scripting

Shell script to find if any new entry in directory

I require a shell script to find if any new entry of dump files present in a particular directory and to send an email if any new entry exists.I had a crontab to run the script for every 5 min. Below are the file names.dump.20150327.152407.12058630.0002.phd.gz... (9 Replies)
Discussion started by: bhas85
9 Replies

3. Web Development

Directory index forbidden by Options directive error on specific directory with indexing disabled

I am seeing the following error appear numerous times in my Apache error log: I have my Apache config configured as below, so I would expect indexing not to occur on this directory as it falls under the parent /web directory. Strangely all the IP address, including this example, all... (5 Replies)
Discussion started by: crmpicco
5 Replies

4. UNIX for Dummies Questions & Answers

Not able to delete this file/directory/entry

Hello UNIX gurus, I noticed this file or whatever in one of our directories, and somehow I am not able to proceed with my work, without deleting this one. .insert--- 1 siebload intrface 0 Feb 22 01:25 Testfile I am confused, as it doesnt appear to be a file, and on doing any... (2 Replies)
Discussion started by: ppathak1234
2 Replies

5. Shell Programming and Scripting

Run SED for all index.jsp files across a directory structure.

Hi, I am a novice and require help once again. I have a over 200 file all called index.jsp placed in different directories The following Sed command gives me the data of all included jsp files in index.jsp sed -n -e 's/^.*page="\(*\).*$/\1/p' index.jsp How can I run the above... (6 Replies)
Discussion started by: rajkdutta
6 Replies

6. Shell Programming and Scripting

Sort from start index and end index in line

Hi All, I have a file (FileNames.txt) which contains the following data in it. $ cat FileNames.txt MYFILE17XXX208Sep191307.csv MYFILE19XXX208Sep192124.csv MYFILE20XXX208Sep192418.csv MYFILE22XXX208Sep193234.csv MYFILE21XXX208Sep193018.csv MYFILE24XXX208Sep194053.csv... (5 Replies)
Discussion started by: krish_indus
5 Replies

7. Shell Programming and Scripting

Unix script to detect new file entry in directory

Hi All, I want to detect each new file coming / getting created in unix directory. When every new file came to directory, i have to get its details like its size , date and time stamp and store it into another file. Could any one please tell me , how i can achieve that? Thanks. (13 Replies)
Discussion started by: james_1984
13 Replies

8. UNIX for Dummies Questions & Answers

wh inode index starts from 1 unlike array index (0)

brothers why inode index starts from 1 unlike array inex which starts from 0 its a question from the design of unix operating system of maurice j.bach i need to know the answer urgently...someone help please (1 Reply)
Discussion started by: sairamdevotee
1 Replies

9. Filesystems, Disks and Memory

why the inode index of file system starts from 1 unlike array index(0)

why do inode indices starts from 1 unlike array indexes which starts from 0 its a question from "the design of unix operating system" of maurice j bach id be glad if i get to know the answer quickly :) (0 Replies)
Discussion started by: sairamdevotee
0 Replies

10. Shell Programming and Scripting

tcsh + completing a sub-directory entry

As part of a script Im designing, I am required to allow the command line to finish off part of a series of sub-directory entries. Basically what I want to do is cp /root/parent/part of subs name + other part of subs name/file /other_root/other_parent/other_sub/file without facing... (0 Replies)
Discussion started by: JamesGoh
0 Replies
Login or Register to Ask a Question