11-23-2006
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
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
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
2. Linux
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
3. UNIX for Dummies Questions & Answers
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
4. UNIX for Advanced & Expert Users
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
5. UNIX for Dummies Questions & Answers
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
6. Shell Programming and Scripting
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
7. UNIX for Dummies Questions & Answers
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
8. Shell Programming and Scripting
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
9. Shell Programming and Scripting
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
10. Shell Programming and Scripting
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
LEARN ABOUT REDHAT
xmdirectiontostringdirection
XmDirectionToStringDirection(library call) XmDirectionToStringDirection(library call)
NAME
XmDirectionToStringDirection -- A function that converts an XmDirection value to an XmStringDirection value
SYNOPSIS
#include <Xm/Xm.h>
XmStringDirection XmDirectionToStringDirection (dir)
XmDirection dir;
(void)
DESCRIPTION
XmDirectionToStringDirection converts the specified XmDirection direction value to its equivalent XmStringDirection value. Basically, if
the XmDirection value has a horizontal direction specification, that horizontal element is used; otherwise, the XmStringDirection value is
interpreted as XmSTRING_DIRECTION_L_TO_R. This function provides backward compatibility with the XmStringDirection data type.
Note that the Motif toolkit also contains an XmStringDirectionToDirection routine to convert an XmStringDirection value to its XmDirection
equivalent.
dir Specifies the XmDirection value to be converted.
RETURN
Returns the following XmStringDirection values:
XmSTRING_DIRECTION_R_TO_L
If the dir argument has a right to left horizontal direction value in it, for example XmRIGHT_TO_LEFT_TOP_TO_BOTTOM.
XmSTRING_DIRECTION_L_TO_R
If the dir argument has a left to right horizontal direction in it, for example XmLEFT_TO_RIGHT_TOP_TO_BOTTOM, or if the horizon-
tal direction value in the dir argument is ambiguous, such as in the XmTOP_TO_BOTTOM value.
XmSTRING_DIRECTION_DEFAULT
If there was no horizontal direction specified.
RELATED INFORMATION
XmDirection(3), XmDirectionMatch(3), XmDirectionMatchPartial(3), XmDirectionToStringDirection(3), XmString(3), XmStringDirection(3), and
XmStringDirectionToDirection(3),
XmDirectionToStringDirection(library call)