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 > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sorting Directory Listing Sepia UNIX for Dummies Questions & Answers 1 07-11-2007 08:44 AM
Listing Files krishna_sicsr High Level Programming 3 04-05-2007 02:32 PM
Listing of files Vitalka Linux 1 03-02-2005 09:32 AM
help - listing files richarmj Filesystems, Disks and Memory 2 10-02-2003 10:14 AM
Recursive directory listing without listing files psingh UNIX for Dummies Questions & Answers 4 05-10-2002 11:52 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-23-2006
dave_angel dave_angel is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 2
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 (permalink)  
Old 11-23-2006
Andrek Andrek is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 122
Try Ls -lt
The "t" sorts by access time then by name

ls -ltr will sort in the reverse order.
  #3 (permalink)  
Old 11-23-2006
dave_angel dave_angel is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 2
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.
Closed Thread

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:57 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