need help listing/sorting files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need help listing/sorting files
# 1  
Old 11-23-2006
Question need help listing/sorting files

I am currently attempting to create a file which I access from an oracle form.

At the minute I do a host command and run an ls -l e.g.

/bin/ls -l /dir/dir/dir/ > /tmp/list.txt

I then read this file within my oracle form. However I want the user to be able to restrict, sort and filter the file so list.txt appears differently according to various choices.

Using ls I can give the user the ability to add a wildcard search so they specify the search criteria and this is used within the ls command e.g. the user wants to list all files begining with sav:

/bin/ls -l /dir/dir/dir/sav* > /tmp/list.txt

this works fine, but I also want the user to be able to specify ascending or descending order and order by name or date. Again this is all easy using the -r and -t arguments.

e.g.
/bin/ls -l /dir/dir/dir/sav* > /tmp/list.txt
/bin/ls -lr /dir/dir/dir/sav* > /tmp/list.txt
/bin/ls -lt /dir/dir/dir/sav* > /tmp/list.txt
/bin/ls -ltr /dir/dir/dir/sav* > /tmp/list.txt

However I now want to give the user the ability to restrict the output by displaying all files (as it does now) or files that were modified in the last 1 , 7 or 30 days.

As far as I can see this is not possible using the ls command.

I have tried using the find command, as follows:

last day:
/usr/bin/find /dir/dir/dir/sav* -daystart -mtime -1 -type f -ls > /tmp/list.txt
last 7 days
/usr/bin/find /dir/dir/dir/sav* -daystart -mtime -7 -type f -ls > /tmp/list.txt
last 30 days
/usr/bin/find /dir/dir/dir/sav* -daystart -mtime -30 -type f -ls > /tmp/list.txt
all files:
/usr/bin/find /dir/dir/dir/sav* -type f -ls > /tmp/list.txt

Here the user can specify the seach criteria (e.g. sav) and the number of days but I can't find a way of sorting the output by date or name as you can with ls arguments.

An example of the output I am getting from my latest attempt:

/usr/bin/find /dir/dir/dir/sav* -daystart -mtime -7 -type f -ls > /tmp/list.txt

is:

147977 260 -rwxr-xr-x 1 oracle dba 262144 Nov 19 12:20 /dir/dir/dir/sav1.fmb
149139 180 -rwxr-xr-x 1 oracle dba 180224 Nov 19 12:20 /dir/dir/dir/sav2.fmb
149125 276 -rwxr-xr-x 1 oracle dba 278528 Nov 20 15:41 /dir/dir/dir/sav3.fmb
149119 332 -rwxr-xr-x 1 oracle dba 335872 Nov 19 13:48 /dir/dir/dir/sav6.fmb
147540 364 -rwxr-xr-x 1 oracle dba 368640 Nov 19 10:59 /dir/dir/dir/sav5.fmb
149881 408 -rwxr-xr-x 1 oracle dba 413696 Nov 21 14:16 /dir/dir/dir/sav12.fmb
149557 436 -rwxr-xr-x 1 oracle dba 442368 Nov 22 15:12 /dir/dir/dir/sav36.fmb

Could anyone please suggest how I can achive this? Please let me know if you need further info, or if anything is unclear.

Best Regards
# 2  
Old 11-23-2006
Try Ls -lt
The "t" sorts by access time then by name

ls -ltr will sort in the reverse order.
# 3  
Old 11-23-2006
thanks, but I know about -t and -r, these will not work with the find command. I think I am almost there but within oracle forms the output doesn't seem to write to the file.

I've used backquotes, so for example: I've got the following for listing files begining with sav, modified in the last 7 days, and listed by date in reverse order:

ls -ltr `/usr/bin/find /dir/dir/dir/sav* -daystart -mtime -7 -type f -ls > /tmp/list.txt`

If I do this within a unix command window (putty) it works a treat but using a host command with oracle forms it doesn't work.......I think I'm almost there though!

I'll try it at work again tomorrow, but I think I need to specify the exact path for the ls command as I've done with the find command. I am also direct error output (i.e. 2>) to a file but I've not checked that yet.

thanks for your suggestion though.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies

2. Shell Programming and Scripting

listing files

Hi Guys, I need to list out the files which are not ending with particular extension in ksh but the extension can come within the file name. Please help me.. Thanks (2 Replies)
Discussion started by: jesu
2 Replies

3. Shell Programming and Scripting

Complex data sorting in excel files or text files

Dear all, I have a complex data file shown below,,,,, A_ABCD_13208 0 0 4.16735 141044 902449 1293900 168919 C_ABCD_13208 0 0 4.16735 141044 902449 1293900 168919 A_ABCDEF715 52410.9 18598.2 10611 10754.7 122535 252426 36631.4 C_DBCDI_1353 0... (19 Replies)
Discussion started by: AAWT
19 Replies

4. UNIX for Dummies Questions & Answers

Need help with listing and sorting in DGUX

Hello all, very much a Unix newbie. My company has an old DG/UX system we use for customer data. I need to archive some data to clear some space, so I wanted to be able to list items in each directory by size, to grab some "low hanging" fruit to give me some breathing room as the system is... (0 Replies)
Discussion started by: Trader2699
0 Replies

5. Shell Programming and Scripting

perl script for listing files and mailing the all files

Hi, I am new to perl: I need to write perl script to list all the files present in directory and mail should be come to my inbox with all the files present in that directory. advanced thanks for valuable inputs. Thanks Prakash GR (1 Reply)
Discussion started by: prakash.gr
1 Replies

6. UNIX for Dummies Questions & Answers

Listing files

how would i list all files, directories and exectable files in my directory? is there anyway to find out what date a file was created? Thanks!! (2 Replies)
Discussion started by: trob
2 Replies

7. UNIX for Advanced & Expert Users

listing files excluding files from control file

I have a directory named Project.I have a control file which contains valid list of files.I would like list the files from directory Project which contains files other than listed in the control file. Sample control file: TEST SEND SFFFILE CONTL The directory contains followign... (15 Replies)
Discussion started by: ukatru
15 Replies

8. UNIX for Dummies Questions & Answers

Sorting Directory Listing

If I do an ls -l on a directory I get this: -rw-r--r-- 1 root other 5248094 Jun 24 03:56 monitor.log.7 -rw-r--r-- 1 root other 5248303 Jul 11 11:19 ct.log.1 -rw-r--r-- 1 root other 5248907 Jun 29 06:01 ct_monitor.log.5 -rw-r--r-- 1 root other 5249042 Jun 19... (1 Reply)
Discussion started by: Sepia
1 Replies

9. Linux

Listing of files

How can I list all files in a directory and its subdirectories that have been created or changed since the system was booted. I was trying to acomplish this with "ls" and "find" commands but could not get anything usefull. Maybe some one can provide me a hint. Thank you for your time. (1 Reply)
Discussion started by: Vitalka
1 Replies

10. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies
Login or Register to Ask a Question